fbpx
Wikipedia

Line-cylinder intersection

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.

Four cases for an intersection of a line and a cylinder. Intersections with the gray cylinder are highlighted in red. Global axes are back. The magenta line has zero intersections with the cylinder. Cyan line has a single point of intersection. Green line has two intersections. Yellow line lies tangent to the cylinder, so has infinitely many points of intersection.

An arbitrary line and cylinder may have no intersection at all. Or there may be one or two points of intersection.[1] 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.[2][3][4] This method is closely related to Line–sphere intersection.

Cylinder equation, end caps excluded edit

Let   be the cylinder base (or one endpoint),   be the cylinder axis unit vector, cylinder radius  , and height (or axis length)  . The cylinder may be in any orientation.

The equation for an infinite cylinder can be written as

 

where   is any point on the cylinder surface. The equation simply states that points   are exactly at Euclidean distance   from the axis   starting from point  , where   is measured in units of  . Note that   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 on the left side:

 

Point   is at signed distance

 

from the base along the axis. Therefore, the two equations defining the cylinder, excluding the end caps, is

 
 

The line edit

Let   be a line through origin,   being the unit vector, and   the distance from origin.

If your line does not pass through origin but point  , i.e. your line is  , replace   with   everywhere; distance   is then the distance from  .

The intersection problem edit

The intersection between the line and the cylinder is

 
 

where the signed distance along the axis   is

 

Solution edit

Rearranging the first equation gives a quadratic equation for  . Solving that for   gives

 

where   if   is a unit vector. If

 

the line is parallel to the axis, and there is no intersection, or the intersection is a line. If

 

the line does not intersect the cylinder.

Solving   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   from the cylinder base   along the axis   to the intersection   is within zero and the length of the cylinder:

 

where   is still

 

End caps edit

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 edit

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   does not include the end caps. If   is the cylinder height including both hemispherical end caps, then  .

Check if the line   intersects either sphere: center   or   and radius  :

 

If

 

the line does not intersect the end cap sphere.

If there are solutions  , accept only those that hit the actual end cap hemisphere:

    or    

where, once again,

 

Planar end caps edit

Planar end caps are circular regions, radius  , in planes centered at   and  , with unit normal vectors   and  , respectively. The line   intersects the plane if and only if

 

Solving d is simple,

 

Note that if

 

the line is parallel to the end cap plane (and also perpendicular to the cylinder axis). Finally, if and only if

 

the intersection point   is within the actual end cap (the circular region in the plane).

Unit normal vector at an intersection point edit

One of the many applications for this algorithm is in ray tracing, where the cylinder unit normal vector   at the intersection   is needed for refracted and reflected rays and lighting.

The equations below use the signed distance   to the intersection point   from base   along the axis  , which is always

 

For the cylinder surface (excluding the end caps, but including the seam),  :

 

For a spherical end cap at the base,  :

 

for a spherical end cap at the other end,  :

 

For a planar end cap at the base,  :

 

for a planar end cap at the other end,  :

 

See also edit

References edit

  1. ^ Narrien, John (1846). "Chap. VI". Analytical Geometry with the Properties of Conic Sections. London: Longman, Brown, Green, and Longmans. p. 156. Retrieved December 12, 2023. ...Thus a straight line can cut a curve surface of the second order in only two points...
  2. ^ Shene, Ching-Kuang (1994). "Computing the intersection of a line and a cylinder (Chapter V.1)". In Heckbert, Paul (ed.). Graphics Gems IV. AP Professional, Boston. pp. 353–355. ISBN 9780123361561. Retrieved December 12, 2023.
  3. ^ Cychosz, Joseph M.; Waggenspack, Warren N. Jr. (1994). "Intersecting a Ray with a Cylinder (Chapter V.2)". In Heckbert, Paul (ed.). Graphics Gems IV. AP Professional, Boston. pp. 356–365. ISBN 9780123361561. Retrieved December 12, 2023.
  4. ^ Held, Martin (1997). "ERIT—A Collection of Efficient and Reliable Intersection Tests". Journal of Graphics Tools. 2 (4): 25–44. doi:10.1080/10867651.1997.10487482.

External links edit

  • Collections of intersection techniques for computational geometry:
    • Intersections (Ray Tracing Resources Page) by Eric Haines, 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:
    • line - cylinder intersection in Johannes Buchner's collection of 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)

