Line Cylinder Intersection

11.1k Views Asked by At

I am looking for an efficient way of finding the intersection of a line with a cylinder. Several answers are suggested on this site and other places, however I found this answer the most efficient one. The only challenge I am facing is that the given question and its answer only apply to a case where the line originates from the cylinder axis. Is there any similar approach that can be generalized to lines starting and ending at any arbitrary position?

To be specific, I am looking for finding intersection of any arbitrary line with a cylinder where the cylinder axis is assumed to lie on one the axes (say Z-axis). The given cylinder doesn't have caps and therefore, the line may or may not intersect with the cylinder. If it does intersect, it may have one or two intersection(s) of course.

3

There are 3 best solutions below

1
On BEST ANSWER

If your cylinder is set along an an axis, one way you could think of this is the following:

You "watch" your cylinder with your vision axis colinear with the cylinder axis, you can transform your parameterized line in the same referential as the cylinder then solve for a simple circle-line intersection in 2D.

enter image description here

I'd recommend working with a paremeterized line too, then finding:

  • 0 intersection, you're done.
  • 1 intersection, keep the parameter $t$ you solved for and compute the value in the referential you wish for ( given your line parameterized equation )
  • 2 intersections, keep the 2 parameters $t1$, $t2$ you solved for and compute the values in the referential you wish for for ( given your line parameterized equation )
  • $\infty$ intersections ( the line is contained within the 2d circle ) for that you can check for 2 points really far appart on the line and check if they are both inside the circle.

You are not forced to solve quadratics in order to find this intersection, but you can't avoid some trigonometry, here is an example:

enter image description here

enter image description here

1
On

The best way is to parametrize your line and plug into the equation of the cylinder.

For example if you have a line starting at $P(1,2,3)$ and the direction vector is $ V=<2,3,5>$.

Then the parametrization is $$x=1+2t, y=2+3t,z=3+5t$$

Now suppose your cylinder is $$ x^2 + y^2 =25$$

Plugging your $ x,y,z $of your line line in the equation of the cylinder implies $$ (1+2t)^2 + (2+3t)^2 =25$$ Solve for t and if you have any answer you have our points of intersection by plugging the values for t in the parametric equations of your line.

0
On

Let $A$, $B$ be two points on your line, and $A'$, $B'$ their projections onto the $xy$-plane (I'm assuming the $z$-axis is the axis of the cylinder). You can compute first of all the distance $d$ from $O=(0,0,0)$ to line $A'B'$: $$ d^2=(A'\cdot A')-t^2(A'-B')\cdot(A'-B'), $$ where: $$ t={A'\cdot (A'-B')\over(A'-B')\cdot(A'-B')}. $$ If $d>R$ (the radius of the cylinder) then line $AB$ doesn't intersect the cylinder, and you're done. Otherwise, define $$ k=\sqrt{R^2-d^2\over(A'-B')\cdot(A'-B')} $$ and the intersection points between line $AB$ and the cylinder are given by: $$ A+(t\pm k)(B-A). $$ Notice that those points lie between $A$ and $B$ if $0\le (t\pm k)\le1$.