What an intersection returns
Let’s start with what the caller needs back. Two curves meet at points, a curve meets a surface at points, and two surfaces meet along curves. Each point should come with its parameters on both pieces of geometry, because the caller will split an edge or a face there and needs to know where in its domain. Each curve of a surface–surface intersection should come with its two images in the parameter rectangles of the surfaces, the pcurves that part one attached to every coedge, because the curve is about to become the edge of two new faces.
Points and curves are not enough. Take a plane and a cylinder. The plane can cut the cylinder in two lines, touch it along one line, or miss it, and these three answers lead a Boolean down three different paths: two lines split the face, a line of contact may only mark where two faces touch, and nothing means nothing to do. A plane through the cylinder’s axis direction can also lie on a face of a box that is flush with the cylinder, in which case the two faces overlap over an area. So an intersection routine returns one of four kinds of answer:
- transversal: isolated points or curves where the two pieces cross;
- tangent: points or curves where they touch without crossing;
- coincident: the two share a whole curve or a whole region;
- empty.
So each pair of analytic types gets a result that names its case, such as two lines, a tangent line, coincident or empty, and the caller has to handle each one. Every point comes with its multiplicity as well, 1 where the two pieces cross and 2 where they touch, so the caller never has to work out which it was. The classification is where most of the difficulty lies, and section three is about it. First, the two ways an intersection can be computed at all.
Two routes: substitution and iteration
Part three wrote each elementary surface parametrically, as a map from (u, v) to a point. Each one also has an implicit form, an equation F(X) = 0 that a point satisfies exactly when it lies on the surface. With W = X − C measured from the surface’s centre or apex, and A its unit axis, the implicit forms are:
| Surface | F(X) = 0 | Degree |
|---|---|---|
| Plane, normal n | n·W | 1 |
| Sphere, radius r | |W|2 − r2 | 2 |
| Cylinder, radius r | |W|2 − (W·A)2 − r2 | 2 |
| Cone, half-angle α, apex C | (W·A)2 − cos2α |W|2 | 2 |
| Torus, radii R, r | (|W|2 + R2 − r2)2 − 4R2(|W|2 − (W·A)2) | 4 |
The cone’s equation describes both nappes, as the cone of part three does. If one piece of geometry has an implicit form and the other a parametric one, we can substitute: put the parametric curve into the implicit equation and get one equation in one unknown. A line O + tD substituted into a surface of degree n gives a polynomial of degree n in t, so a line meets a plane once, a quadric at most twice, and a torus at most four times. A conic substituted into a quadric gives degree at most four. These are closed forms, and every root they produce is exact to rounding.
When neither piece has a usable implicit form, which is the case for every B-spline, we iterate: write the condition that the two parametrisations give the same point, and solve it numerically with Newton’s method from starting points that a search has to supply. This is the route of sections eight to eleven. It works for any geometry, but it inherits the two problems of part six: an iteration converges to whatever is near its start, so the search must not miss anything, and at a tangency the equations become singular.
The two routes also say what kind of object an intersection curve is. Two quadrics meet in a curve of degree four in general, a space quartic, which is not one of the ten elementary geometries. Only in special positions does it break into conics and lines, and section six covers those. The quartic itself still has an exact description, because a cylinder and a cone are made of straight lines, and section seven builds it from them. Free-form surfaces, and a torus out of its special positions, go through the numerical route.
Tangency is a distance
Let’s take the simplest case where tangency matters: a line and a circle in a plane. A circle of radius 1 and a horizontal line at height 1 − d meet where x2 + (1 − d)2 = 1, at x = ±√(2d − d2). For d > 0 there are two roots, for d = 0 a double root, for d < 0 none.
Exact zero never happens in floating point, so the routine needs a tolerance, and the natural first attempt is to apply it to the roots: if the two roots are within 10−7 of each other, call them one tangent point. Let’s see what that does.
As we can see, a tolerance on the roots is a tolerance on the square root of the distance. A line that was built to touch the circle, and is off by rounding, comes out as two points almost a thousandth apart, or as nothing, depending on which way the rounding went. A Boolean given those two points splits the face at them and leaves a sliver between them.
The fix is to apply the tolerance to the quantity it is defined on, which is a distance in space. For the line and circle, the line’s closest approach to the centre is at distance δ = 1 − d, and the rule becomes: tangent if |δ − r| ≤ tolerance, two points if δ is smaller, nothing if larger. In general:
- Find the point of closest approach first. For a quadratic in t it is the vertex t* = −b/2a, the midpoint of the two roots, whether they are real or not.
- Measure the distance from the curve at t* to the surface. If it is within tolerance, report one tangent point at t*, with multiplicity two.
- Otherwise the sign of the discriminant decides between two points and none, and it is now safe, because the two roots are clearly separated.
With a tolerance of 10−7, a line along the top of the unit sphere, at height 1 + d, is one tangent point for every |d| ≤ 10−7. Just outside the band, at d = −2 × 10−7, it is two points already 1.265 × 10−3 apart, and above the band the line misses.
Two smaller rules make the closed forms of the next sections behave. First, centre the parameter. A line’s parameter starts wherever its origin happens to be, and a quadratic written about a far-away origin loses digits in its constant term; writing it about the closest approach, t = t* + s, makes s2 = r2 − δ2 the whole equation for a sphere. Second, solve quadratics without cancellation: compute q = −½(b + sign(b)√disc), and take the roots as q/a and c/q. The textbook formula subtracts two nearly equal numbers for the smaller root when the roots differ greatly in size.
Curves against curves in closed form
Two curves in space usually miss each other, so the closed forms for two curves work in a plane. When both curves lie in one plane, one of them is written as an implicit equation in that plane’s coordinates and the other is substituted into it, as section two did for surfaces. When their planes cross, a curve can meet the other only where it pierces the other’s plane. Two lines are the exception, solved directly in space. We parametrise the conics in a frame with centre or vertex P and in-plane axes X and Y:
ellipse P + a cos t X + b sin t Y
parabola P + (t2/4f) X + tY
hyperbola P + a cosh t X + b sinh t Y
with the circle as the ellipse with a = b = r, f the parabola’s focal length, and the hyperbola one branch. In the frame’s coordinates (x, y) their implicit equations are
x2/a2 + y2/b2 = 1, y2 = 4fx, x2/a2 − y2/b2 = 1
A line substituted into a conic gives a quadratic, a circle gives a trigonometric equation that becomes a quartic, and two ellipses give a quartic in one coordinate. Each card below gives the equation, the cases with their conditions, and a figure with a panel per case. The figures look straight down on the plane of the two curves, so circles stay round, except for the panels whose case needs depth.
Two lines
For the lines X1(s) = O1 + sD1 and X2(t) = O2 + tD2, with unit directions, write W = O1 − O2, c = D1·D2, d = D1·W and e = D2·W. The closest pair of points, where X1 − X2 is square to both lines, is at
s = (ce − d)/(1 − c2), t = (e − cd)/(1 − c2)
and 1 − c2 = |D1 × D2|2 is the squared sine of the angle between the lines. The lines meet if the two points are within ε of each other, and are skew otherwise. When 1 − c2 ≤ εa the lines are parallel, and the distance δ from O1 to the second line decides between parallel and coincident. In a plane the same system is solved as two equations in s and t, with determinant D1 × D2, and there is no skew case.
| Case | Condition | Intersection |
|---|---|---|
| point | 1 − c2 > εa, |X1(s) − X2(t)| ≤ ε | X1(s), with s and t |
| skew | 1 − c2 > εa, |X1(s) − X2(t)| > ε | none; s, t and the distance |
| parallel | 1 − c2 ≤ εa, δ > ε | none; the distance δ |
| coincident | 1 − c2 ≤ εa, δ ≤ ε | the whole line |
A line and a circle
In the circle’s plane, a line meets |x − C|2 = r2 as it meets a sphere. With W = O − C,
t2 + 2(W·D) t + |W|2 − r2 = 0
with vertex t0 = −W·D, the closest approach to the centre at distance δ = |W + t0D|, and roots t0 ± √(r2 − δ2). A line that crosses the circle’s plane meets it at one point, the line–plane point of section five, and that point is a hit only if it lies on the circle. A touch in the plane is a double root and a pierce is a single one, so the multiplicity returned with the point tells the caller which it was.
| Case | Condition | Intersection |
|---|---|---|
| two points | in the plane, δ < r − ε | t0 ± √(r2 − δ2) |
| tangent | in the plane, |δ − r| ≤ ε | t0, multiplicity 2 |
| empty | in the plane, δ > r + ε | none |
| one point | crossing the plane within ε of the circle | the crossing point, multiplicity 1 |
| empty | crossing the plane off the circle, or parallel to the plane and off it | none |
Two circles
In one plane, let d = |C2 − C1| be the distance between the centres and u = (C2 − C1)/d. Subtracting the two circles’ equations leaves a line square to u, the radical line, at distance a from C1, and the points lie on it:
a = (r12 − r22 + d2)/2d, h = √(r12 − a2), C1 + au ± hu⊥
The circles touch when d is within ε of r1 + r2, from outside, or of |r1 − r2|, from inside, and the point of contact is C1 + au. Circles in parallel planes miss. Circles in crossing planes meet only on the line where the planes cross, and the last card of this section solves them.
| Case | Condition | Intersection |
|---|---|---|
| points | |r1 − r2| + ε < d < r1 + r2 − ε | C1 + au ± hu⊥ |
| tangent | d within ε of r1 + r2 or of |r1 − r2| | C1 + au |
| empty | d > r1 + r2 + ε, d < |r1 − r2| − ε, or parallel planes apart | none |
| coincident | d ≤ ε and |r1 − r2| ≤ ε | the whole circle |
| crossing planes | the planes cross | up to two points, on the line where the planes meet: see the last card |
A line and a conic
Write the line in the conic’s frame as (ox + tdx, oy + tdy). The ellipse’s equation becomes a quadratic in t,
(dx2/a2 + dy2/b2) t2 + 2(oxdx/a2 + oydy/b2) t + ox2/a2 + oy2/b2 − 1 = 0
the hyperbola’s is the same with the b2 terms negated, and the parabola’s is
dy2 t2 + (2oydy − 4fdx) t + oy2 − 4fox = 0
Tangency is decided at the vertex, as in section three. The parabola’s leading coefficient vanishes for a line parallel to its axis, dy = 0, and the hyperbola’s for a line parallel to an asymptote, dx/a = ±dy/b. The equation is then linear, and its one root is a crossing. The hyperbola here is one branch, so a root on the other branch is dropped, and a line across both branches comes back with one hit. Only the double root at the vertex is a touch; every other single hit is a crossing, of multiplicity 1. A line that crosses the conic’s plane is handled as for the circle.
| Case | Condition | Intersection |
|---|---|---|
| two points | two roots, both on the conic | the two points |
| tangent | a double root at the vertex | one point, multiplicity 2 |
| one point | a linear root, parallel to the parabola’s axis or an asymptote; one root left after the other branch; or crossing the plane on the conic | one point, multiplicity 1 |
| empty | no root on the conic, or crossing the plane off it | none |
A circle and a conic
Put the circle’s centre at (cx, cy) in the conic’s frame and its points at (cx + r cos s, cy + r sin s), with s measured from the conic’s X. Each conic’s equation has the form αx2 + βy2 + γx + κ = 0: the ellipse with α = 1/a2, β = 1/b2, γ = 0, κ = −1; the parabola with α = 0, β = 1, γ = −4f, κ = 0; the hyperbola as the ellipse with β = −1/b2. Substituting the circle and collecting the products of sines and cosines gives
A cos 2s + B sin 2s + C cos s + D sin s + E = 0
A = r2(α − β)/2, B = 0, C = r(2αcx + γ), D = 2rβcy
E = αcx2 + βcy2 + γcx + κ + r2(α + β)/2
with B = 0 because no conic has an xy term in its own frame. The half-angle substitution u = tan(s/2), with cos s = (1 − u2)/(1 + u2) and sin s = 2u/(1 + u2), multiplied through by (1 + u2)2, gives a quartic whose coefficients in ascending powers of u are
A + C + E, 4B + 2D, −6A + 2E, −4B + 2D, A − C + E
so there are at most four hits. Each root is checked on the conic, which also drops the hyperbola’s other branch. The substitution cannot reach s = π, which is u = ∞, so s = π is tried separately. Near it, a root is a large u, and a tangency there is a double root at large u that rounding can turn into a pair of complex roots or split in two. Near s = π, decide tangency on the distance between the two conics at their closest approach, as section three does, and not on the roots. A double root away from s = π is one point of multiplicity 2, and the multiplicity is what separates two contacts from two crossings. A circle on a circular ellipse with its centre and radius is coincident, and the planes are tested as for two circles.
| Case | Condition | Intersection |
|---|---|---|
| points | two to four roots on the conic | the points, each of multiplicity 1 where they cross and 2 where they touch |
| tangent | exactly one root on the conic, a double one | one point, multiplicity 2 |
| empty | no root on the conic, or parallel planes apart | none |
| coincident | an ellipse with a = b = r, its centre within ε of the circle’s | the whole circle |
| crossing planes | the planes cross | up to two points, on the line where the planes meet: see the last card |
Two ellipses
Work in the first ellipse’s frame, where it is x2/a12 + y2/b12 = 1. The second, with centre c and axes the columns of a rotation R in that frame, is (x − c)TQ(x − c) = 1 with Q = R diag(1/a22, 1/b22) RT, which expands to a general conic
qax2 + qby2 + qcxy + qdx + qey + qf = 0
with qa = Q11, qb = Q22, qc = 2Q12, (qd, qe) = −2Qc and qf = cTQc − 1. Read it as a quadratic in y, with β(x) = qcx + qe its linear coefficient, and replace y2 by the first ellipse’s δ(x) = b12(1 − x2/a12). What is left is linear in y, β(x) y + η(x) = 0 with η(x) = qbδ(x) + qax2 + qdx + qf, and squaring it against y2 = δ(x) gives a quartic in x:
β(x)2 δ(x) − η(x)2 = 0
Each real root gives y = −η/β, or both ±√δ where β vanishes, and a point is kept when it lies on both ellipses within ε, which removes the roots the squaring added. Where the two values ±√δ are within ε of each other the ellipses touch at the end of the first one’s major axis, and we take the point on the axis, since √δ magnifies the rounding of x there. This quartic has no point it cannot reach, unlike the half-angle one. Ellipses with the same centre and radii coincide when their major axes are parallel, or when both are circles.
| Case | Condition | Intersection |
|---|---|---|
| points | two to four points kept | the points, each of multiplicity 1 where they cross and 2 where they touch |
| tangent | exactly one point kept, a double one | one point, multiplicity 2 |
| empty | no point kept, or parallel planes apart | none |
| coincident | same centre and radii within ε, major axes parallel | the whole ellipse |
| crossing planes | the planes cross | up to two points, on the line where the planes meet: see the last card |
Conics in crossing planes
Two conics whose planes cross can only meet on the line L where the planes cross, so we intersect each conic with L in its own plane and compare. With the planes n1·X = d1 and n2·X = d2 and m = n1 × n2, the line is L0 + λu, with
L0 = (d1 n2 × m + d2 m × n1)/|m|2, u = m/|m|
Each conic against L is the line–conic card above, in that conic’s plane, and gives at most two values of λ. A value that both conics share within ε is a hit. So two conics in crossing planes meet at most twice, and they cannot coincide. A hit is a crossing, of multiplicity 1, unless both conics touch L at that point. Then they share the tangent u there, and the hit has multiplicity 2.
| Case | Condition | Intersection |
|---|---|---|
| two points | two values of λ shared within ε | L0 + λu at each, multiplicity 1 |
| one point | one value shared | the point, multiplicity 1, or 2 where both conics touch L |
| empty | no value shared, or a conic that misses L | none |
Curves against surfaces in closed form
A curve meets a surface where its parametrisation satisfies the surface’s implicit equation, and substituting one into the other leaves a single equation in the curve’s parameter. Its roots are the hits. The three quadrics share one form,
(x − Q)TM(x − Q) = k
with Q the sphere’s centre, a point of the cylinder’s axis or the cone’s apex. For the sphere, M = I and k = r2. For the cylinder with unit axis a, M = I − aaT and k = r2, and for the double cone of half-angle α, M = aaT − cos2α I and k = 0. A line gives a quadratic, a conic a quartic, and the torus a quartic for a line. Each card below gives the equation, the cases with their conditions, and a figure with a panel per case. A tangent hit is a double root, and it is decided as section three argued, on the distance from the surface at the vertex of the equation.
A line and a plane
For the line X(t) = O + tD, with D a unit vector, and the plane n·(x − P) = 0, substitution gives a linear equation:
(n·D) t + n·(O − P) = 0
| Case | Condition | Intersection |
|---|---|---|
| point | |n·D| > εa | t = −n·(O − P)/n·D |
| parallel | |n·D| ≤ εa, |n·(O − P)| > ε | none |
| coincident | |n·D| ≤ εa, |n·(O − P)| ≤ ε | the whole line |
A line and a sphere
With W = O − C, the sphere’s equation along the line is
t2 + 2(W·D) t + |W|2 − r2 = 0
Its vertex t0 = −W·D is the line’s closest approach to the centre, at a distance δ = |W + t0D|, and the roots are t0 ± √(r2 − δ2).
| Case | Condition | Intersection |
|---|---|---|
| two points | δ < r − ε | t0 ± √(r2 − δ2) |
| tangent | |δ − r| ≤ ε | t0 |
| empty | δ > r + ε | none |
A line and a cylinder
With W = O − Q, wa = W·a and da = D·a, the cylinder’s equation along the line is
(1 − da2) t2 + 2(W·D − wada) t + |W|2 − wa2 − r2 = 0
The leading coefficient is sin2θ, with θ the angle between the line and the axis. While it is nonzero, the vertex is the line’s closest approach to the axis, at a distance δ, and the cases are the sphere’s. When it is zero the line is parallel to the axis, the linear term vanishes with it, and the line lies on the cylinder or misses it.
| Case | Condition | Intersection |
|---|---|---|
| two points | sin2θ > εa, δ < r − ε | the two roots |
| tangent | sin2θ > εa, |δ − r| ≤ ε | the vertex |
| empty | sin2θ > εa, δ > r + ε | none |
| coincident | sin2θ ≤ εa, the line on the cylinder | the whole line, a generator |
| empty | sin2θ ≤ εa, the line off it | none |
A line and a cone
With W = O − Q from the apex, the double cone’s equation along the line is
(da2 − cos2α) t2 + 2(wada − cos2α W·D) t + wa2 − cos2α |W|2 = 0
The leading coefficient is cos2θ − cos2α, and the angle θ between the line and the axis sorts the lines. A line steeper than the cone, θ < α, is inside the cone at both ends, so it crosses the surface twice, once on each nappe. A shallower line, θ > α, is outside at both ends, and it crosses one nappe twice, touches it, or misses it. A line parallel to a generator, θ = α, leaves a linear equation and meets the cone once. If the linear term vanishes too, the line is a generator or lies in the plane tangent along one without touching it. Any line through the apex has a double root there, because the cone is singular at its apex, so the apex comes back with multiplicity 2.
| Case | Condition | Intersection |
|---|---|---|
| two points | |cos2θ − cos2α| > εa, two roots, the vertex off the cone | one on each nappe when θ < α |
| tangent | |cos2θ − cos2α| > εa, the vertex within ε of the cone | the vertex: in a tangent plane, or the apex |
| empty | θ > α, no real root | none |
| one point | |cos2θ − cos2α| ≤ εa, linear term above ε | t = −c/b, constant over linear coefficient |
| coincident | |cos2θ − cos2α| ≤ εa, linear term within ε, the line on the cone | the whole line, a generator |
| empty | the same, the line off the cone | none |
A line and a torus
The torus gives a quartic. Writing ρ2(t) = |W + tD|2 − (wa + tda)2 for the squared distance from the axis, and k = |W|2 + R2 − r2, the equation (t2 + 2(W·D)t + k)2 = 4R2ρ2(t) expands to
t4 + 4m t3 + (4m2 + 2k − 4R2(1 − da2)) t2
+ (4mk − 8R2(m − wada)) t + k2 − 4R2(|W|2 − wa2) = 0, m = W·D
A quartic has up to four real roots, and tangency appears as a double root. The tangency rule of section three still applies, with the critical points of the quartic (the roots of its derivative, a cubic) in place of the single vertex: wherever the curve’s distance to the torus at a critical point is within tolerance, the roots on either side of it merge into one tangent point.
| Case | Condition | Intersection |
|---|---|---|
| hits | real roots, after merging at touching critical points | up to four points, each with its multiplicity: 2 for a tangent hit |
| empty | no real root | none |
A conic and a plane
With the conics parametrised as in section four and e = n·(P − P0) for the plane through P0, the plane’s equation along each is short. For the ellipse, with C = a n·X and D = b n·Y,
C cos t + D sin t + e = 0, t = φ ± arccos(−e/√(C2+D2)), φ = atan2(D, C)
tangent when |e| is within εs of √(C2+D2), with s a length scale, |P − P0| + a + b for an ellipse and |P − P0| + r + 1 for a circle. The parabola gives a quadratic in t, (n·X/4f) t2 + (n·Y) t + e = 0. The hyperbola gives C cosh t + D sinh t + e = 0, which with u = et becomes the quadratic (C + D) u2 + 2e u + C − D = 0, keeping the roots with u > 0. When the conic’s plane is parallel to the plane, n·X = n·Y = 0, and e alone decides.
| Case | Condition | Intersection |
|---|---|---|
| hits | the planes cross, real roots | up to two points, each with its multiplicity |
| empty | no real root, or the planes parallel and |e| > ε | none |
| circle | a circle with its plane parallel and |e| ≤ ε | the circle itself |
| coincident | an ellipse, parabola or hyperbola in the plane | the whole curve |
A conic and a quadric
Substituting the ellipse into the quadric form, with W = P − Q, the products of sines and cosines collect into
A cos 2t + B sin 2t + C cos t + D sin t + E = 0
A = ½(a2XTMX − b2YTMY), B = ab XTMY, C = 2a XTMW, D = 2b YTMW
E = WTMW + ½(a2XTMX + b2YTMY) − k
and the half-angle substitution of section four, s = tan(t/2), turns it into the same quartic, which in ascending powers of s has the coefficients
A + C + E, 4B + 2D, −6A + 2E, −4B + 2D, A − C + E
It has the blind spot part six found: t = π is s = ∞, so t = π is always added as a candidate. The parabola needs no substitution, because it is already polynomial:
(XTMX/16f2) t4 + (XTMY/2f) t3
+ (YTMY + XTMW/2f) t2 + 2YTMW t + WTMW − k = 0
The hyperbola gives the same five-term equation with cosh and sinh, its A and E having ½(a2XTMX + b2YTMY) and ½(a2XTMX − b2YTMY) in place of the ellipse’s. With u = et, multiplying by 2u2 gives the quartic
(A + B) u4 + (C + D) u3 + 2E u2 + (C − D) u + A − B = 0, u > 0
Each candidate is then checked by evaluating the conic there and measuring its distance to the surface. That check is the final word, and its tolerance should be at least a few units in the last place of the point’s largest coordinate: a point a thousand units from the origin cannot be placed more finely than about 10−13, whatever the tolerance says.
The degree bound gives a cheap test for coincidence. On a conic, a quadric’s equation is a polynomial of degree at most four, in tan(t/2), in t or in et. A nonzero polynomial of degree four has at most four roots, so if five distinct points of the conic lie on the surface, the polynomial is identically zero and the whole conic lies on it.
| Case | Condition | Intersection |
|---|---|---|
| hits | candidates that pass the distance check | up to four points, each with its multiplicity: 2 for a tangent hit |
| empty | no candidate passes | none |
| circle | a circle lying on the surface | the circle itself |
| coincident | an ellipse, parabola or hyperbola with five distinct points on the surface | the whole curve |
Surfaces against surfaces in closed form
Two surfaces meet in circles, conics and lines only in special positions, and a kernel recognises the position first and computes second. This section covers those positions; section seven takes up two quadrics in general position, where the intersection is a quartic. Each pair has a table of its cases, with the condition that selects each one and the result, and a figure with a panel per case. Throughout, ε is the distance tolerance and εa the angular one, typically 10−7 and 10−12, and a tangent case is a band of width ε around an equality, as section three argued. Where a condition is a squared length, the band is scaled to match.
Plane and plane
With unit normals n1 and n2, the line runs along d = n1 × n2. A point on it satisfies both plane equations ni·x = ei. Set to zero the coordinate in which d is largest, and the two equations leave a 2 by 2 system in the other two, whose determinant is that largest component of d.
| Case | Condition | Intersection |
|---|---|---|
| line | |d| > εa | the line through that point along d |
| parallel | |d| ≤ εa, planes more than ε apart | none |
| coincident | |d| ≤ εa, planes within ε | the whole plane |
Plane and sphere
Let δ = n·(C − P) be the signed distance from the sphere’s centre C to the plane through P, and F = C − δn the foot of the centre on the plane.
| Case | Condition | Intersection |
|---|---|---|
| circle | |δ| < r − ε | centre F, axis n, radius √(r2 − δ2) |
| tangent point | ||δ| − r| ≤ ε | the point F |
| empty | |δ| > r + ε | none |
Sphere and sphere
With radii R and r, centres d apart and e the unit vector from the first centre to the second, subtracting the two sphere equations leaves a plane square to e, the radical plane, at
h = (d2 + R2 − r2) / 2d, ρ2 = R2 − h2
from the first centre C1, and the intersection is the first sphere cut by that plane. ρ2 is a squared length, so its band is 2ε max(R + r + d, 1), about ε times the size of the configuration.
| Case | Condition | Intersection |
|---|---|---|
| circle | ρ2 above the band | centre C1 + he, axis e, radius ρ |
| tangent point | ρ2 within the band: d = R + r or d = |R − r| | the point C1 + he |
| empty | ρ2 below the band, or d ≤ ε with |R − r| > ε | none |
| coincident | d ≤ ε and |R − r| ≤ ε | the whole sphere |
Plane and cylinder
Let a be the cylinder’s axis, θ the angle between the plane’s normal and a, and s = n·a = cos θ. Where the axis crosses the plane, which is the centre of the section, the cylinder’s cross-section is stretched along the axis’s shadow on the plane by 1/|cos θ|. When the plane is parallel to the axis, the distance δ from the axis to the plane decides, as for the sphere.
| Case | Condition | Intersection |
|---|---|---|
| circle | sin θ ≤ εa | radius r |
| ellipse | sin θ > εa, |s| > εa | semi-axes r/|s| along the axis’s shadow and r across |
| two lines | |s| ≤ εa, |δ| < r − ε | generators ±√(r2 − δ2) either side of the axis’s foot |
| tangent line | |s| ≤ εa, ||δ| − r| ≤ ε | the generator through the foot |
| empty | |s| ≤ εa, |δ| > r + ε | none |
Plane and cone
The conic sections. With α the cone’s half-angle, θ the angle between the plane’s normal and the axis folded into [0, 90°], and σ the distance from the apex to the plane, the cases split first on whether the plane passes through the apex and then on θ against 90° − α, the angle at which the plane is parallel to a generator.
Off the apex, take coordinates in the plane from the foot of the apex: λ along M, the axis’s shadow on the plane, and w across it. A point X is on the cone when (X − apex)·a = |X − apex| cos α. With s = n·a = ±cos θ, squaring and dividing by cos2α gives
w2 + Aλ2 + Bλ + C = 0
A = (cos2α − sin2θ)/cos2α, B = −2σs sin θ/cos2α, C = σ2(cos2α − s2)/cos2α
The sign of A is the classification: positive below θ = 90° − α, zero at it, negative beyond. Completing the square, the centre of the ellipse or hyperbola is at λc = −B/2A. With K = B2/4A − C, the semi-axes are √(K/A) along M and √K across, using absolute values for the hyperbola. The parabola’s vertex is at λ = −C/B, and its focal length is |B|/4.
Through the apex, every generator meets the plane at the apex unless it lies in the plane. A generator is the line through the apex along d(φ) = (sin α cos φ, sin α sin φ, cos α), and it lies in the plane when n·d(φ) = 0. With the normal leaning in the XZ plane, that condition is cos φ = −cot α cot θ.
| Case | Condition | Intersection |
|---|---|---|
| circle | |σ| > ε, sin θ ≤ εa | radius |σ| tan α, at the foot of the apex |
| ellipse | |σ| > ε, θ < 90° − α − εa | closed, on one nappe |
| parabola | |σ| > ε, |θ − (90° − α)| ≤ εa | one open branch |
| hyperbola | |σ| > ε, θ > 90° − α + εa | two branches, one on each nappe |
| apex point | |σ| ≤ ε, θ < 90° − α − εa | the apex: no generator lies in the plane |
| tangent line | |σ| ≤ ε, |θ − (90° − α)| ≤ εa | one generator, the double root φ = π |
| two lines | |σ| ≤ ε, θ > 90° − α + εa | the generators at φ = ±arccos(−cot α cot θ) |
We decide the tangent rows on the angle θ itself, which changes linearly as the plane tilts. A test on cos φ would be far narrower. For a 30° cone, the section is an ellipse at θ = 45°, a parabola at 60° and a hyperbola at 75°.
Two cylinders with parallel axes
Parallel cylinders are two circles in a cross-section, extruded along the axis. With radii R and r, axes d apart and e the unit vector across from the first axis to the second, the cross-sections meet on the radical line at s = (d2 + R2 − r2)/2d, at heights ±h = ±√(R2 − s2) along a × e. Axes that are not parallel give a space quartic, which section seven solves.
| Case | Condition | Intersection |
|---|---|---|
| two lines | |R − r| + ε < d < R + r − ε | lines along a through se ± h a × e |
| tangent line | d within ε of R + r or of |R − r| | the line through se |
| empty | d > R + r + ε, or d < |R − r| − ε | none |
| coincident | d ≤ ε and |R − r| ≤ ε | the whole cylinder |
Surfaces of revolution on one axis
When two surfaces of revolution share an axis, the whole problem lives in one meridian half-plane, with coordinates (ρ, z). Each surface is a curve there: a plane square to the axis is a horizontal line, the cylinder a vertical line, the cone a pair of slanted lines from its apex, the sphere a half circle centred on the axis, and the torus a circle off it. Intersecting the two surfaces is intersecting these two plane curves, which is a line or circle problem with a closed form. Each meeting point (ρ, z) with ρ > 0 is a circle of latitude in space, of radius ρ at height z. A meeting point on the axis is a single point, meridians that touch give surfaces that touch along a whole circle, and meridians that coincide give coincident surfaces.
Two meridian circles meet where their equations, subtracted, agree. The squares cancel and leave a line, the radical line. Substituting it back into one circle gives a quadratic in z, whose two, one or no roots are two circles, a tangent circle, or none. That is how each pair below is solved.
Sphere and cylinder on its axis
A sphere of radius R centred at height c on the axis, and a cylinder of radius r: the meridians ρ2 + (z − c)2 = R2 and ρ = r meet at z = c ± √(R2 − r2).
| Case | Condition | Intersection |
|---|---|---|
| two circles | r < R − ε | radius r at z = c ± √(R2 − r2) |
| circle | |r − R| ≤ ε | the equator, where the two touch |
| empty | r > R + ε | none |
Sphere and cone on its axis
Measure t along the axis from the apex, put the sphere’s centre at t = c, and let its radius be R. The cone’s meridian ρ = |t| tan α in the sphere’s gives t2/cos2α − 2ct + c2 − R2 = 0, so
t = c cos2α ± cos α √D, D = R2 − c2sin2α
Each root is a circle of radius |t| tan α. Both lie on one nappe unless the sphere holds the apex, |c| < R, when there is one on each. D is a squared length, and its band is ε max(R2 + c2, 1).
| Case | Condition | Intersection |
|---|---|---|
| two circles | D above the band | the two roots |
| tangent circle | D within the band: R = |c| sin α | one circle at t = c cos2α |
| empty | D below the band | none |
A cone with a cylinder or a cone on its axis
A cylinder of radius r on a cone’s axis meets each nappe once, at t = ±r/tan α from the apex: two circles, both of radius r.
For two cones on one axis, with half-angles α and α′, k = tan α, k′ = tan α′, and the second apex at t = d on the first cone’s axis, the meridians meet where k|t| = k′|t − d|. That happens at
t = k′d / (k′ + k) and t = k′d / (k′ − k)
The first is between the apexes and the second outside them, and the second disappears when the angles are equal.
| Case | Condition | Intersection |
|---|---|---|
| two circles | |d| > ε, |α − α′| > εa | the two rings above, of radius k|t| |
| circle | |d| > ε, |α − α′| ≤ εa | one ring at t = d/2 |
| apex point | |d| ≤ ε, |α − α′| > εa | the shared apex |
| coincident | |d| ≤ ε, |α − α′| ≤ εa | the whole cone |
Torus and plane
Take the torus with major radius R and minor radius r, centred at the origin about a. Three positions of the plane have a closed form. A plane square to the axis at height h is the coaxial case, a horizontal line meeting the tube’s meridian circle. A plane containing the axis cuts the two meridian circles themselves. A plane through the centre tilted from the equator by θ = asin(r/R), θ being the angle between n and a, touches the tube at two points and cuts it in two circles of radius R, the Villarceau circles. Their centres lie at distance r from the torus’s centre, one on each side, along the line where the plane crosses the equatorial plane, and the circles cross each other at the two points of contact. Tilted 10−7 radians further, the plane is no longer special, and the section is a general quartic, left to marching.
| Case | Condition | Intersection |
|---|---|---|
| two circles | square to the axis, |h| < r − ε | radii R ± √(r2 − h2) at height h |
| tangent circle | square to the axis, ||h| − r| ≤ ε | radius R at height h |
| empty | square to the axis, |h| > r + ε | none |
| circle | square to the axis, R < √(r2 − h2), a spindle torus | the outer circle only, radius R + √(r2 − h2) |
| two circles | the axis lies in the plane | radius r, centred ±R along n × a |
| two circles | through the centre, |R sin θ − r| ≤ ε | radius R, centred ±r along n × a |
| general | any other plane | a quartic, for marching |
Torus and cylinder on its axis
A cylinder of radius c is the vertical line ρ = c in the meridian plane, which meets the tube’s circle (ρ − R)2 + z2 = r2 at z = ±√(r2 − (c − R)2).
| Case | Condition | Intersection |
|---|---|---|
| two circles | |c − R| < r − ε | radius c at those two heights |
| tangent circle | ||c − R| − r| ≤ ε | radius c at z = 0, the outer or inner equator |
| empty | |c − R| > r + ε | none |
Torus and sphere on its axis
A sphere of radius s centred at height c on the axis has the meridian ρ2 + (z − c)2 = s2. Subtracting the tube’s circle leaves the radical line, and substituting it into the sphere gives a quadratic in z:
2Rρ = K + 2cz, K = R2 − r2 − c2 + s2
(1 + c2/R2) z2 + 2(Kc/2R2 − c) z + K2/4R2 + c2 − s2 = 0
Each root z is a circle of radius ρ = (K + 2cz)/2R, kept only if ρ ≥ 0. A sphere centred off the axis meets the torus in a curve of degree eight, left to marching.
| Case | Condition | Intersection |
|---|---|---|
| two circles | two roots, both with ρ ≥ 0 | a circle at each root |
| circle | two roots, one with ρ < 0 | the other circle |
| tangent circle | a double root | one circle, where the two touch |
| empty | no real root | none |
Torus and cone on its axis
A cone with its apex at height a on the axis and k = tan α has the meridian ρ = m(z − a) on each nappe, with m = k on one and −k on the other. In the tube’s circle it gives a quadratic per nappe:
(m2 + 1) z2 − 2m(ma + R) z + (ma + R)2 − r2 = 0
Only roots with m(z − a) ≥ 0 lie on that nappe. Up to four rings come out, and a double root is a tangent ring. A cone whose axis or apex is off the torus’s axis meets it in a curve of degree eight, left to marching.
| Case | Condition | Intersection |
|---|---|---|
| rings | a root on either nappe | a ring of radius m(z − a) at each root, flagged tangent for a double root |
| empty | no root on either nappe | none |
Two tori on one axis
With the second torus of radii R′ and r′ centred at height z′, the two tube circles subtract to the radical line
2(R′ − R) ρ = r2 − r′2 − R2 + R′2 + z′2 − 2zz′
Substituting it into the first circle gives a quadratic in z, as for the sphere. When the major radii are equal the line is horizontal instead, at z* = (r2 − r′2 + z′2)/2z′, and the rings have radii R ± √(r2 − z*2). Tori on different axes meet in a curve of degree up to sixteen, left to marching.
| Case | Condition | Intersection |
|---|---|---|
| two circles | two roots, both with ρ ≥ 0 | a circle at each root |
| circle | two roots, one with ρ < 0 | the other circle |
| tangent circle | a double root | one circle, where the two touch |
| empty | no real root | none |
| coincident | same centre, same radii | the whole torus |
Everything else. Two cylinders with crossing axes, a sphere off a cylinder’s axis, a cone tilted against another: two quadrics off these special positions meet in a space quartic, and section seven still solves them without iterating. A slanted plane through a torus, or a quadric off the torus’s axis, meets it in a curve of degree four to eight, and the kernel hands those to the marching of section ten. The closed forms are worth having for the cases above because they are exact and cheap, and because the special positions are the ones designers build: a hole drilled along an axis, a fillet sphere on a cylinder’s axis, a plane cut square to a shaft.
Two quadrics in general position
Off the special positions of section six, two quadrics meet in a space quartic, a curve of degree four. It still has a closed form, because one of the two surfaces is almost always ruled. A cylinder and a cone are made of straight lines, their generators, and among the elementary quadrics only the sphere is not ruled. Two spheres meet in a circle, and a plane against anything is section six, so every pair left has a cylinder or a cone in it. A generator meets the other quadric in a quadratic, and solving that quadratic for every generator gives the whole curve, one point per root, in closed form. Levin’s method for any two quadrics rests on the same idea, and Dupont, Lazard, Lazard and Petitjean made it exact and near-optimal; with a cylinder or a cone already in hand, the walk below is the simple case of it.
Walking the generators
Write the ruled quadric as a family of lines X = B(t) + sD(t), with t going once round it. For a cylinder of radius r about the line through C along a, with u and v completing a frame,
B(t) = C + r(cos t u + sin t v), D = a
and for a cone with apex O, axis a and half-angle α, B = O and D(t) = cos α a + sin α(cos t u + sin t v), with negative s on the other nappe. Put the generator into the other quadric’s equation F from section two. F has degree two, so
F(B + sD) = A(t) s2 + 2β(t) s + γ(t) = 0
with A the quadratic part of F applied to D, 2β = ∇F(B)·D and γ = F(B). The generator meets the other quadric where
s±(t) = (−β ± √Δ)/A, Δ(t) = β2 − Aγ
computed without cancellation as in section three, q = −(β + sign(β)√Δ) and the roots q/A and γ/q. The sign of Δ over the circle of generators gives the shape of the curve.
- Δ > 0 for every t: two loops, one per root, each going once round the ruled quadric.
- Δ ≥ 0 on arcs of t, zero at their ends: one loop per arc, out along s+ and back along s−. At the ends the generator touches the other quadric and the two roots meet.
- Δ with a double zero inside an arc: the roots meet there without parting, so the loop passes through the same point twice and crosses itself. This is a node, and the two surfaces touch at it.
- Δ ≤ 0 with a single double zero: a tangent point, where one generator touches the other quadric.
- Δ < 0 everywhere: empty.
- A = 0 at some t: the generator is parallel to an asymptotic direction of the other quadric, one root runs off to infinity, and the curve has unbounded branches. This needs a cone, and the card on two cones treats it.
The arc ends are closed forms for each pair below, usually an arccosine. Tangency is decided on distances, as section three argued: a node or a tangent point is a band of width ε round an equality between distances, and a configuration inside the band is moved onto the equality before the curve is computed, for instance by changing each cylinder’s radius by half the difference, so that the node comes out as an exact double zero of Δ. Otherwise the two roots would come out almost a thousandth apart, by the square-root rule of section three, and a loop that should cross itself would come apart into two near-touching loops.
Each loop is exact as a function of t, and a kernel can keep it that way, as an evaluator of the formulas. To hand it to modelling as a B-spline, interpolate points and tangents from the formulas, a cubic Hermite span between consecutive samples, and refine until the midpoint and the quarter points of every span lie within ε/4 of the exact curve. Measure that against the curve, not against the two surfaces. Where the surfaces meet at a small angle, with c the cosine between their normals, a point at distances g1 and g2 from them lies at
√((g12 + g22 − 2c g1g2)/(1 − c2))
from their intersection to first order, which grows without bound as c → 1, so a span close to both surfaces can still be far from the curve near a node. The pcurve on the ruled quadric is (t, s(t)) directly. On the other surface it comes from that surface’s closed-form inverse, which has no answer at a pole of a sphere, so a loop through a pole is split there or the sphere’s frame is turned to keep the poles off it.
Two cylinders
Take the first cylinder of radius R about the z axis, and put x along the common normal of the two axes. The second, of radius r, has its axis through (d, 0, 0) along (0, sin ψ, cos ψ), so d is the distance between the axes and ψ the angle between them, and ψ = 0 is the parallel case of section six. Along the generator B = (R cos t, R sin t, 0), D = z of the first,
A = sin2ψ, β = −R sin t sin ψ cos ψ, γ = (R cos t − d)2 + R2sin2t cos2ψ − r2
Δ = sin2ψ (r2 − (R cos t − d)2), s± = (R sin t cos ψ ± √(r2 − (R cos t − d)2))/sin ψ
A generator meets the second cylinder when |R cos t − d| ≤ r, that is for cos t between (d − r)/R and (d + r)/R, and the angle ψ plays no part in which generators meet it. Walk the wider cylinder, R ≥ r. The node and the tangent point are both at t = 0, the point (R, 0, 0).
| Case | Condition | Intersection |
|---|---|---|
| two loops | d < R − r − ε | one per arc, t between acos((d + r)/R) and acos((d − r)/R), and its mirror in t = 0 |
| crossing loop | d within ε of R − r | one loop through the node (R, 0, 0) |
| one loop | R − r + ε < d < R + r − ε | |t| ≤ acos((d − r)/R) |
| tangent point | d within ε of R + r | (R, 0, 0) |
| empty | d > R + r + ε | none |
| two ellipses | d ≤ ε and |R − r| ≤ ε | a split case: see below |
A sphere and a cylinder off its axis
Take the cylinder of radius r about the z axis and the sphere of radius R centred at (e, 0, c), with e > 0 its distance from the axis; e = 0 is the coaxial card of section six. Along a vertical generator A = 1 and β = −c, and
Δ = R2 − r2 − e2 + 2re cos t = 2re(cos t − c0), c0 = (r2 + e2 − R2)/2re
X = (r cos t, r sin t, c ± √Δ)
so the generators that meet the sphere are those with cos t ≥ c0, and c0 sorts the cases. The best-known member is Viviani’s curve, R = 2r and e = r: the cylinder passes through the sphere’s centre and touches it from inside, and the loop crosses itself at the point of contact.
| Case | Condition | Intersection |
|---|---|---|
| two loops | R > r + e + ε | z = c ± √Δ all round |
| crossing loop | R within ε of r + e | one loop through the node (−r, 0, c) |
| one loop | |r − e| + ε < R < r + e − ε | |t| ≤ acos c0 |
| tangent point | R within ε of |r − e| | (r, 0, c), from inside the cylinder if e < r |
| empty | R < |r − e| − ε | none |
A sphere and a cone off its axis
Take the cone with its apex at the origin about the z axis, half-angle α, and the sphere of radius R centred at C = (e, 0, h). A point sD(t) of a generator is on the sphere when s2 − 2ms + k = 0, with
m(t) = C·D = h cos α + e sin α cos t, k = |C|2 − R2, s = m ± √(m2 − k)
Here k is the power of the apex with respect to the sphere, and √(|C|2 − m2) is the distance from the centre to the generator, so a generator meets the sphere when that distance is at most R. The sign of k splits the cases first. With the apex inside the sphere, k < 0, the roots have opposite signs for every t, and there is one loop on each nappe. With the apex on the sphere, k = 0, the roots are 0 and 2m: the apex itself, and one loop s = 2m(t), which passes through the apex only where m changes sign. With the apex outside, k > 0, both roots have the sign of m, so a generator meets the sphere only on the nappe m points to, and only where |m| ≥ √k. For the upper nappe, with m between mmin = h cos α − e sin α at t = π and mmax = h cos α + e sin α at t = 0, the cases are in the table; the lower nappe is the same with −m.
| Case | Condition | Intersection |
|---|---|---|
| two loops | k < 0: the apex inside | one loop on each nappe |
| loop and apex | k = 0: the apex on the sphere | s = 2m(t), and the apex |
| two loops | k > 0, mmin > √k | s+ and s− all round |
| crossing loop | mmin = √k | one loop through the node at t = π |
| one loop | mmin < √k < mmax | cos t ≥ (√k − h cos α)/(e sin α) |
| tangent point | mmax = √k | mmaxD(0) |
| empty | mmax < √k on both nappes | none |
| two tangent points | h = 0, R = e cos α | e sin α D(0) and −e sin α D(π), one on each nappe |
The equalities are bands of width ε on the distance from the centre to the generator at t = 0 and t = π, against R. In the last row the sphere sits level with the apex, and the distance from its centre to the generators at t = 0 and t = π is e cos α on both nappes.
A cone and a cylinder
Here the cylinder is the one to walk. Let the cylinder have axis a1 and radius r, and the cone apex O, axis a2 and half-angle φ, with cos ψ = a1·a2. In the plane through O square to a1, let W(t) run from the apex to the foot of generator t, round a circle of radius r centred where the cylinder’s axis crosses that plane. A generator is O + W + sa1, and since W is square to a1,
A = cos2ψ − cos2φ, β = cos ψ (W·a2), γ = (W·a2)2 − cos2φ |W|2
Δ = cos2φ [(W·a2)2 + A |W|2]
When the cylinder is steeper than the cone, ψ < φ and A > 0, Δ is positive for every generator, and the curve is two loops round the cylinder, one on each nappe. When it is shallower, A < 0, and Δ ≥ 0 says that W lies within an angle λ of the direction of a2 projected into the plane, on either side, with
sin λ = sin φ/sin ψ
That double wedge is the shadow of the cone along a1, and the generators that meet the cone are the arcs of the cylinder’s circle inside it. So the cases are read in the plane, from a circle against two pairs of rays. The arc ends are where the circle crosses the rays, a quadratic, and the node and the tangent point are where it touches one, decided on the distance from the circle’s centre to the ray against r.
| Case | Condition | Intersection |
|---|---|---|
| two loops | A > 0: the cylinder steeper than the cone | one loop round the cylinder on each nappe |
| two loops | the circle inside one half of the shadow | the cylinder passes through both walls of a nappe |
| two loops | the circle crossing both edges of one half | a nappe passes through the cylinder |
| two loops | the circle round the apex | one arc in each half, one loop on each nappe |
| one loop | the circle crossing one edge | the arc inside the shadow |
| crossing loop | the circle touching an edge from inside | a loop through the node |
| tangent point | the circle touching an edge from outside | one point |
| empty | the circle outside the shadow | none |
Between the two, A = 0: the cylinder is parallel to a generator of the cone, the quadratic drops to a linear equation, and the curve runs off to infinity along that direction. It is left to marching here.
Two cones
Walk the first cone, with apex O1, axis a1 and half-angle φ1, along d(t) = cos φ1 a1 + sin φ1(cos t e1 + sin t e2), against the second with apex O2, axis a2 and half-angle φ2. With w = O1 − O2,
A = (d·a2)2 − cos2φ2, β = d·m, γ = (w·a2)2 − cos2φ2 |w|2, m = (w·a2)a2 − cos2φ2 w
and Δ = dTMd with M = mmT − γ(a2a2T − cos2φ2 I). Since Mw = 0, Δ only sees the part of d across w. The sign of γ says where the first apex is. With γ > 0 it is inside the second cone, every generator of the first meets the second twice, and when A keeps one sign the curve is two loops round the first cone. With γ < 0 it is outside, and Δ factors as
Δ = (n0·d)(n1·d)
with n0 and n1 the normals of the two planes through both apexes that touch the second cone. A generator meets the second cone when it lies between those planes, and the arc ends, n·d(t) = 0, are of the form C cos t + D sin t + e = 0 from section five, solved by one arccosine each.
Two cones also bring the case A = 0, where a generator of the first is parallel to one of the second. One root runs to infinity there and comes back from infinity of the other sign, on the other nappe, so the pieces of the curve between the zeros of A are unbounded branches. Each branch is still exact. Parametrise it by a u that maps the open t-interval between two zeros onto the whole line, such as t = tm + (2h/π) atan u for an interval of half-width h about tm, and near a zero of A compute the root that stays finite as γ/q, which the cancellation-free formula above already does.
| Case | Condition | Intersection |
|---|---|---|
| two loops | γ > 0, A of one sign | s+ and s− all round |
| loops | γ < 0, A of one sign | one loop per arc between the tangent planes, up to two |
| branches | A changes sign | the loops, and unbounded branches between the zeros of A |
| empty | no generator between the tangent planes | none |
When the quartic splits
Some positions off the coaxial ones of section six still break the quartic into conics or lines, and a kernel should recognise them before walking, because the pieces are exact conics with their own closed forms.
Quadrics round one sphere. Two quadrics that touch the same sphere meet in two conics. Take the sphere of radius ρ at C, W = X − C and S = |W|2 − ρ2. A cylinder of radius ρ through C along a is S − (W·a)2 = 0, and a cone that touches the sphere, with half-angle φ and its apex at C − (ρ/sin φ)a, is cos2φ S − (W·a + ρ sin φ)2 = 0. Divide the cone’s equation by cos2φ and subtract the two equations: S cancels, and a difference of two squares is left, two planes.
cylinder–cylinder W·a1 = ±W·a2
cone–cylinder cos φ (W·a1) = ±(W·a2 + ρ sin φ)
cone–cone (W·a1 + ρ sin φ1)/cos φ1 = ±(W·a2 + ρ sin φ2)/cos φ2
On either plane the two quadrics agree, so each plane cuts one conic from both, by the plane–cylinder or plane–cone card of section six. The two conics cross where both quadrics touch the sphere: each touches it along a circle, the cylinder in the plane W·a = 0 and the cone in W·a = −ρ sin φ, and the circles meet in up to two contact points. The test is on the axes: two cylinders of equal radius whose axes meet, a cylinder of radius ρ and a cone whose axis meets the cylinder’s at distance ρ/sin φ from the apex, or two cones whose axes meet at distances ρ/sin φ1 and ρ/sin φ2 from their apexes. The first is the pipe tee, and the second a reducer.
Two cones with one apex. Every point of both cones lies on a line through the shared apex, so the intersection is lines. A unit direction d lies on both when d·a1 = c1 = ±cos φ1 and d·a2 = c2 = ±cos φ2. With g = a1·a2, write d = xa1 + ya2 + z(a1 × a2):
x = (c1 − gc2)/(1 − g2), y = (c2 − gc1)/(1 − g2), z2 = (1 − g2 − c12 − c22 + 2gc1c2)/(1 − g2)2
Fixing the sign of c1, since −d is the same line, leaves two signs of c2 and two of z, so up to four lines. Where z2 is within the tolerance of 0 the two lines of a pair merge into one tangent line, along which the cones touch. In angles, with ω the angle between the axes, the pair c2 = +cos φ2 gives lines when |φ1 − φ2| ≤ ω ≤ φ1 + φ2, and the other pair when the same holds for π − ω. The apex belongs to every answer, and coaxial cones with one apex are the apex alone, as in section six.
Parallel cones of one angle. Two cones with parallel axes a and the same half-angle φ have equations that differ by a polynomial of degree one, so they meet in a plane. With v = O2 − O1 and W = X − O1, subtracting the two equations gives
2W·[(v·a)a − cos2φ v] = (v·a)2 − cos2φ |v|2
a plane through the midpoint of the two apexes, and the curve is its section of either cone. With the second apex inside the first cone the section is an ellipse, outside it a hyperbola with one branch on each nappe, and on it the line through both apexes, along which the cones touch. A parabola does not occur: the plane is parallel to a generator only when the second apex lies on the first cone, and then the section is that line.
What stays numeric
A few positions of two quadrics are left to the marching of section ten. A cone and a cylinder parallel to one of its generators run to infinity along a single direction. Two cones need marching when an apex lies on the other cone, where γ = 0 and every generator through the apex is a root; when they touch along a curve; when A has a double zero, so that a branch goes to infinity and comes straight back; and when β vanishes together with A, so that both roots run off at once. Each is a meeting of two of the conditions above, and each can be recognised by the same tests on distances before the walk starts.
Two free-form curves
Two B-spline curves meet where A(s) = B(t). In a plane these are two equations in two unknowns, and Newton’s method on them converges quadratically from a nearby start. The problem, as in part six, is the start: the curves can meet many times, and a starting grid fine enough to see every crossing has to be finer than the closest pair of crossings, which is unknown.
The convex hull property removes the guesswork. Cut both curves into Bézier pieces. A piece lies inside the box of its control points, so two pieces whose boxes do not overlap cannot meet. That gives a subdivision algorithm:
- Start with every pair of pieces, one from each curve.
- Take a pair. If its boxes are disjoint, drop it.
- If both boxes are small enough, keep the pair as a candidate.
- Otherwise halve the larger piece with de Casteljau’s algorithm, and put the two new pairs back.
- From each candidate, run Newton on A(s) − B(t) = 0 from the middle of its two parameter intervals, and keep the converged points that are new.
Near a crossing at a good angle the boxes separate quickly, and the number of pairs grows only with the number of crossings. Near a tangency they do not separate at all, because the two curves stay within each other’s boxes over a stretch whose length grows as the square root of the box size. So the subdivision needs a depth limit, and a pair that reaches it is a tangency candidate: there, minimise the distance between the curves instead of solving for zero, and report a tangent point if the minimum is within tolerance. The same applies to two curves that overlap over an interval, where every subdivided pair survives; checking a few points along the candidate interval tells overlap from tangency.
In three dimensions two curves generically do not meet at all, and A(s) = B(t) is three equations in two unknowns. The problem is then the minimum of |A(s) − B(t)|2, a projection problem in two parameters, solved by the bounded Newton iteration and the box bounds of part six. A minimum within tolerance is an intersection, and the formulation has a useful side effect: the same search returns the closest approach of two curves that miss, which a tolerance check on an edge needs anyway.
A curve and a free-form surface
A curve meets a surface where C(t) = S(u, v): three equations in three unknowns. Newton’s step δ = (δt, δu, δv) solves
[ C′ −Su −Sv ] δ = −(C(t) − S(u, v))
a 3 by 3 system whose matrix has the three derivative vectors as columns. Its determinant is C′·(Su × Sv), the component of the curve’s tangent along the surface normal. It vanishes exactly when the curve is tangent to the surface, so the equation degenerates in the same place as the closed forms, for the same reason.
Seeds come from the same box test as before, between the Bézier pieces of the curve and the Bézier patches of the surface, subdividing the larger of the two until both are small. Where the determinant is small near the converged point, the contact is a tangency candidate, and the routine switches to minimising |C − S|2 over (t, u, v). This is less precise than it sounds. The distance near a tangent contact grows with the square of the distance along the curve, so a whole stretch of curve lies within tolerance of the surface, and the contact point can only be located to about the square root of the tolerance. Solving the tangent line on the 3 by 1 torus this way finds the two contacts only to a few times 10−7 in t; the closed form of section five gives 3 and 9 exactly. That is a reason to prefer the closed form whenever one exists, not a defect of the numerical method.
Two surfaces: marching
Two surfaces meet along curves, and the curve is the solution set of three equations in four unknowns:
S1(u1, v1) − S2(u2, v2) = 0
One unknown too many is what makes the solution a curve rather than points. Marching traces it: start from a point on it, step along its tangent, pull the step back onto both surfaces, and repeat. Let’s take a cylinder of radius 1 and a sphere of radius 1.78 centred 0.8 off its axis, which meet in one closed curve that turns tightly where the sphere comes within 0.02 of the cylinder.
Each step has four parts.
The tangent. The curve lies in both surfaces, so its tangent is perpendicular to both normals:
T = (N1 × N2) / |N1 × N2|
Its sign is arbitrary, so we keep T·Tprev > 0 from one step to the next. To move in parameters as well as in space, we need the parameter direction (ai, bi) on each surface with aiSu + biSv = T. T lies in the tangent plane, so this has an exact solution, from the 2 by 2 system of the first fundamental form of part five:
[ Su·Su Su·Sv ; Su·Sv Sv·Sv ] (a, b) = (T·Su, T·Sv)
The step length. A chord of length h on a curve of curvature κ deviates from the curve by about κh2/8 at its middle. To keep that deviation within a chosen ε, take
h = √(8ε / κ), clamped to [hmin, hmax]
The curvature of the intersection curve comes from the surfaces. Each surface bends the curve by its normal curvature in the direction T, κi = ai2Suu·Ni + 2aibiSuv·Ni + bi2Svv·Ni. The curve’s curvature vector k is perpendicular to T, so it lies in the plane of the two normals, and its components along them are those two normal curvatures. Writing k = λN1 + μN2 and c = N1·N2:
λ = (κ1 − c κ2) / (1 − c2), μ = (κ2 − c κ1) / (1 − c2), κ = |k|
The 1 − c2 in the denominators is sin2 of the angle between the surfaces: where they meet at a shallow angle, the curve bends sharply and the steps shorten, which is what the figure shows at its two turns. The curvature can also grow along a step, so after each step we compute it again at the new point and retake the step if the new value asks for one clearly shorter. Six of the 68 steps in the figure were retaken this way.
The predictor and the corrector. The predicted parameters are (ui, vi) + h(ai, bi) on each surface. They are off the curve by about the deviation ε, and the corrector brings them back. It needs a fourth equation to pin down where along the curve the new point lands, and the natural one is the plane at distance h along T from the current point Pk:
S1 − S2 = 0, (S1 − Pk)·T − h = 0
Newton on these four equations in (u1, v1, u2, v2) has the Jacobian with rows [S1u, S1v, −S2u, −S2v] for the three coordinates, and [T·S1u, T·S1v, 0, 0] for the plane. In the figure it converges to 10−13 in three iterations on most steps and five at the tight turns. If it does not converge within a handful of iterations, halve h and try again.
A simpler corrector is tempting: project the predicted point onto the first surface, then onto the second, and repeat until it stops moving. Each projection is a call to the routine of part six, so it needs no new code. But it converges linearly, at a rate set by the angle θ between the surfaces. Near the intersection each pair of projections multiplies the error by about cos2θ:
| Angle between the surfaces | 60° | 30° | 10° | 5° | 1° |
|---|---|---|---|---|---|
| Passes of alternating projection to 10−7 | 12 | 53 | 459 | 1,748 | 38,451 |
| Newton steps | 1 | 1 | 1 | 1 | 1 |
The table is for two planes, where Newton is exact in one step; on curved surfaces it takes a few, quadratically. Shallow angles are exactly where marching is hardest, and where the alternating corrector fails.
Stopping. A march ends in one of three ways, and the routine has to tell them apart:
- It closes. The starting point lies within the next step and ahead of the current point. The curve is a loop.
- It leaves a parameter rectangle. The step crosses the boundary of either surface’s domain. Clip it exactly: intersect the boundary curve of that surface with the other surface, using section nine, and end the branch there. The branch is open, and the other end will be found the same way when marching from the starting point in the opposite direction.
- The normals become parallel. |N1 × N2| falls below the angular tolerance, so T is undefined: the surfaces are tangent there, or the curve crosses itself. Stop and hand the point to whatever handles tangent contact, which is beyond this article.
The output of a march is a sequence of points with four parameters each. That is three curves at once: the points in space, and their (u, v) images on each surface, which become the pcurves of the new edges. Each is fitted with a B-spline, after unwrapping any periodic parameter against its neighbour as part six described, and the fitted curves are checked against the surfaces between the marched points.
Finding every branch
Marching traces a branch once it has a point on it. The difficult part of surface–surface intersection is producing at least one starting point on every branch, and no more than necessary.
Open branches are the easy kind. A branch that is not a closed loop must leave the domain of one of the surfaces, so it crosses the boundary of a parameter rectangle. Intersecting each of the four boundary curves of each surface with the other surface, using section nine, finds a point on every open branch, and in fact both ends of each. March from each such point, and drop the ones that a previous march already reached.
Closed loops touch no boundary, so no boundary point finds them, and a grid of samples finds them only if a sample happens to fall close enough. Let’s take a surface over the unit square cut by a horizontal plane, with a narrow bump inside the domain.
The point marked in the figure is not a coincidence. Inside a closed loop of the section, the height of the surface above the plane is zero on the loop and has one sign within it, so it has a maximum or a minimum inside, and there its gradient vanishes: the surface is level, and its normal is parallel to the plane’s. The statement for two surfaces is the same with both normals: when a closed loop bounds a region on each of two smooth patches, there is a line normal to both surfaces, meeting them at a point of each, with both normals parallel to the segment between those points. Those pairs of points are the stationary points of the distance between the two surfaces, the solutions of
(S1 − S2)·S1u = (S1 − S2)·S1v = (S1 − S2)·S2u = (S1 − S2)·S2v = 0
four equations in four unknowns, which is part six’s projection condition with a surface in place of the point. So a kernel can find every loop in two steps: find all the stationary points of the distance between the two surfaces, and from each one, walk along either surface until the signed distance to the other changes sign, which gives a curve–surface intersection and a starting point on the loop. Points that land on a branch already traced are dropped.
Finding the stationary points is itself a search that must not miss anything, and in the figure it is a real one: Newton started from a 9 by 9 grid never reaches the top of the narrow bump, and a 30 by 30 grid is needed. The robust way is the bounds and subdivision of part six, applied to pairs of patches. The cheaper alternative avoids solving for the stationary points at all. If the normals of one patch all lie in a cone of directions and the normals of the other lie in a cone that cannot contain a direction parallel to any of them, then no pair of parallel normals exists, and no closed loop can lie inside that pair of patches. So subdivide pairs of overlapping patches until each pair either passes that normal-cone test, in which case its boundary points find all of its branches, or is too small to matter.
Implementation checklist
If we implement intersection from scratch, these are the decisions in the order the problems arrive.
Return a classification, not only geometry. Transversal, tangent, coincident or empty, with parameters on both pieces for every point, and both pcurves for every curve.
Use the closed forms where they exist: substitution for lines and conics against the elementary surfaces, and the special positions of two surfaces, including the coaxial pairs, which reduce to their meridians. Recognise the position before computing.
Decide tangency on a distance. Evaluate the distance at the closest approach (the vertex of a quadratic, the critical points of a quartic) and compare that with the tolerance. Never compare root separations with it.
Centre the parameter and solve quadratics without cancellation.
Add the candidates a substitution cannot reach, such as t = π for tan(t/2), and verify every candidate by measuring its distance to the other surface, with a tolerance no finer than the rounding of its coordinates.
Test coincidence by the degree bound: five points of a conic on a quadric means the whole conic is on it.
Recognise the quadric pairs that split before walking: two quadrics touching one sphere meet in two conics, two cones with one apex in lines, two parallel cones of one angle in one conic.
Walk the generators of the ruled quadric for any other pair: one quadratic per generator, the shape decided by the sign of its discriminant over the circle of generators, the arc ends in closed form, nodes and tangent points snapped onto their exact configuration, and every fitted span checked against the curve, not against the surfaces.
For free-form curves and curve–surface pairs, subdivide by boxes before iterating, and switch to minimising the distance where the Jacobian becomes singular.
March with a Newton corrector on four equations, the step length from the curvature of the intersection curve, rechecked at the end of the step, and a consistent orientation of the tangent.
Stop for three reasons and tell them apart: closure, the boundary (clipped exactly), parallel normals.
Seed every branch: boundary curves against the other surface for open branches, stationary points of the distance or a normal-cone test for closed loops.
What this article leaves out
Tangential and singular intersections. Where two surfaces touch along a curve (a cylinder lying on a plane, a fillet meeting its support faces) or where the intersection curve crosses itself, the normals are parallel and marching has no direction. Kernels treat these with dedicated methods, and they are among the hardest cases in the field.
Algebraic methods. Resultants eliminate variables between implicit equations to give a single polynomial whose roots are the intersection, and the pencil method of Levin parametrises the intersection of any two quadrics through a ruled quadric in the pencil they span. Section seven is the case where one of the two is already ruled; for two spheres, two ellipsoids or any pair with no ruled member, the pencil finds one, and Dupont, Lazard, Lazard and Petitjean made the method exact, with the fewest square roots. Resultants and the general pencil method are beyond the scope of this series.
Self-intersections. A curve or a surface that meets itself, as an offset does once its distance exceeds the radius of curvature. The same tools apply, with the difficulty that every point trivially meets itself.
Making the result consistent. An intersection curve computed for one pair of faces must end exactly where the curves of the neighbouring pairs end, at the same vertices, or the Boolean’s result does not close. Organising the intersections into a consistent set of new edges and vertices is the subject of part eleven.
Reading list
Sources
N. M. Patrikalakis and T. Maekawa, Shape Interrogation for Computer Aided Design and Manufacturing, Springer, 2002, chapter 5, “Intersection problems”. Not consulted directly. The standard survey of the field, covering the classification of intersection problems, subdivision, marching and loop detection.
T. W. Sederberg and T. Nishita, “Curve intersection using Bézier clipping”, Computer-Aided Design 22 (1990), 538–549. Not consulted directly. A sharper version of the box subdivision of section eight, which clips each curve to the strip that can contain the other instead of halving it.
J. Levin, “A parametric algorithm for drawing pictures of solid objects composed of quadric surfaces”, Communications of the ACM 19 (1976), 555–563. Not consulted directly. The pencil method: a ruled quadric in the pencil of the two, walked along its generators as in section seven.
L. Dupont, D. Lazard, S. Lazard and S. Petitjean, “Near-optimal parameterization of the intersection of quadrics”, Journal of Symbolic Computation 43 (2008). Not consulted directly. Three papers that make the pencil method exact for any two quadrics, with a parametrisation in the fewest square roots and every singular and split case classified.
R. E. Barnhill and S. N. Kersey, “A marching method for parametric surface/surface intersection”, Computer Aided Geometric Design 7 (1990), 257–280. Not consulted directly. Marching in the four parameters of the two surfaces, as in section ten.
T. W. Sederberg, H. N. Christiansen and S. Katz, “Improved test for closed loops in surface intersections”, Computer-Aided Design 21 (1989), 505–508. Not consulted directly. The normal-cone criterion of section eleven for ruling out closed loops between two patches.
Method
The figures are drawn by a program that computes what they show: the root separations of the tangency figure from their formula, the hits of sections four and five and the sections of section six from the closed forms above, with the plane sections of the cone from the generators through the apex, the boxes by running the subdivision of section eight, the marching round the cylinder and sphere with the predictor, corrector and step rule of section ten, the zigzags by running the alternating corrector, and the loop by tracing from the boundary points and from the critical points of the height. The quartics of section seven are drawn by walking the generators with the formulas of their cards, the arc ends and the thresholds of every panel computed from the closed forms. Each hit and each point of a section or a quartic drawn in sections four to seven lies on both of its objects to 10−9. Each march point lies on both surfaces to 10−12, and the midpoint of every chord stays within 1.6ε of the curve.
Every case panel of sections four to seven, 160 panels in thirty-six figures, was rebuilt in a second implementation of the closed forms, written separately from the figure program. Each returned the case its panel is titled with, the same number of points or curves and the same multiplicities, and every point drawn lies on its result to 10−9, or 10−7 for the conics in crossing planes and the quartics of section seven. The tangency band, the two-sphere circle, the Villarceau circles, the conic coincidence, the line–torus quartic and the five crossings of the subdivision figure were checked the same way.
The marching of section ten was also run in the second implementation, seeded from the grid samples where the distance to the other surface is a local minimum, corrected by Newton in the plane normal to the tangent, with the step set from the curvature. On the cylinder and sphere of the marching figure it returns one closed curve, the figure’s marched points lie within 1.1 × 10−7 of it, and its cubic B-spline through the marched points stays within 2.8 × 10−5 of both surfaces between them. Corrected by alternating projection instead, and seeded only from samples already on the other surface, the same march misses both this curve and a plane at height 0.3 across a unit sphere. The alternating-projection table was measured on two planes with the figure program.
. New section seven: two quadrics in general position, with a card per pair and the cases that split into conics or lines. A card for conics in crossing planes.
. Part numbers renumbered for the new part two, The Mathematics a Kernel Stands On.