Line-cylinder intersection is the calculation of any points of intersection, given an analytic geometry description of a line and a cylinder in 3D space. An arbitrary line and cylinder may have no intersection at all. Or there may be one or two points of intersection. Or a line may lie along the surface of a cylinder, parallel to its axis, resulting in infinitely many points of intersection. The method described here distinguishes between these cases, and when intersections exist, computes their positions. The term "cylinder" can refer to a three-dimensional solid or, as in this article, only the curved external surface of the solid. This is why a line piercing a cylinder's volume is considered to have two points of intersection: the surface point where it enters and the one where it leaves. See § end caps. A key intuition of this sort of intersection problem is to represent each shape as an equation which is true for all points on the shape. Solving them as a system of two simultaneous equations finds the points which belong to both shapes, which is the intersection. The equations below were solved using Maple. This method has applications in computational geometry, graphics rendering, shape modeling, physics-based modeling, and related types of computational 3d simulations. This has led to various implementations. This method is closely related to Line–sphere intersection.
Cylinder equation, end caps excluded Let b ¯ = ( b x , b y , b z ) {\displaystyle {\bar {b}}=(b_{x},b_{y},b_{z})} be the cylinder base (or one endpoint),
a ^ = ( a x , a y , a z ) {\displaystyle {\hat {a}}=(a_{x},a_{y},a_{z})} be the cylinder axis unit vector, cylinder radius r {\displaystyle r} , and height (or axis length) h {\displaystyle h} . The cylinder may be in any orientation. The equation for an infinite cylinder can be written as
‖ a ^ × ( p ¯ − b ¯ ) ‖ = r {\displaystyle \lVert {\hat {a}}\times ({\bar {p}}-{\bar {b}})\rVert =r}
where p ¯ = ( x , y , z ) {\displaystyle {\bar {p}}=(x,\ y,\ z)} is any point on the cylinder surface. The equation simply states that points p ¯ {\displaystyle {\bar {p}}} are exactly at Euclidean distance r {\displaystyle r} from the axis a ^ {\displaystyle {\hat {a}}} starting from point b ¯ {\displaystyle {\bar {b}}} , where r {\displaystyle r} is measured in units of ‖ a ^ ‖ {\displaystyle \lVert {\hat {a}}\rVert } . Note that ‖ a ^ ‖ = 1 {\displaystyle \lVert {\hat {a}}\rVert =1} if a ^ {\displaystyle {\hat {a}}} is a unit vector. Because both sides of the equation are always positive or zero, we can square it, and eliminate the square root operation in the Euclidean norm on the left side:
‖ a ^ × ( p ¯ − b ¯ ) ‖ 2 = r 2 {\displaystyle {\lVert {\hat {a}}\times ({\bar {p}}-{\bar {b}})\rVert }^{2}=r^{2}}
Point p ¯ {\displaystyle {\bar {p}}} is at signed distance
t = a ^ ⋅ ( p ¯ − b ¯ ) {\displaystyle t={\hat {a}}\cdot ({\bar {p}}-{\bar {b}})}
from the base along the axis. Therefore, the two equations defining the cylinder, excluding the end caps, is
… excerpt ends here. Continue reading the full article.


