I\'m trying to find the point of intersection between a sphere and a line but honestly, I don\'t have any idea of how to do so. Could anyone help me on this one ?
Here's a more concise formulation using inner products, less than 100 LOCs, and no external links. Also, the question was asked for a line, not a line segment.
Assume that the sphere is centered at C
with radius r
. The line is described by P+l*D
where D*D=1
. P
and C
are points, D
is a vector, l
is a number.
We set PC = P-C
, pd = PC*D
and s = pd*pd - PC*PC + r*r
. If s < 0
there are no solutions, if s == 0
there is just one, otherwise there are two. For the solutions we set l = -pd +- sqrt(s)
, then plug into P+l*D
.