Skip to content

CAD kernel foundations · Part two

The mathematics a kernel stands on

Part one described a solid by its boundary and left two debts: which side of the skin is material, and what the skin is made of. Both are paid in linear algebra. We go through points and vectors, the dot and cross products, frames and placements and their handedness, what a mirror does to a frame, and where a surface normal comes from, with a figure and a checkable number for each.

Why the boundary needs mathematics

Part one recorded a solid as topology pointing at geometry, and checked the topology by counting. Two questions stayed open, and both need numbers before any algorithm can start. Given a face, which side holds the material? Given a formula, where does it sit in space?

A normal answers the first question: one arrow per face saying which way is out. A frame answers the second: one origin plus three directions saying where each formula lives. What follows defines both, starting from the difference between a point and a vector.

Each section below follows the same shape: the definition, the rule, why the rule holds, a figure, and one number small enough to check by hand. A short script recomputes every one of them; the reading list says how. Later parts spend what is set up here. Part three writes the ten curves and surfaces a kernel knows in closed form, each as a canonical shape in a placement of section five, and shows where a parametrisation fails to produce a normal. Derivatives return in parts six and ten, where projection and intersection iterate on them.

Points, vectors, directions

A point marks a place and nothing else. A vector marks a displacement between two places: it has a length and an orientation, and no position. A direction is a vector whose length is one, and which must stay one. A kernel stores each as three numbers and treats them as three types, because a transformation moves them differently.

Translate everything by t→. A point moves: T(P) is P+t→. A vector does not. Take two points A and B and the vector B−A between them. After the translation it is T(B)−T(A)=(B+t→)−(A+t→)=B−A: the t→ cancels. So the translation does not apply to a vector, and a direction behaves like the vector.

x y drawn in the plane z = 3 t = (4, −1, 0) A (1, 2, 3) B (3, 3, 3) T(A) (5, 1, 3) T(B) (7, 2, 3) B − A T(B) − T(A) B − A = (2, 1, 0) T(B) − T(A) = (2, 1, 0)
One translation, two points. A = (1, 2, 3) and B = (3, 3, 3), shifted by t = (4, −1, 0), land on (5, 1, 3) and (7, 2, 3). The vector between them is (2, 1, 0) before and after.

A rigid motion is a rotation and a translation together. The rotation applies to all three types. The translation applies to the point only. A direction also has to be renormalised if the transformation had any scaling in it, or it is no longer a direction.

Point

P T(P)

has a position and nothing else, so a translation moves it

Vector

v T(v)

has length and orientation but no position, so the translation part does not apply to it

Direction

d T(d) both of length 1

a vector constrained to length 1, and it stays 1 through any rigid motion

The normal bug

A normal is a direction, so it must ignore translations. Stored in the same type as a point, it moves with the part instead, and the face reports the wrong side on exactly the parts of a model that were moved: the assembled ones. The shape looks correct. The inside/outside test from part one breaks. Section six adds the second half of the bug: under a scale that is not the same in every direction, a normal does not even move like a tangent.

We keep the types apart in notation throughout the series. A point is a bare letter. A vector or a direction carries an arrow. Read P=O+x⁢X→ as a sentence: start at the place O, then walk x along the arrow X→.

The dot product

The dot product multiplies two vectors into one number:

a→⋅b→=a1b1+a2b2+a3b3

multiply component by component, then add. The result is a plain number, not a vector.

Three things fall out of it. Length: a vector dotted with itself is its squared length, so ‖a→‖=a→⋅a→. Angle: a→⋅b→=‖a→‖⁢‖b→‖⁢cos⁡θ. Perpendicularity: the dot product is zero exactly when the two are at right angles.

Take a→=(1,0,0) and b→=(1,1,0). The dot product is 1. The lengths are 1 and 2, so cos⁡θ=1/2 and the angle between them is 45°.

The dot product also drops a perpendicular. Given a vector and a unit direction, (a→⋅d→)⁢d→ is the part of a→ along d→. Projecting (3, 4, 0) onto the x direction gives (3, 0, 0), of length ‖a→‖⁢cos⁡θ=5⋅3/5=3. Part six inverts curves and surfaces with this operation, thousands of times per model.

