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.
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.
I'd recommend working with a paremeterized line too, then finding:
You are not forced to solve quadratics in order to find this intersection, but you can't avoid some trigonometry, here is an example: