Is there an optimized equation for calculating if a sphere and line will intersect, i'm aware of the closest point solution but i was wondering if there was another. There's also the quadratic equation but it requires a lot of calculations, and i'm not sure of all the early outs that are possible with it. I know of two by (i think)...
Vec3 d = lineEnd - lineStart; // the ray
Vec3 f = lineStart - sphereCenter; // center -> lineStart
float c = dot(f, f) - radius * radius;
if(c <= 0)
{
// first out
// sphere is touching the vertex
// hit !
}
float b = dot(f, d);
if(b >= 0)
{
// second out
// line ray and center -> start, are going same direction
// if the start point didn't intersect above
// then there's no way for the segment or other point to
// miss
}
float a = dot(d, d);
// ... any other optimizations
if(b*b - a*c < 0)
{
// miss
}