x d θ O foot (3, 0, 0) a a = (3, 4, 0), |a| = 5 d = (1, 0, 0), a direction (a · d) d = (3, 0, 0) |a| cos θ = 5 · 3/5 = 3 drawn to scale: slope 4 : 3
The projection, drawn to scale. The vector a = (3, 4, 0) has length 5. The dashed line meets the direction d = (1, 0, 0) at a right angle, and its foot (3, 0, 0) divides a into the part along d and the part across it.

The cross product

The cross product multiplies two vectors into a third vector, perpendicular to both:

a→×b→=(a2b3−a3b2,a3b1−a1b3,a1b2−a2b1)

each component combines the other two. Dotting the result with either input gives zero, which is the check that it stands perpendicular to both.

Its length is the area of the parallelogram the two inputs span: ‖a→×b→‖=‖a→‖⁢‖b→‖⁢sin⁡θ. For (1, 0, 0) and (0, 1, 0) the product is (0, 0, 1) and the area of the unit square is 1. For (4, 0, 0) and (1, 2, 0) it is (0, 0, 8): a base of 4 times a height of 2.

Order matters. Swapping the inputs negates the result: b→×a→=−a→×b→. The right-hand rule says which of the two perpendicular directions the product takes: point the fingers from the first input toward the second, and the thumb gives the product. The formula itself knows nothing about hands. It always gives (1, 0, 0) × (0, 1, 0) = (0, 0, 1), first axis times second axis equals third, in whatever frame the coordinates are read in. Whether that third axis is where a right thumb points depends on the frame being right-handed, which the next section defines.

a = (4, 0, 0) b = (1, 2, 0) area = |a × b| = 8 O a × b a × b = (0, 0, 8) out of the page, at O b × a = (0, 0, −8) into the page right hand: fingers a → b, thumb along a × b
The product as an area with a side, for a = (4, 0, 0) and b = (1, 2, 0). The shaded parallelogram has area 8 = ‖a × b‖. A vector across the page is drawn end-on: ⊙, a circle with a dot, is an arrow tip coming toward you, and ⊗, a circle with a cross, is its tail going away. So a × b = (0, 0, 8) is the ⊙ at O, and b × a = (0, 0, −8) would be a ⊗.

Frames, placements and handedness

A frame is an origin plus three directions that are pairwise perpendicular and each of unit length. Call them X→, Y→ and Z→. Any point is then an origin plus three walks, one along each direction, and the three walks are a matrix product:

P=O+x⁢X→+y⁢Y→+z⁢Z→=M⁢(x,y,z)+O

where O is the origin and the three arrowed letters are the frame’s directions, which are also the three columns of M. The numbers x, y, z are the point’s coordinates in the frame. A point has no arrow because a point is not a vector.

So a frame is a matrix plus a translation, and every rule this article proves about matrices applies to frames. A kernel uses that twice over. Every curve and surface it knows in closed form is stored as two separate things: a canonical shape, written in the simplest possible position, and a placement, a frame that says where that position is in space. A circle is not stored as a general circle in space. It is stored as a radius, one number describing a circle at the origin of the XY plane, plus an origin and a frame.

X Y Z canonical: at the origin, in the XY plane X Y Z placed: the same five numbers, somewhere else the placement
One circle, stored once. What is kept is a radius and a placement (an origin and a frame). Every closed-form curve and surface of part three follows the same division: a canonical shape, and where it sits.

Placements come in three sizes, depending on what the geometry needs:

PlacementIsEnough for
a point and one directionan axisa line; and the axis of revolution of every surface in part three but the plane
a point and two directionsa frame for a planeany of the four conics (a conic is a planar curve, so a plane is all it needs)
a point and three directionsa full frameany of the five surfaces

Two frames fit the definition for any choice of X→ and Y→, because Z→ can point either way along the remaining perpendicular. The cross product tells them apart:

X→×Y→=±Z→

plus for a right-handed (direct) frame, minus for a left-handed (indirect) one.

The determinant puts the same test in one number. For three directions it is det[X→Y→Z→]=(X→×Y→)⋅Z→, the signed volume of the box the three span: its size is the volume, and its sign says on which side of the first two the third one lies. For a frame the box is a unit cube, so only the sign is left: +1 for right-handed, −1 for left-handed, with nothing between. It is also the determinant of the matrix M above.

