Skip to content

CAD kernel foundations · Part three

The mathematics behind geometry

Elementary geometries: the curves and surfaces a kernel knows in closed form

Part one split a boundary representation into topology and geometry, and then focused on the topology. This article covers the other half: the five curves and five surfaces that carry most of the geometry in most CAD models. Each is a short formula placed in a frame, the canonical shape plus placement that part two set up. We go through what each formula is, what its parameters measure, where the parametrisation stops working, and why a kernel keeps ten special cases instead of turning everything into splines.

What a parametrisation is

Part one described a boundary representation as topology pointing at geometry, and said very little about the geometry. This article covers that half: ten formulas, what their parameters measure, and where each one stops working.

The tools come from part two. A point, a vector and a direction are three types that a transformation moves differently, and every geometry here is stored as a canonical shape plus a placement: an origin and a right-handed frame. Part two derives both, in points, vectors, directions and frames and placement. Each formula below is written in the canonical position, in the placement’s own coordinates x, y and z, and then placed in space as P=O+x⁢X→+y⁢Y→+z⁢Z→.

A curve is a function from an interval of the real line into space. A surface is a function from a rectangle of the plane into space. That is the whole definition, and the rest of this article is about ten particular functions.

C:I⊆ℝ⟶ℝ3S:D⊆ℝ2⟶ℝ3

A curve is a map from an interval, a surface a map from a rectangle. Everything in this article is one of these two, and the ten geometries differ only in what the map does.

The rectangle should be taken literally. It is an ordinary flat region with its own coordinates, and everything the surface does (where it curves, where it repeats, where it fails) is a statement about what the map does to some part of that region.

So the interval and the rectangle are part of the definition of a geometry. The same formula on a different domain is a different curve: the circle formula on a quarter of a turn is an arc, and the cone formula on the wrong side of one value of v is the other nappe. This is why every closed form below has its domain on the same line, after the formula. A square bracket is a bound the map reaches and evaluates at; a round bracket is a range that runs on without end. The interval alone cannot say whether its two ends are the same place, so where they are, the note underneath prints the identity that says so, and that identity is what the word periodic means. A mathematician would avoid the problem by writing that domain half-open, [0, 2π), so that every point of the curve has exactly one parameter, but these geometries deliberately do not declare it that way. Both ends are legal parameters and both evaluate. This redundancy is useful: it lets a curve lying along the seam be given a parameter on each side of it. The seam edge from part one, one curve in space and two edges of the rectangle, is this extra end appearing in the topology.

A practical note on the unbounded ranges: a range written here as running to infinity is, in a kernel, a large finite number standing in for it. Checking whether a bound is infinite is a comparison against that sentinel, not a test for a floating-point infinity, and arithmetic that goes past it returns an ordinary number instead of a signal.

u v 0 2π −h h R S D — the parameter rectangle S(R)
A region of the domain, and the patch it becomes. Nothing is bent: u and v are read off the two sides of the rectangle, and the map turns the rectangle’s own grid into the curved grid on the surface.

Two properties of this arrangement matter more than any individual formula.

Evaluating forwards is cheap; going backwards is a different problem. Given a parameter, producing the point takes a few multiplications and one or two trigonometric calls. Given a point, producing the parameter is a separate algorithm: a closed form for all ten of these geometries, which is a large part of why they are worth keeping, and an iterative solve for anything more general. Every algorithm built on top has to deal with this asymmetry.

A kernel needs derivatives as well as values. Evaluation routines come in a family: the point alone, the point with its first derivatives, and the point with first and second derivatives. The first derivative gives the tangent of a curve and, through a cross product, the normal of a surface. The second gives curvature. Both feed the Newton iterations that every projection and every surface–surface intersection is built on, and an intersector that cannot get a reliable second derivative near a point will not converge there.

Where the numbers come from

Every formula below was checked against a production kernel’s own evaluator: the closed form as printed here, evaluated in Python, against the library’s answer at the same parameters, in a deliberately skew placement so that a formula which is only correct in the canonical frame would fail. There are twenty-nine checks, agreeing to the last bit in most cases and to 4×10−16 in the worst. Every measured quantity further down (the derivative magnitudes, the apex parameter, the seam distances, the collapse at the poles) comes from the same programs.

