1. Why I am writing this

In my previous article, I laid out a test plan for checking whether large language models (LLMs) can write usable, manufacturable parametric parts. The idea I kept coming back to was that “it ran” is not the same as “it is correct.” But to understand how a script can run and still produce a bad part, or fail on a perfectly reasonable request, you need to know what the CAD software is doing underneath the script.


So, this article is the background chapter, written to stand on its own. It is for mechanical engineering students who use CAD every day but have never looked at how the software stores a shape, and for programmers who are curious about where AI and CAD meet.


A note on scope: I am a student, not a kernel developer. I have simplified some things, and where my understanding is limited, I say so and point to the books.

2. A CAD model is a definition, not a drawing

What you see on screen is a rendering. What the software stores is a definition from which the rendering, the volume, the mass properties, and the toolpaths can all be computed. Two ideas run through every representation:

  • Geometry is the actual shape: a plane, a cylinder, a curve, a point with coordinates.
  • Topology is how the pieces connect: which faces meet along which edge, and which edges end at which vertex.

File formats show the difference clearly. A STEP file (ISO 10303) can carry exact faces and edges, which is why you can open a STEP part in another CAD system and still select a face to modify it. An STL file carries only a list of triangles. That is enough for a slicer, but the exact cylinder of a drilled hole is gone, replaced by flat facets. STL also stores no units, so the software reading it has to assume them.

3. Three ways to represent a solid

3.1 Boundary representation (B-rep)

Most mechanical CAD systems describe a solid by its boundary. A B-rep has two layers. The topological layer holds faces, edges, and vertices and records how they are connected. The geometric layer attaches a surface to each face, a curve to each edge, and a point to each vertex. A drilled hole, for example, is a face lying on a cylindrical surface, bounded by two circular edges.


Even a plain box shows the structure: 6 faces, 12 edges, and 8 vertices. For simple solids like this, Euler’s formula holds: V − E + F = 2, and 8 − 12 + 6 = 2. Martti Mäntylä’s book builds solid modeling around operators that preserve this kind of consistency, known as Euler operators. Solids with through-holes or faces with inner boundaries need extra terms in the formula.


Most kernels keep common shapes (planes, cylinders, cones, spheres, and tori) as exact analytic surfaces and use NURBS for freeform ones (Section 4). Commercial kernels such as Parasolid and ACIS, and the open-source OpenCASCADE kernel that CadQuery is built on, are all B-rep kernels.


The strength of B-rep is that features have handles: you can select a face and shell it, or select an edge and fillet it. The cost is complexity. A B-rep can be invalid: faces that do not quite meet, surfaces that intersect themselves, or inconsistent orientation. A viewer may display such a model without complaint while the kernel refuses to operate on it. This is why my test plan includes a validity check and does not stop at “it exports.”


For further reading: Aristides Requicha’s 1980 survey of rigid-solid representations is the classic overview, Christoph Hoffmann’s Geometric and Solid Modeling is a readable textbook, and Ian Stroud’s Boundary Representation Modelling Techniques focuses on how B-rep systems work in practice.

3.2 Constructive solid geometry (CSG)

In CSG a shape is a tree. The leaves are primitives such as boxes, cylinders, and spheres, and the nodes are Boolean operations (union, difference, intersection) and transformations such as translate and rotate. A bracket with a hole is “a box minus a cylinder.” Requicha’s survey treats CSG as one of the main families of solid representation, and OpenSCAD is the best-known scripting tool built around it.

CSG is compact and natural to write as code, and a CSG model is mathematically well defined as long as its primitives are. The cost is that the tree describes how to build the shape, not what the finished faces and edges are. There is no direct way to say “round this edge,” because edges only exist after the tree is evaluated. In CSG tools, rounding edges usually needs workarounds.

3.3 Meshes (STL)

A mesh approximates the surface with triangles. It stores vertex positions and which triangles they form, and nothing about design features, exact curves, or units. It is the standard hand-off format for 3D printing slicers, and for that purpose it works well. For engineering work, such as adding a tolerance or drilling a hole in the right place on an imported part, it is a poor starting point because the exact definition has been thrown away. Its accuracy depends on how finely the surface was triangulated.

Side by side


B-rep

CSG

Mesh (STL)

What is stored

Faces, edges, vertices, plus surfaces and curves

Tree of primitives and Boolean operations

Triangles

Exact curved surfaces?

Yes

Yes, in the ideal definition

No, approximated

Can you select a face or edge?

Yes

Not directly

Not in a meaningful way

Typical file

STEP

Source script (for example OpenSCAD)

STL

Typical use

Engineering CAD, machining

Compact scripted parts

3D printing hand-off

4. NURBS: how curves and surfaces are defined

NURBS stands for Non-Uniform Rational B-Splines. The standard reference is Les Piegl and Wayne Tiller’s The NURBS Book. A NURBS curve is defined by four ingredients:

  • Control points, which pull the curve toward them
  • Weights, one per control point, that increase or decrease each point’s pull
  • A knot vector, which controls how the pieces of the curve blend together
  • A degree, such as 2 (quadratic) or 3 (cubic)


The rational part, the weights, matters because ordinary polynomial splines cannot represent a circle exactly, while rational ones can. Piegl and Tiller show a full circle built from rational quadratic segments. This is one reason NURBS became the common language for CAD curves: one representation covers circles, ellipses, and sculpted freeform curves.