right-handed: X × Y = Z X Y Z toward you det[X Y Z] = +1 left-handed: X × Y = −Z X Y Z away from you det[X Y Z] = −1
Two frames with the same X and Y. On the left Z comes toward the reader (⊙), and the turn from X to Y, seen from the tip of Z, is counterclockwise: right-handed. On the right Z goes away (⊗): left-handed. No rotation in space carries one to the other.

Every frame built from scratch in this series is right-handed: its third direction is computed as the cross product of the first two, so it cannot come out the other way. A mirror is the only operation that produces a left-handed one. The convention has consequences. Reverse Z→ and every cross product computed from it reverses too. The most important of these is the surface normal, which is how a face knows which side is material. So a mirrored frame gives more than a mirrored picture: it gives a surface whose outside is its inside. The next two sections show how that happens.

Handedness in these figures

The 3D figures in this series are generated, and the first version of the generator projected the axes so that X ran to the lower right and Y to the lower left. That arrangement is the mirror of a right-handed frame: the turn from the projected X to the projected Y goes the opposite way from the one the viewpoint should see. No drawing in part one showed it, because none of them labelled their axes. A labelled triad drawn that way would have contradicted every statement about normals in this series, and most readers would have sensed the problem without seeing it. The generator now checks the handedness of its own projection before it draws anything.

Rotations and mirrors

A transform is a 3×3 matrix plus a translation, the same shape as a frame. The matrix does the turning, stretching and reflecting; the translation moves the result. This section is about the matrix. When it is orthogonal, its columns are a frame: pairwise perpendicular unit directions. Orthogonal matrices keep every length and every angle, so orthonormality survives them.

The determinant sorts them. At +1 the matrix is a rotation: the solid turns in space. At −1 it is a mirror: every length and angle is still kept, and still no turning produces it. Try it with three fingers of the right hand, each at right angles to the other two: thumb along X, index along Y, middle finger along Z. Now the mirror image: thumb along X, index along −Y, middle along Z. Turn the right hand any way you like; it cannot make that. The left hand makes it at once. Two fingers would not show this, because any two perpendicular directions can be turned onto any other two. Handedness needs all three.

The cross product tracks the difference. For any invertible matrix:

(Ma→)×(Mb→)=det⁡(M)⋅M−T(a→×b→)

the cross product of two transformed vectors is the transformed cross product, scaled by the determinant, where the transform is the inverse transpose of M rather than M itself.

Check it on a matrix that is neither a rotation nor a mirror. Take M with rows (2, 1, 0), (0, 1, 3) and (1, 0, 1), whose determinant is 5, and the vectors a→=(1,2,0) and b→=(0,1,1). Then Ma→=(4,2,1) and Mb→=(1,4,1), and their cross product is (−2, −3, 14). On the other side, a→×b→=(2,−1,1), and multiplying it by det⁡(M)⋅M−T gives (−2, −3, 14) again.

The general form has a payoff. A normal is a cross product of two tangents, and tangents move by M, so the rule says that normals move by M−T, up to a scale. For a rotation that is the same as M. For a scale that differs between directions it is not. Stretch x by 2. The tangent (1, 1, 0) becomes (2, 1, 0). The normal (1, −1, 0), perpendicular to it, moved like a tangent becomes (2, −1, 0), and its dot product with the new tangent is 3: no longer perpendicular. Moved by M−T it becomes (0.5, −1, 0), and the dot product is 0. This is the second half of the normal bug: a kernel that moves a normal with the matrix it uses for points is wrong under such a scale, even after it drops the translation.

For an orthogonal matrix the inverse transpose is the matrix itself, and the rule shortens:

(Ma→)×(Mb→)=det⁡(M)⋅M(a→×b→)

a rotation carries the cross product along. A mirror carries it along and reverses it.

Mirror the frame of the last section in the plane y = 0. The columns go from (X, Y, Z) to (X, −Y, Z):

X→′=(1,0,0),Y→′=(0,−1,0),Z→′=(0,0,1)X→′×Y→′=(0,0,−1)=−Z→′

a right-handed frame goes in, a left-handed one comes back, and the determinant goes from +1 to −1. Nobody flipped anything; the arithmetic did it.