line, cylinder, intersection, calculation, points, intersection, given, analytic, geometry, description, line, cylinder, space, four, cases, intersection, line, cylinder, intersections, with, gray, cylinder, highlighted, global, axes, back, magenta, line, zero. 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 Four cases for an intersection of a line and a cylinder Intersections with the gray cylinder are highlighted in red Global axes are back The magenta line has zero intersections with the cylinder Cyan line has a single point of intersection Green line has two intersections Yellow line lies tangent to the cylinder so has infinitely many points of intersection An arbitrary line and cylinder may have no intersection at all Or there may be one or two points of intersection 1 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 2 3 4 This method is closely related to Line sphere intersection Contents 1 Cylinder equation end caps excluded 2 The line 3 The intersection problem 4 Solution 5 End caps 5 1 Hemispherical end caps 5 2 Planar end caps 6 Unit normal vector at an intersection point 7 See also 8 References 9 External linksCylinder equation end caps excluded editLet b b x b y b z displaystyle bar b b x b y b z nbsp be the cylinder base or one endpoint a a x a y a z displaystyle hat a a x a y a z nbsp be the cylinder axis unit vector cylinder radius r displaystyle r nbsp and height or axis length h displaystyle h nbsp 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 nbsp where p x y z displaystyle bar p x y z nbsp is any point on the cylinder surface The equation simply states that points p displaystyle bar p nbsp are exactly at Euclidean distance r displaystyle r nbsp from the axis a displaystyle hat a nbsp starting from point b displaystyle bar b nbsp where r displaystyle r nbsp is measured in units of a displaystyle lVert hat a rVert nbsp Note that a 1 displaystyle lVert hat a rVert 1 nbsp if a displaystyle hat a nbsp 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 nbsp Point p displaystyle bar p nbsp is at signed distance t a p b displaystyle t hat a cdot bar p bar b nbsp from the base along the axis Therefore the two equations defining the cylinder excluding the end caps is a p b 2 r 2 displaystyle lVert hat a times bar p bar b rVert 2 r 2 nbsp 0 a p b h displaystyle 0 leq hat a cdot bar p bar b leq h nbsp The line editLet p n d displaystyle bar p hat n d nbsp be a line through origin n displaystyle hat n nbsp being the unit vector and d displaystyle d nbsp the distance from origin If your line does not pass through origin but point o displaystyle bar o nbsp i e your line is o n d displaystyle bar o hat n d nbsp replace b displaystyle bar b nbsp with b o displaystyle bar b bar o nbsp everywhere distance d displaystyle d nbsp is then the distance from o displaystyle bar o nbsp The intersection problem editThe intersection between the line and the cylinder is a n d b 2 r 2 displaystyle lVert hat a times hat n d bar b rVert 2 r 2 nbsp 0 t h displaystyle 0 leq t leq h nbsp where the signed distance along the axis t displaystyle t nbsp is t a n d b displaystyle t hat a cdot hat n d bar b nbsp Solution editRearranging the first equation gives a quadratic equation for d displaystyle d nbsp Solving that for d displaystyle d nbsp gives d n a b a n a n a r 2 a a b n a 2 n a n a displaystyle d frac hat n times hat a cdot bar b times hat a pm sqrt hat n times hat a cdot hat n times hat a r 2 hat a cdot hat a bar b cdot hat n times hat a 2 hat n times hat a cdot hat n times hat a nbsp where a a 1 displaystyle hat a cdot hat a 1 nbsp if a displaystyle hat a nbsp is a unit vector If n a 0 displaystyle lVert hat n times hat a rVert 0 nbsp the line is parallel to the axis and there is no intersection or the intersection is a line If n a n a r 2 a a b n a 2 lt 0 displaystyle hat n times hat a cdot hat n times hat a r 2 hat a cdot hat a bar b cdot hat n times hat a 2 lt 0 nbsp the line does not intersect the cylinder Solving d displaystyle d nbsp 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 displaystyle t nbsp from the cylinder base b displaystyle bar b nbsp along the axis a displaystyle hat a nbsp to the intersection p n d displaystyle bar p hat n d nbsp is within zero and the length of the cylinder 0 t h displaystyle 0 leq t leq h nbsp where t displaystyle t nbsp is still t a n d b displaystyle t hat a cdot hat n d bar b nbsp End caps editThe 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 edit 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 displaystyle h nbsp does not include the end caps If H displaystyle H nbsp is the cylinder height including both hemispherical end caps then h H 2 r displaystyle h H 2r nbsp Check if the line p n d displaystyle bar p hat n d nbsp intersects either sphere center c b displaystyle bar c bar b nbsp or c b a h displaystyle bar c bar b hat a h nbsp and radius r displaystyle r nbsp d n c n c 2 r 2 c c displaystyle d hat n cdot bar c pm sqrt hat n cdot bar c 2 r 2 bar c cdot bar c nbsp If n c 2 r 2 c c lt 0 displaystyle hat n cdot bar c 2 r 2 bar c cdot bar c lt 0 nbsp the line does not intersect the end cap sphere If there are solutions d displaystyle d nbsp accept only those that hit the actual end cap hemisphere r t lt 0 displaystyle r leq t lt 0 nbsp or h lt t h r displaystyle h lt t leq h r nbsp where once again t a n d b displaystyle t hat a cdot hat n d bar b nbsp Planar end caps edit Planar end caps are circular regions radius r displaystyle r nbsp in planes centered at c b displaystyle bar c bar b nbsp and c b a h displaystyle bar c bar b hat a h nbsp with unit normal vectors a displaystyle hat a nbsp and a displaystyle hat a nbsp respectively The line n d displaystyle hat n d nbsp intersects the plane if and only if n d c a 0 displaystyle hat n d bar c cdot hat a 0 nbsp Solving d is simple d a c a n displaystyle d frac hat a cdot bar c hat a cdot hat n nbsp Note that if a n 0 displaystyle hat a cdot hat n 0 nbsp the line is parallel to the end cap plane and also perpendicular to the cylinder axis Finally if and only if n d c n d c lt r 2 displaystyle hat n d bar c cdot hat n d bar c lt r 2 nbsp the intersection point n d displaystyle hat n d nbsp is within the actual end cap the circular region in the plane Unit normal vector at an intersection point editOne of the many applications for this algorithm is in ray tracing where the cylinder unit normal vector v displaystyle hat v nbsp at the intersection n d displaystyle hat n d nbsp is needed for refracted and reflected rays and lighting The equations below use the signed distance t displaystyle t nbsp to the intersection point n d displaystyle hat n d nbsp from base b displaystyle bar b nbsp along the axis a displaystyle hat a nbsp which is always t a n d b displaystyle t hat a cdot hat n d bar b nbsp For the cylinder surface excluding the end caps but including the seam 0 t h displaystyle 0 leq t leq h nbsp v n d a t b n d a t b displaystyle hat v frac hat n d hat a t bar b lVert hat n d hat a t bar b rVert nbsp For a spherical end cap at the base r t lt 0 displaystyle r leq t lt 0 nbsp v n d b r displaystyle hat v frac hat n d bar b r nbsp for a spherical end cap at the other end h lt t h r displaystyle h lt t leq h r nbsp v n d b a h r displaystyle hat v frac hat n d bar b hat a h r nbsp For a planar end cap at the base t 0 displaystyle t 0 nbsp v a displaystyle hat v hat a nbsp for a planar end cap at the other end t h displaystyle t h nbsp v a displaystyle hat v hat a nbsp See also editLine sphere intersection Line plane intersection Intersection geometry References edit Narrien John 1846 Chap VI Analytical Geometry with the Properties of Conic Sections London Longman Brown Green and Longmans p 156 Retrieved December 12 2023 Thus a straight line can cut a curve surface of the second order in only two points Shene Ching Kuang 1994 Computing the intersection of a line and a cylinder Chapter V 1 In Heckbert Paul ed Graphics Gems IV AP Professional Boston pp 353 355 ISBN 9780123361561 Retrieved December 12 2023 Cychosz Joseph M Waggenspack Warren N Jr 1994 Intersecting a Ray with a Cylinder Chapter V 2 In Heckbert Paul ed Graphics Gems IV AP Professional Boston pp 356 365 ISBN 9780123361561 Retrieved December 12 2023 Held Martin 1997 ERIT A Collection of Efficient and Reliable Intersection Tests Journal of Graphics Tools 2 4 25 44 doi 10 1080 10867651 1997 10487482 External links editCollections of intersection techniques for computational geometry Intersections Ray Tracing Resources Page by Eric Haines 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 line cylinder intersection in Johannes Buchner s collection of 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 Retrieved from https en wikipedia org w index php title Line cylinder intersection amp oldid 1215906023, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.