A NURBS surface extends the idea to a grid of control points with a knot vector in each direction. In a B-rep, a face is often a NURBS surface patch that is trimmed by the boundary curves of its edges. Gerald Farin’s Curves and Surfaces for CAGD and Michael Mortenson’s Geometric Modeling give broader introductions to the same mathematics.


My understanding is that this is one reason operations like fillets, shells, and offsets are harder than extrusions. The kernel has to compute new surfaces, such as a blend between two faces or a copy of a face pushed inward by the wall thickness. The exact offset of a freeform surface is generally not another NURBS surface of the same simple form, so it has to be approximated, trimmed, and stitched back into a watertight solid. A tiny gap or overlap, and the result is invalid.

5. How CAD builds a part: history, parameters, and selection

Parametric CAD builds a part as a sequence: sketch a profile, extrude it, cut a hole, fillet an edge. Each step is an operation the kernel applies to the B-rep left by the previous step, and “parametric” means the sequence can be replayed with new values. Order matters. Filleting before cutting holes leaves different edges to work with than filleting after.


The hard part is referring to things. “Fillet this edge” requires a way to identify the edge. In interactive CAD, you click on it, and the software must remember which edge you meant when a parameter changes and the history is replayed. When the topology changes, such references can break or jump to the wrong entity. This is known as the topological naming problem, and it is widely discussed in the CAD community.


Code-based CAD avoids stored references by describing what to select with a rule. Here is a short CadQuery example:

import cadquery as cq # A 40 x 40 x 20 mm block block = cq.Workplane("XY").box(40, 40, 20) # Select the four vertical edges by a rule ("parallel to Z") and round them rounded = block.edges("|Z").fillet(5) # A 25 mm radius would ask for 50 mm of material along a 40 mm side, # so the kernel cannot build it: # too_big = block.edges("|Z").fillet(25) 

The rule "|Z" means “edges parallel to Z.” A rule like this is robust when your intent is clear, but it can also match more or fewer edges than you meant, and a script that selects the wrong edges may still run. That is exactly the kind of gap between “it ran” and “it is correct” that I want to measure.

6. Where AI enters the picture

An LLM writes text. It never sees the B-rep. It writes a sequence of operations and, on a first attempt, has to predict what shape that sequence will produce: which way a sketch plane faces, which edges a selector will pick, whether a fillet radius will fit. The kernel is the one that finds out, and the model learns about it only if someone feeds the error message back, which is what the repair condition in my test plan does.


Researchers and users approach this in different ways:

  1. General-purpose LLMs writing code for a CAD scripting library such as CadQuery or OpenSCAD. This is what my test plan evaluates.
  2. Models trained directly on CAD operation sequences. DeepCAD (Rundi Wu, Chang Xiao, and Changxi Zheng, ICCV 2021) is an example. It describes each shape as a sequence of CAD operations (sketch and extrude) and trains a Transformer-based generative model on a dataset of such sequences.
  3. Approaches that generate meshes or other approximate shapes. These can look convincing, but as Section 3.3 explains, they do not carry the exact faces and features that engineering work depends on.


Based on how the kernel works, here is where I expect problems to show up. These are reasoned risks, not test results:

Concept

Likely trouble spot for an AI-written part

Sketch planes and local coordinates

A feature on the wrong plane or the wrong side of the part

Selectors on B-rep edges and faces

A rule that picks more, fewer, or different edges than intended

Order of operations

Fillet before holes, or shell before cuts: valid but different (or invalid) geometry

NURBS-based operations (fillet, shell, offset)

Operations that fail on real geometry

Units

The kernel works with plain numbers, so millimetres are only a convention and units can drift

Validity versus correctness

A valid solid with the wrong dimensions

7. A checklist for reading any AI-generated CAD script

You do not need to trust the script or distrust it. You need to check it. Here is the list I would use:

  1. Are all dimensions in a parameter block, and does the geometry code actually use them?
  2. Is each sketch on the plane you think it is, and which way is “up”?
  3. Do the selectors pick exactly the edges and faces you intend? Count them.
  4. Is the order of operations sensible? Fillets and chamfers usually come late.
  5. Is the result exactly one valid solid?
  6. Does the volume match a hand calculation, and does the bounding box match the specification?
  7. Does it export to STEP and not only STL, so the exact geometry survives?

8. Limitations of this article

  • Simplified. Real kernels handle many more surface types, tolerances, and edge cases than I describe here.
  • Kernels differ. Parasolid, ACIS, and OpenCASCADE do not behave identically, and neither do the CAD programs built on them.
  • Reasoned, not tested. The trouble spots in Section 6 come from understanding how the representations work. They are not experimental findings.
  • A student’s view. Please check the primary sources listed below before relying on any detail.

9. Conclusion

Knowing how a CAD kernel represents a shape tells you what to check when something else generates that shape. A solid is a boundary of faces and edges backed by exact surfaces, usually NURBS for the freeform ones. A script is a list of instructions the kernel has to carry out, and every instruction can fail in a way the script’s author cannot see. That is why “it ran” never settles the question.


The results of the test plan from my previous article will come in a separate article, once I have run the tests and can report real numbers instead of guesses.