The five curves

A line and the four conics. This set is not an arbitrary choice: the conics are exactly the curves we get by cutting a cone with a plane, and together with the line they are every curve of degree two or less. Everything beyond them is free-form, which is part four.

Each is printed the same way: the formula with its domain, and under the rule the inverse map, the parameter recovered from a point. The inverse is written in the placement’s own coordinates, so x and y below are the lengths a point measures along the placement’s first two directions. All ten of these inverses are closed forms, which is the main reason these geometries are kept as special cases.

Line

D O u = 0 u = 5 COORDINATE BY COORDINATE C(u) = O + u D O a point, D a unit direction u is signed distance from O, along D no X / Y frame here an origin and one direction is the whole of a line
A line. It is the only elementary curve with no frame to resolve against: a point and a direction define it, and u is the distance along that direction.
C(u)=O+u⁢D→,u∈(−∞,+∞)
the way backu=(P−O)⋅D→

The only curve here with no frame to resolve against. A point and a direction define it, and the parameter is the signed distance from the origin along that direction, so equal steps in u are exactly equal steps in space. It is also the only curve in this article whose parametrisation leaves no choices to make.

Circle

X Y u R u = 0 R cos u R sin u C(u) COORDINATE BY COORDINATE x = R cos u y = R sin u u the angle from X arc length is R u, so u is proportional to distance travelled
A circle. Equal steps in u are equal steps along the curve, and it is the only conic here for which that is true.
C(u)=O+R⁢cos⁡u⁢X→+R⁢sin⁡u⁢Y→,u∈[0,2⁢π]
the way backu=atan2⁡(y,x)

the interval is closed and its two ends are one point on the curve: C(u+2⁢π)=C(u). This is what periodic means here, and a bare pair of numbers cannot express it.

The parameter is the angle from the X direction, and arc length is R u. The circle is the only conic here whose parameter is proportional to the distance travelled along the curve, so u can be used in place of arc length. Its periodicity, stated under the formula, is the first appearance of a problem that comes back later.

Ellipse

X Y u a b a cos u b sin u C(u) COORDINATE BY COORDINATE x = a cos u y = b sin u u the eccentric angle read on the dashed major circle, not the angle to the point itself
An ellipse. The parameter is taken on the circle of radius a and dropped onto the curve, so u is not the angle measured from the centre to the point.
C(u)=O+a⁢cos⁡u⁢X→+b⁢sin⁡u⁢Y→,u∈[0,2⁢π]
the way backu=atan2⁡(yb,xa)

u is the eccentric angle, as the a and b in the inverse show: divide the two coordinates by their own radii and the ellipse becomes the circle whose angle is u. Periodic in the same way as the circle, C(u+2⁢π)=C(u).

It looks like the circle with two radii instead of one, but there is a difference that is easy to miss. The parameter is the eccentric angle: we take the angle on the circle of radius a and project it vertically onto the ellipse. It is not the angle measured from the centre to the point. With a = 6 and b = 2.5, the parameter u = 0.2 lands at a polar angle of 0.084, off by 58 per cent. It is not arc length either: the speed along the curve runs from 2.5 at the ends of the major axis to 6.0 at the ends of the minor, so equal steps in u cover arc lengths differing by a factor of 2.4. If we tessellate an ellipse on a uniform parameter grid, the chords bunch at the ends and stretch at the sides.

Hyperbola

X Y a asymptote a cosh u b sinh u C(u) COORDINATE BY COORDINATE x = a cosh u y = b sinh u x²/a² − y²/b² = 1 one branch; the other is not reachable from any real u
A hyperbola. cosh is never less than 1, so this parametrisation reaches only one branch. The opposite branch is a second curve, which no value of u reaches.
C(u)=O+a⁢cosh⁡u⁢X→+b⁢sinh⁡u⁢Y→,u∈(−∞,+∞)
the way backu=arsinh⁡(yb)

