Line-cylinder Intersection
   HOME

TheInfoList



OR:

Line-cylinder intersection is the calculation of any points of
intersection In mathematics, the intersection of two or more objects is another object consisting of everything that is contained in all of the objects simultaneously. For example, in Euclidean geometry, when two lines in a plane are not parallel, their ...
, given an
analytic geometry In mathematics, analytic geometry, also known as coordinate geometry or Cartesian geometry, is the study of geometry using a coordinate system. This contrasts with synthetic geometry. Analytic geometry is used in physics and engineering, and als ...
description of a line and a
cylinder A cylinder () has traditionally been a three-dimensional solid, one of the most basic of curvilinear geometric shapes. In elementary geometry, it is considered a prism with a circle as its base. A cylinder may also be defined as an infinite ...
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 A surface, as the term is most generally used, is the outermost or uppermost layer of a physical object or space. It is the portion or region of the object that can first be perceived by an observer using the senses of sight and touch, and is ...
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 ''Acer'' is a genus of trees and shrubs commonly known as maples. The genus is placed in the soapberry family Sapindaceae.Stevens, P. F. (2001 onwards). Angiosperm Phylogeny Website. Version 9, June 2008 nd more or less continuously updated si ...
. 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 In analytic geometry, a line and a sphere can intersect in three ways: # No intersection at all # Intersection in exactly one point # Intersection in two points. Methods for distinguishing these cases, and determining the coordinates for the p ...
.


Cylinder equation, end caps excluded

Let = ( b_x , b_y , b_z ) be the cylinder base (or one endpoint), = ( a_x , a_y , a_z ) be the cylinder axis unit vector, cylinder radius r, and height (or axis length) h. The cylinder may be in any orientation. The equation for an infinite cylinder can be written as :\lVert \times ( - ) \rVert = r where = (x , \ y , \ z ) is any point on the cylinder surface. The equation simply states that points are exactly at
Euclidean distance In mathematics, the Euclidean distance between two points in Euclidean space is the length of the line segment between them. It can be calculated from the Cartesian coordinates of the points using the Pythagorean theorem, and therefore is o ...
r from the axis starting from point , where r is measured in units of \lVert\rVert. Note that \lVert\rVert = 1 if 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 Euclidean space is the fundamental space of geometry, intended to represent physical space. Originally, in Euclid's ''Elements'', it was the three-dimensional space of Euclidean geometry, but in modern mathematics there are ''Euclidean spaces'' ...
on the left side: :^2 = r^2 Point is at signed distance :t = \cdot ( - ) from the base along the axis. Therefore, the two equations defining the cylinder, excluding the end caps, is :^2 = r^2 :0 \leq \cdot ( - ) \leq h


The line

Let = d be a line through origin, being the unit vector, and d the distance from origin. If your line does not pass through origin but point , i.e. your line is + d, replace with (-) everywhere; distance d is then the distance from .


The intersection problem

The intersection between the line and the cylinder is :^2 = r^2 :0 \leq t \leq h where the signed distance along the axis t is :t = \cdot ( d - )


Solution

Rearranging the first equation gives a
quadratic equation In mathematics, a quadratic equation () is an equation that can be rearranged in standard form as ax^2 + bx + c = 0\,, where the variable (mathematics), variable represents an unknown number, and , , and represent known numbers, where . (If and ...
for d. Solving that for d gives :d = \frac where (\cdot) = 1 if is a unit vector. If :\lVert \times \rVert = 0 the line is parallel to the axis, and there is no intersection, or the intersection is a line. If :(\times)\cdot(\times) r^2 - (\cdot)(\cdot(\times))^2 < 0 the line does not intersect the cylinder. Solving d only gives you the distance at which the line intersects the ''infinite'' cylinder. To see if the intersection occurs within the part we consider the actual cylinder, we need to check if the signed distance t from the cylinder base along the axis to the intersection = d is within zero and the length of the cylinder: :0 \le t \le h where t is still :t = \cdot ( d - )


End caps

The above assumes that the cylinder does not have end caps; they must be checked for separately. The seam where the end cap meets the cylinder is assumed to belong to the cylinder, and is excluded from the end cap.


Hemispherical end caps

Hemispherical end caps are just half-spheres at both ends of the cylinder. This object is sometimes called a capsule, or possibly fixed-radius linearly-swept sphere. Cylinder height h does not include the end caps. If H is the cylinder height including both hemispherical end caps, then h = H - 2 r. Check if the line = d intersects either sphere: center = or = + h and radius r: :d = \cdot \pm \sqrt If :(\cdot)^2 + r^2 - (\cdot) < 0 the line does not intersect the end cap sphere. If there are solutions d, accept only those that hit the actual end cap hemisphere: :-r \le t < 0   or   h < t \le h+r where, once again, :t = \cdot ( d - )


Planar end caps

Planar end caps are circular regions, radius r, in planes centered at = and = + h, with unit normal vectors - and , respectively. The line d intersects the plane if and only if :( d - ) \cdot = 0 Solving d is simple, :d = \frac Note that if : \cdot = 0 the line is parallel to the end cap plane (and also perpendicular to the cylinder axis). Finally, if and only if :( d - ) \cdot ( d - ) < r^2 the intersection point d is within the actual end cap (the circular region in the plane).


Unit normal vector at an intersection point

One of the many applications for this algorithm is in ray tracing, where the cylinder unit normal vector at the intersection d is needed for refracted and reflected rays and lighting. The equations below use the signed distance t to the intersection point d from base along the axis , which is always :t = \cdot ( d - ) For the cylinder surface (excluding the end caps, but including the seam), 0 \le t \le h: : = \frac For a spherical end cap at the base, -r \le t < 0: : = \frac for a spherical end cap at the other end, h < t \le h + r: : = \frac For a planar end cap at the base, t = 0: : = - for a planar end cap at the other end, t = h: : =


See also

*
Line–sphere intersection In analytic geometry, a line and a sphere can intersect in three ways: # No intersection at all # Intersection in exactly one point # Intersection in two points. Methods for distinguishing these cases, and determining the coordinates for the p ...
*
Line–plane intersection In analytic geometry, the intersection of a line and a plane in three-dimensional space can be the empty set, a point, or a line. It is the entire line if that line is embedded in the plane, and is the empty set if the line is parallel to the ...
*
Intersection (geometry) In geometry, an intersection is a point, line, or curve common to two or more objects (such as lines, curves, planes, and surfaces). The simplest case in Euclidean geometry is the line–line intersection between two distinct lines, which eith ...


References

{{reflist


External links

* Collections of intersection techniques for computational geometry: *
Intersections (Ray Tracing Resources Page)
by
Eric Haines Eric Haines is an American software engineer and expert in computer graphics, specifically image rendering. he is with NVIDIA Corporation as Distinguished Engineer. He is a co-author of the book ''Real-Time Rendering'', currently in its fourth ...
, table of links for many intersection calculations, including ray-cylinder. *
collection of ray-surface intersectors for GPU shaders
by Inigo Quilez, including ray-cylinder. * Derivations which require cylinder be in a constrained orientation: *

in Johannes Buchner's collection o
Line-Intersection formulae
*
Line - Cylinder intersection -
at IllusionCatalyst *
Line Cylinder Intersection
at Mathematics Stack Exchange (math.stackexchange.com) * Partial solution: *
Calculating ray-cylinder intersection points
at Mathematics Stack Exchange (math.stackexchange.com) Analytic geometry Geometric algorithms Geometric intersection