Sphere–cylinder intersection

In the theory of analytic geometry for real three-dimensional space, the curve formed from the intersection between a sphere and a cylinder can be a circle, a point, the empty set, or a special type of curve.

For the analysis of this situation, assume (without loss of generality) that the axis of the cylinder coincides with the z-axis; points on the cylinder (with radius $$r$$) satisfy


 * $$x^2 + y^2 = r^2.$$

We also assume that the sphere, with radius $$R$$ is centered at a point on the positive x-axis, at point $$(a, 0, 0)$$. Its points satisfy


 * $$(x-a)^2 + y^2 + z^2 = R^2.$$

The intersection is the collection of points satisfying both equations.

Sphere lies entirely within cylinder
If $$a+R < r$$, the sphere lies entirely in the interior of the cylinder. The intersection is the empty set.

Sphere touches cylinder in one point
If the sphere is smaller than the cylinder ($$R < r$$) and $$a+R = r$$, the sphere lies in the interior of the cylinder except for one point. The intersection is the single point $$(r, 0, 0)$$.

Sphere centered on cylinder axis
If the center of the sphere lies on the axis of the cylinder, $$a = 0$$. In that case, the intersection consists of two circles of radius $$r$$. These circles lie in the planes
 * $$z = \pm\sqrt{R^2 - r^2};$$

If $$r = R$$, the intersection is a single circle in the plane $$z = 0$$.

Non-trivial cases
Subtracting the two equations given above gives


 * $$z^2 + (r^2 - R^2 + a^2) = 2ax.$$

Since $$x$$ is a quadratic function of $$z$$, the projection of the intersection onto the xz-plane is the section of an orthogonal parabola; it is only a section due to the fact that $$-r < x < r$$. The vertex of the parabola lies at point $$(-b, 0, 0)$$, where


 * $$b = \frac{R^2 - r^2 - a^2}{2a}.$$

Intersection consists of two closed curves
If $$R > r + a$$, the condition $$x < r$$ cuts the parabola into two segments. In this case, the intersection of sphere and cylinder consists of two closed curves, which are mirror images of each other. Their projection in the xy-plane are circles of radius $$r$$.

Each part of the intersection can be parametrized by an angle $$\phi$$:


 * $$(x,y,z) = \left(r\cos\phi,r\sin\phi,\pm\sqrt{2a(b + r\cos\phi)}\right).$$

The curves contain the following extreme points:


 * $$\left(-r, 0, \pm\sqrt{R^2 - (r+a)^2}\right);\quad

\left(0, \pm r, \pm\sqrt{R^2 - (r-a)(r+a)}\right);\quad \left(+r, 0, \pm\sqrt{R^2 - (r-a)^2}\right).$$

Intersection is a single closed curve
If $$R < r + a$$, the intersection of sphere and cylinder consists of a single closed curve. It can be described by the same parameter equation as in the previous section, but the angle $$\phi$$ must be restricted to $$-\phi_0 < \phi < +\phi_0$$, where $$\cos\phi_0 = -b/r$$.

The curve contains the following extreme points:
 * $$\left(-b, \pm\sqrt{r^2-b^2}, 0\right);\quad

\left(0, \pm r, \pm\sqrt{R^2 - (r-a)(r+a)}\right);\quad \left(+r, 0, \pm\sqrt{R^2 - (r-a)^2}\right).$$

Limiting case
In the case $$R = r + a$$, the cylinder and sphere are tangential to each other at point $$(r, 0, 0)$$. The intersection resembles a figure eight: it is a closed curve which intersects itself. The above parametrization becomes


 * $$(x,y,z) = \left(r\cos\phi,r\sin\phi,2\sqrt{ar}\cos\frac{\phi}{2}\right),$$

where $$\phi$$ now goes through two full revolutions.

In the special case $$a = r, R = 2r$$, the intersection is known as Viviani's curve. Its parameter representation is


 * $$(x,y,z) = \left(r\cos\phi,r\sin\phi,R\cos\frac\phi2\right).$$

The volume of the intersection of the two bodies, sometimes called Viviani's volume, is


 * $$V=2\int\int_{(x-a)^2+y^2\le r^2,x^2+y^2\le R^2} \sqrt{R^2-x^2-y^2}dxdy =\left(\frac{2\pi}{3}-\frac89\right)R^3.$$