cosh is never less than one, so this map reaches only one branch. The opposite branch is a second curve that no value of u reaches, and a kernel that needs both stores both. The parameter runs over the whole real line, the curve is unbounded, and in the placement’s own coordinates the points satisfy the implicit form:

x2a2−y2b2=1

the branch this parametrisation reaches, in the placement’s own coordinates. Checked at the sampled parameters: the left side comes back 1 to twelve decimal places.

Parabola

X Y x = −f focus u²/4f u C(u) COORDINATE BY COORDINATE x = u²/4f y = u the parameter IS the y coordinate focus at (f, 0) directrix the line x = −f the axis is X, not Y
A parabola. The parameter is the offset along Y, so the curve opens along X: it is the transpose of the usual y = x².
C(u)=O+u24⁢f⁢X→+u⁢Y→,u∈(−∞,+∞)
the way backu=y

Its conventions are often surprising, because it is the transpose of the usual y = x². The parameter is the offset along Y, so the axis of the parabola is X and the curve opens along it. f is the focal distance: the focus is at (f, 0) and the directrix is the line x = −f. Checked at three parameters, the distance from the curve to the focus equals the distance to the directrix to twelve decimal places, which is the definition of a parabola.

The five surfaces

The plane, and four surfaces of revolution. Each of the four is one of the curves above, turned about an axis: a line parallel to the axis gives the cylinder, a line at an angle to it gives the cone, a circle centred on it gives the sphere, and a circle beside it gives the torus. Seen this way, the formulas are expected to look alike: the two horizontal components are always some radius times cos u and sin u, and the surfaces differ only in what that radius is and what the third component does.

The inverses are printed under each formula as they were for the curves, and four of the five start the same way, with the same arctangent of the same two coordinates. In them ρ is the distance from the axis, ρ=x2+y2: the same ρ the formulas build from v, read off the point instead of computed from it.

Plane

X Y Z u v P(u, v) COORDINATE BY COORDINATE x = u a length along X y = v a length along Y z = 0 no third parameter
A plane. Both parameters are lengths along the frame’s own directions, so it is the only one of the five with no angle in it.
x=uy=vz=0
S(u,v)=O+u⁢X→+v⁢Y→,(u,v)∈(−∞,+∞)×(−∞,+∞)
the way backu=x,v=y

the three components are lengths along the placement’s own directions; below the rule they are gathered into the one vector equation, which is the form the rest of this article uses.

Both parameters are lengths along the frame’s own directions, and the domain is the whole plane. It is the only one of the five with no angles, no periodicity, no degenerate point and no self-intersection. This is why much of a kernel’s fast path is a check for whether all the geometry involved is planar.

Cylinder

X Y Z R u v P(u, v) COORDINATE BY COORDINATE x = R cos u y = R sin u z = v a length, not an angle u an angle round the axis v a length along it
A cylinder. u is an angle and v is a length: it is the only surface of the five whose two parameters are not the same kind of quantity.
x=R⁢cos⁡uy=R⁢sin⁡uz=v
S(u,v)=O+R⁢cos⁡u⁢X→+R⁢sin⁡u⁢Y→+v⁢Z→,(u,v)∈[0,2⁢π]×(−∞,+∞)
the way backu=atan2⁡(y,x),v=z

u closes on itself (S(u+2⁢π,v)=S(u,v)), and v does not close and is not bounded.

u goes around the axis and v moves along it. This is the only surface of the five whose two parameters are not the same kind of quantity: one is an angle, the other a length.

Cone

X Y Z α u apex v ρ P(u, v) COORDINATE BY COORDINATE x = ρ cos u y = ρ sin u z = v cos α ρ = R + v sin α zero at the apex α the half-angle a constant, not a parameter u round the axis v the distance along the ruling
A cone. Its two horizontal components are the cylinder’s, with a radius ρ that grows along the axis and reaches zero at the apex, where the surface stops being smooth.
x=ρ⁢cos⁡uy=ρ⁢sin⁡uz=v⁢cos⁡αρ=R+v⁢sin⁡α
S(u,v)=O+ρ⁢(cos⁡uX→+sin⁡uY→)+v⁢cos⁡α⁢Z→,(u,v)∈[0,2⁢π]×(−∞,+∞)
the way backu=atan2⁡(y,x),v=sin⁡α⁢(ρ−R)+cos⁡α⁢z