mirror plane y = 0, seen edge-on before after X Y Z X × Y = (1,0,0) × (0,1,0) = (0,0,1) = Z: counterclockwise, out of the page X′ Y′ Z′ X′ × Y′ = (1,0,0) × (0,−1,0) = (0,0,−1) = −Z′: clockwise, into the page
The mirror in y = 0, seen edge-on as the horizontal line. Only Y reverses; X stays, and Z still comes toward the reader (⊙). Below the line the turn from X′ to Y′ runs clockwise, so X′ × Y′ goes into the page (⊗), along −Z′: the mirrored frame is left-handed.

Parameters and normals

A parametrised surface S(u,v) turns a rectangle of parameters into points in space. Its two partial derivatives, Su and Sv, are the tangents along each parameter. Their cross product is the normal:

N→=Su×Sv

the direction of the normal comes from the order of the parameters. Swap them and it points the other way.

Take the cylinder of radius r in a right-handed frame, S(u,v)=O+r⁢cos⁡u⁢X→+r⁢sin⁡u⁢Y→+v⁢Z→. Its tangents are Su=−r⁢sin⁡u⁢X→+r⁢cos⁡u⁢Y→ and Sv=Z→. At r=2, u=0.7, the unit normal works out to (0.7648, 0.6442, 0), which is exactly the radial direction (cos 0.7, sin 0.7, 0). The normal points away from the axis.

right-handed frame (X, Y, Z) axis u = 0 u Su N Sv unit N = (0.7648, 0.6442, 0), outward mirrored frame (X, −Y, Z) axis u = 0 u Su N Sv same formula: Su reverses, N inward
The cylinder seen down its axis, so Sv = Z comes toward the reader (⊙). On the left, u runs counterclockwise from the ray u = 0; at u = 0.7 on the circle of radius 2 the tangent Su runs along the circle and N = Su × Sv points out along the radius. On the right, the same formula in the mirrored frame (X, −Y, Z): u runs clockwise, Su reverses, and N points in.

Now mirror the whole surface in y = 0, with the matrix M of the last section. There are two ways to hold the image, and neither keeps everything. Keep the formula and use the mirrored frame (X, −Y, Z): then S′(u,v)=M(S(u,v)), so every parameter lands on the image of the point it had before. But that frame is left-handed, and the normal comes out inward: this is the surface whose outside is its inside, from section five. At r=2, u=0.7, the normal dotted with the outward radial direction is −2, where the original gave +2. Keep a right-handed frame instead, and the same point set needs a reversed parameter, S′(−u,v)=M(S(u,v)), which negates Su and turns the normal back outward. One choice keeps the parameters, the other keeps the outward side. A kernel must pick, per surface, and record the pick. Part one called that pick orientation.

What the boundary stores

A closed surface divides space into two regions. A consistent outward normal names one of them material. That pair, the skin plus its normals, answers the question part one opened with: for any point in space, material or air.

Part three writes the ten geometries those skins are cut from: the five curves and five surfaces a kernel knows in closed form, each as a canonical shape in a placement. Parts six and ten differentiate them. Everything they compute rests on what this article set up: three types that move differently, the dot product for lengths, angles and projections, the cross product for areas and normals, the right-handed frame, and the matrix rule for the cross product when the frame changes sides.

Reading list

Sources

  • G. Strang, Introduction to Linear Algebra, 6th ed., Wellesley-Cambridge Press, 2023. Read directly, for the four facts this article is built from: length and angle from the dot product, area from the cross product, handedness as the sign of the determinant, and the cross product under a matrix.
  • I. Stroud and H. Nagy, Solid Modelling and CAD Systems: How to Survive a CAD System, Springer, 2011. Read directly, for where each fact is spent inside a modeller: placements as origin plus directions, normals as cross products of surface derivatives, and orientation as the record of which side is material.

Method

  • Every number printed above, in the text and in the figures, is recomputed from its definition by a plain Python script with no dependencies, which fails if any of them disagrees: the translated points, the 45° angle, the projection, the cross products and the parallelogram area, the determinant of both frames, the frame written as a matrix, both sides of the matrix identity on a matrix that is not orthogonal, the normal under a stretch, the mirror triple, and the cylinder normal in the right-handed frame, in the mirrored frame and with the reversed parameter.
  • The point, vector and direction panels and the placed circle are generated by the same program as part three’s figures, which checks that its own axis triad is right-handed before drawing. The other six figures are flat schematics drawn to the numbers their captions print, in the site’s colour tokens.