I'm working on writing an algorithm for a the distance of a ray intersection with a cylinder (t), where the cylinder is of arbitrary rotation. Using this website as inspiration, I know I can find the intersection by solving the following for t:
Where the ray is described by: $x(t) = p_r + tr$ and the cylinder has $x_1$ and $x_2$ describing two points on its central axis and a radius r,
$$ \frac{|(x(t) - x_1)\times (x(t) - x_2)|^2}{|x_1 - x_2|^2} = r^2 $$
However, I'm having a bit of trouble figuring out how I can code solving for t into my algorithm, even after I've expanded everything. Can anyone help me figure out how to do this or suggest an alternative solution to the problem? Thanks so much!