ρ is the radius of the circle at that v, and the only difference between a cone and a cylinder. u closes as the cylinder’s does, S(u+2⁢π,v)=S(u,v); v runs unbounded both ways, and at one value of it the surface reaches its apex.

This is the cylinder’s formula with a radius that grows along the axis, and α is the half-angle between the axis and the ruling. Two things in it are conventions that the geometry does not impose. A reader who has just seen the cylinder will probably notice the first one, and may not notice the second at all.

Why v=z/cos⁡α, and not v=z as for the cylinder? Nothing in the geometry forbids the second, and it is not unusual either: at least one kernel in current use writes the cone exactly that way. The only difference between the two is which side of one right triangle is called v.

α apex R v v cos α v sin α P(u, v) v ALONG THE RULING α apex R v / cos α v = z v tan α P(u, v) v IS THE HEIGHT FORWARD, AND BACK v a distance on the surface ‖∂S/∂v‖ = 1, for every α ρ = R + v sin α z = v cos α u = atan2(y, x) v = sin α (ρ − R) + cos α z FORWARD, AND BACK v the height, as on a cylinder ‖∂S/∂v‖ = sec α ρ = R + v tan α z = v u = atan2(y, x) v = z
The cone’s second parameter, twice. Both panels cut the same cone through the plane of its axis and the point, and both show the same right triangle. The two parametrisations differ only in which of its sides they call v. On the left v is the hypotenuse, and a step of 1 in it is a step of 1 across the surface. On the right v is the vertical leg, which makes the parameter plane the same as the cylinder’s (u and the height), but v is no longer a distance. u is the same angle in both, so it is printed under both.

Written out, and printed in the same way as the five above:

ρ=R+v⁢tan⁡α
S(u,v)=O+ρ⁢(cos⁡uX→+sin⁡uY→)+v⁢Z→,(u,v)∈[0,2⁢π]×(−∞,+∞)

the same cone, parametrised by height. The domain is the one above, u is the same angle, and only two things change: sin α becomes tan α, and the third component loses its cosine.

These are the same points (sampled across both, they agree to 10−13), and the conversion between the two is z=v⁢cos⁡α. The angle does not change: u is the same turn about the axis in both, which is why the figure prints it under both panels. What changes is the radius. Measured against the height it grows as tan α instead of sin α, because the height and the ruling are two different sides of that triangle: 0.532 against 0.470 on the 28° cone, and 11.430 against 0.996 at 85°, where the ruling is nearly flat.

Each form has a real advantage, and neither is obviously better. The height form gives one parameter plane for two surfaces. Its two parameters are an angle and a height, the same as the cylinder’s. So a curve crossing from a cylindrical face onto a conical one has coordinates that mean the same two things on both, the inverse map is plain cylindrical coordinates, and letting α go to zero turns the cone into the cylinder without either parameter changing what it measures. The open-source kernel volmdlr takes this route and documents it: its conical surface maps (θ, z) to a point through ρ = R + z tan α, and the method that goes the other way is documented as returning the cylindrical coordinates of the point.

The ruling form gives a parameter that is a length. With v measured along the ruling, ‖∂S/∂v‖ is exactly 1 for every α: a step of 1 in v is a step of 1 unit across the surface. With v as height it is sec α instead (1.133 at 28°, 2 at 60°, 11.5 at 85°): a constant, but a different one for every cone, and every arc length, deflection bound and tessellation step has to include it from then on. Which advantage matters more depends on what the kernel spends its time doing. A system whose hard problems are tessellation and offsetting wants the metric; a system that moves curves between faces in the parameter plane wants the shared convention. The formula at the top of this section makes the first choice, and the sec α is the cost of the second.

Run v far enough backwards and ρ reaches zero:

vapex=−Rsin⁡α

the parameter at which a cone’s radius reaches zero. Below it ρ goes negative and the surface continues as the opposite nappe.

This is the apex, and it is the first real defect in this list. Measured on a cone of radius 4 and half-angle 28°: the predicted apex parameter is −8.520218, evaluating the surface there at two quite different values of u returns the same point to the last bit, and that point is the one the library itself reports as the apex, (0, 0, −7.522905861), from both. A whole edge of the parameter rectangle is one point in space. Past it, ρ goes negative and the surface continues as the opposite nappe: the arithmetic is legal, but most callers do not expect to be given that region.

Why is the apex not the origin of the frame? Everything above is measured from a circle instead of a point: the frame sits on the reference circle of radius R, at v = 0, and the apex falls wherever the taper puts it (−8.52 along the ruling, −7.52 along the axis, two numbers for one place, which is the previous question again). Putting the origin at the apex is allowed: it is the case R = 0, the representation accepts it, and the kernel named above makes it the default, since its reference radius starts at zero and the frame sits on the apex unless told otherwise. The representation only declines to require it, for three practical reasons.

First, the apex is the only point of the surface with no normal, and a frame anchored there puts the datum of every measurement on the one place where the geometry breaks down. Second, the apex is often far from the part: for a 4-unit radius at a 1° draft angle it is 229 units away, and at 0.2° it is 1,146 units away, 286 radii outside the face it belongs to, so every coordinate of every point on the face would be a small difference of large numbers. Third, it would break the relation between cone and cylinder that this section relies on. With the reference circle as the datum, a cone is a cylinder plus an angle, and letting α go to zero takes us continuously from one to the other. From the apex there is no such limit, because as the taper flattens the apex goes to infinity. This is why the half-angle must stay strictly between zero and a right angle: at zero the cone is a cylinder and has no apex, and at a right angle it is a plane.

Sphere

X Y Z u v R ρ P(u, v) COORDINATE BY COORDINATE x = ρ cos u y = ρ sin u z = R sin v ρ = R cos v the radius of the circle of latitude v u longitude, v latitude both angles
A sphere. Both parameters are angles (u the longitude, v the latitude). The red dots are the poles, where a whole circle of u collapses to one point.
x=ρ⁢cos⁡uy=ρ⁢sin⁡uz=R⁢sin⁡vρ=R⁢cos⁡v
S(u,v)=O+ρ⁢(cos⁡uX→+sin⁡uY→)+R⁢sin⁡v⁢Z→,(u,v)∈[0,2⁢π]×[−π/2,π/2]
the way backu=atan2⁡(y,x),v=atan2⁡(z,ρ)

ρ is the radius of the circle of latitude v, the circle that collapses to a point at each pole. u closes, S(u+2⁢π,v)=S(u,v); v is bounded rather than periodic, and both of its bounds are reached.

Both parameters are angles: u is longitude, and v is latitude, measured from the equator and not from the pole. Both ends of the v range are degenerate: at v = ±π/2 the factor cos v is zero and the whole circle of longitudes collapses onto the axis.

Torus

X Y Z u v R ρ r P(u, v) COORDINATE BY COORDINATE x = ρ cos u y = ρ sin u z = r sin v ρ = R + r cos v v moves what u sweeps u round the axis, v round the tube both angles
A torus. Both parameters are angles again. v moves the point round the tube’s own circle (drawn whole, in purple), which changes the radius ρ that u then sweeps about the axis. The dashed circle of radius R is the path of the tube’s centre: a torus is the purple circle carried round the dashed one.
x=ρ⁢cos⁡uy=ρ⁢sin⁡uz=r⁢sin⁡vρ=R+r⁢cos⁡v
S(u,v)=O+ρ⁢(cos⁡uX→+sin⁡uY→)+r⁢sin⁡v⁢Z→,(u,v)∈[0,2⁢π]×[0,2⁢π]
the way backu=atan2⁡(y,x),v=atan2⁡(z,ρ−R)

the same shape as the cone, with v turning the radius instead of growing it. Both parameters close: S(u+2⁢π,v)=S(u,v) and S(u,v+2⁢π)=S(u,v), so this domain is the only one of the five that is a faithful picture of its own surface.

The formula has the same shape as the cone’s, except that v turns the radius instead of growing it. Both parameters are angles: u goes the long way round the axis, and v goes round the tube. The parameter rectangle, with both pairs of edges glued, is itself a torus, so the domain matches the surface more closely than for any other geometry here. This is also why the torus is the standard example for the counting rule from part one.

Each of the five also has a domain, and the domains differ as much as the formulas do: which parameter is periodic, whether a range is bounded, and whether some line of the rectangle collapses to a point. Here they are side by side, with the same rectangle drawn five times:

Plane u v −∞ ∞ −∞ ∞ no seam, no collapse Cylinder u v 0 2π −∞ ∞ u periodic, v a length Cone u v 0 2π −∞ ∞ the apex is inside the domain apex Sphere u v 0 2π −π/2 π/2 both v ends collapse Torus u v 0 2π 0 2π periodic both ways
a seam: two edges, one curve in space an edge, or a line, that is a single point
The five domains, drawn the same way. A dashed border means the rectangle runs to infinity in that direction; a shaded edge is a seam, where two edges are one curve; a red edge is a whole edge that is a single point in space. The torus is the only one whose rectangle is a faithful picture of its surface: glue both pairs of edges and we get the torus itself.

What the parameters measure

The formulas do not show directly whether a parameter is an angle or a length, but the derivative does. The magnitude of the partial derivative is how far the point moves for a unit step of the parameter, so it works as a unit conversion:

‖∂S∂u‖‖∂S∂v‖

how far the point moves for a unit step of the parameter. Where it is 1 the parameter is arc length; where it is a radius, the parameter is an angle.

Where it is 1, the parameter is arc length. Where it is a radius, the parameter is an angle, and that radius is the conversion factor. Where it depends on the other parameter, the conversion factor changes as we move over the surface. All three cases occur here. The table is measured: each entry is the library’s own first derivative at a sample point, agreeing with the formula beside it to the last bit:

Surface‖∂S/∂u‖u is‖∂S/∂v‖v is
Plane1a length1a length
CylinderRan angle1a length
Coneρ = R + v sin αan angle1a length along the ruling
SphereR cos van angleRan angle
Torusρ = R + r cos van angleran angle

From the table we can see three things. The sphere and the torus have two angular parameters, so neither of their parameters is a distance in any direction. The cylinder and the cone are the mixed cases, and their v is arc length (measured along the ruling for the cone, which is why that entry is 1 and not cos α). And for the cone, the sphere and the torus, the u-speed depends on v: the same step in u covers a long way near a sphere’s equator and almost nothing near its pole.

The last point has a practical consequence. A uniform grid in (u, v) is not a uniform grid on the surface, so a tessellator that samples parameter space evenly produces triangles that crowd at the poles and stretch at the equator. Every mesher has to correct for this, and the table above shows what it is correcting.

Seams, degenerate edges and self-intersection

None of these maps is an exact one-to-one correspondence between the rectangle and the surface. Three different things go wrong, and the first two appear as edges of the parameter rectangle. This is why the two figures in this section show the rectangle and the surface side by side instead of the surface alone.

The seam: two parameters, one point

Wherever a parameter is periodic, the two opposite edges of the rectangle are the same curve in space. Let’s evaluate a cylinder at u = 0 and at u = 2π, with the same v: the two points come back 9.8×10−16 apart, so we have one point with two parameters. This is the seam, which part one met from the topology side: the seam edge that appears once in 3D and twice in the parameter plane. The surface itself is fine there. But any code that turns a point back into a parameter has to choose between the two, and the geometry does not determine the choice.

u v 0 2π −h h u = 0 u = 2π S D — the parameter rectangle u = 0 = 2π
the seam: one curve in space, two edges in the rectangle
The seam. Both shaded edges of the rectangle are the same line on the cylinder: two parameters, one point, measured 9.8×10−16 apart. The surface is ordinary there; it is the rectangle that has two names for one place.

Degeneracy: a whole edge that is one point

The cone’s apex and the sphere’s two poles are edges of the rectangle that collapse to a point. At a sphere’s north pole the measured ‖∂S/∂u‖ is 1.5×10−15 (zero, to the available precision), while ‖∂S/∂v‖ stays at R. The surface normal is the cross product of the two:

n→=∂S∂u×∂S∂v

the surface normal. Where either derivative vanishes this cross product is the zero vector, so at a degenerate edge there is no normal.

So at a degenerate edge there is no normal. Every algorithm that asks a surface which way it faces needs a special case there, and the degenerate edges of part one (the ones with no 3D curve) exist to give the topology a place to record this.

u v 0 2π −π/2 π/2 v = π/2 v = −π/2 S D — the parameter rectangle one point one point
the two edges that are single points the seam, as on the cylinder
A degenerate edge. The top edge of the rectangle is a whole interval of u, and every point of it is the north pole; the bottom edge is the south. ‖∂S/∂u‖ measures 1.5×10−15 there, so the two derivatives no longer span a plane and the surface has no normal at either end.

Self-intersection of the torus

A torus is usually drawn with the ring radius larger than the tube radius, and then ρ = R + r cos v never reaches zero: it stays at or above R − r. Nothing in the formula requires this. If r is larger than R, ρ has two zeros:

R+r⁢cos⁡v=0

has no solution while R > r. Once the tube radius is larger than the ring radius it has two, and at each one an entire circle of u collapses to a single point on the axis.

Measured with R = 2 and r = 5, they are at v = 1.9823 and v = 4.3009, and at each of them the whole circle of u collapses to a single point on the axis: eight sampled longitudes return the identical point, and ‖∂S/∂u‖ is exactly zero. This is the same defect as the cone’s apex, twice, in the middle of a surface that has no apex and whose formula looks ordinary. The same five numbers describe either a regular ring or a self-intersecting spindle, and only an inequality between two of them says which.

In all three cases

Each failure is a place where the map from the rectangle to the surface stops being injective, or stops being an immersion, or both. The parametrisation is convenient, but the rectangle is not a faithful picture of the surface at its own edges. Most of the special cases in a kernel’s surface code are at these three places.

The inverse map: from point to parameter

The inverse map (given a point, return the parameter that produces it) is available in closed form for all ten geometries, and each one is printed under its own formula above. This is a large advantage. But every inverse inherits the defects of the forward map, so let’s look at what it returns in those places.

At a seam, the inverse has to pick one of two correct answers. Evaluate the cylinder at u = 0 and invert the result: we get 0. Evaluate at u = 2π and invert that: we get 2π. It is the same point in space, and the answer depends on which arithmetic produced the point we asked about.

At a pole the result is stranger. Ask the sphere for its exact north pole, the point (0, 0, R), and the inverse returns u = 0. It has to, because the longitude is not there to be recovered. But now evaluate the surface at u = 2.9, v = π/2 and invert the point that comes back. The answer is 2.900000.

A longitude from rounding error

The x and y coordinates of that evaluated pole are not zero. They are −2.97×10−16 and 7.33×10−17, the residue of computing R cos(π/2) in binary floating point. The inverse takes an arctangent of those two numbers and reconstructs the longitude from them. The answer is right, but only by accident: the information is carried entirely in rounding error, and a different order of operations upstream would produce a different longitude with equal confidence. So going from parameters to a point and back does not always return the same parameters.

This is why a kernel stores parameters alongside the topology instead of recomputing them when needed. The vertex parameter on an edge, the curve parameter range, and the parametric curve a face keeps for each of its edges are all, in part, a record of a choice that the geometry alone cannot reproduce.

Special cases or NURBS

Every curve and surface in this article can be written as a NURBS: the conics exactly, as rational quadratics, and the quadric surfaces as rational bi-quadratics. A kernel could use only that one representation, and some systems do. The ones that keep the special cases get four things in return.

AdvantageIn practice
Exactness that survives editingA circle’s radius is a number that was stored, not a consequence of control points and weights. It cannot drift, and it reads back as the number someone typed.
Inversion in closed formProjecting a point onto a cylinder is an atan2 and a dot product. Onto a general spline it is a Newton iteration that needs a starting guess and can fail to converge.
Intersections in closed formPlane against cylinder is a conic; plane against sphere is a circle. The general case is a marching algorithm with tolerance decisions at every step, and this is where a large share of Boolean failures come from.
RecognisabilitySTEP names these as entities in their own right, so a circle survives a round trip between kernels as a circle. Downstream, CAM wants to know a hole is a cylinder, and feature recognition keys on exactly this vocabulary.

STEP has the widest effect of the four. Its geometry schema defines line, circle, ellipse, hyperbola and parabola, and plane, cylindrical_surface, conical_surface, spherical_surface and toroidal_surface: the same ten, in the same canonical shape plus placement form. This is why every kernel has this list and not a slightly different one: it is the vocabulary the interchange format fixed, and a kernel that wants files to survive a round trip follows it.

The cost is paid in the algorithms, not in the data. Ten special cases mean an intersector with a table of pairings, each with its own closed form, its own degeneracies and its own tolerance behaviour, plus a fallback for everything else. Each entry is faster and more exact than the general method, and each is a place for a bug that the general method would not have had. Kernels that keep the special cases accept this cost deliberately.

What this article does not cover

Three topics, each of which needs its own article.

Free-form geometry. Bézier, B-spline and NURBS curves and surfaces: the representation that covers everything the ten above do not, without any of the advantages listed in the previous section. That is the next article, under the same title: the mathematics behind geometry, free-form. A kernel’s geometry divides into these two halves, and this article covers the half with closed forms.

Constructed surfaces. Surfaces of extrusion and revolution built on an arbitrary curve, offset surfaces, and the surfaces that appear as the result of an operation instead of something a user asked for. These are defined in terms of another geometry instead of in closed form, and they inherit its problems in addition to their own.

Bounding. Everything here is unbounded or fully closed. A cylinder is infinite, but the cylindrical face in a model is not. The difference comes from the topology of part one: the wires that cut a finite face out of an infinite surface, and the parametric curves that say where those wires run in the (u, v) rectangle. A shape needs both halves.

Reading list

Sources

  • I. Stroud, Boundary Representation Modelling Techniques, Springer, 2006. Read directly, for where elementary geometry sits inside a modelling system and what the datastructure has to hold alongside it.
  • I. Stroud and H. Nagy, Solid Modelling and CAD Systems: How to Survive a CAD System, Springer, 2011. Read directly. The practical counterpart, and the source of the idea that geometry and topology are counted and stored independently.
  • volmdlr, open source, surfaces.py. Read directly, for the cone written with the height as its second parameter: the parametric equation in the class’s own documentation, the reference radius defaulting to zero, and the inverse map described there as returning cylindrical coordinates. Named as theirs because they published it.
  • ISO 10303-42, the geometric and topological representation schema of STEP. Not consulted directly for this article. The entity names quoted above were taken from the entity set of a STEP translator instead of the standard itself, and are named here as evidence of the shared vocabulary, not as a citation of the text.

Method

  • Every closed form printed above was evaluated against a production kernel’s own evaluator at sampled parameters in a skew placement: 29 checks across the ten geometries, agreeing to the last bit in most cases. The derivative magnitudes, the apex parameter, the seam separations, the pole collapse and the spindle-torus pinch points are measured outputs of the same programs.
  • The figures are generated from the same formulas the article prints, in the same projection, and the generator checks that its own axis triad is right-handed before drawing. Nothing in them is traced or drawn by eye.
Revision history

. Points, vectors and directions, and canonical shape and placement, moved to part two, The Mathematics a Kernel Stands On; the sections that remain are renumbered, and the part numbers count the new part two.