quote:
Original post by s_cloudx
But then, the result would be a vector and t would have to be a vector, too. Oh, dear. 
If I make t a float, I would have to decide if I should put in t0''s x, y, or z value. But since you said t is the distance of how far an object is, I knew I made a mistake somewhere. I suspect that my Vector maths are wrong. Could someone please aid me here?
BTW, oliii, I really appreciate your help. Thank you!
You got it all wrong

t is a float and CANNOT be equal to a vector. A vector length maybe, or a vector component (either x, y or z), or a dot product of 2 vectors, or any vector operations that return a float.
a, b, c are floats too. They are NOT vectors. Look into the equations for ''c'' for example.
(RayPos - SpherePos)*(RayPos - SpherePos) is a dot product of two vector substractions. the substractions produce a vector, but the dot products of the two substractions will turn the result into a scalar. (SphereRad * SphereRad) is a product of scalars, which return a scalar. so a = scalar + scalar = scalar.
a, b, c are lowercase names. This usually means they are either a float or a int. Basically a scalar.
t is a float and is the parametric component for the line equation
P = RayPos + t * RayDir;
Raypos is a vector, Raydir is a vector, (t * raydir) is also a vector (t * RayDir = Vector(RayDir.x*t, Raydir.y*t, RayDir.z*t)).
I use equations in parametric form, which applies into any dimensions (2D, 3D, whatever), and you solve the set of equations for a parameter which is a scalar, with no units attached to it. It''s like a percentage, it''s just a number.
OK, to clear things up, I''ll note the vectors as vVectorName and floats as fFloatName.
Vector vRelPos = vRayPos - vSpherePos;float fC = (vRelPos * vRelPos) - (fSphereRad * fSphereRad);float fB = 2.0f * (vRayDir * vRelPos); float fA = (RayDir * RayDir); float fD = fB*fB - 4*fA*fC; float fT0 = (-fB - sqrt(fD)) / (2*fA);float fT1 = (-fB + sqrt(fD)) / (2*fA);if (fT1 < 0.0f && fT0 < 0.0f) return false;fT = MinimumButPositive(fT0, fT1);vPointOfIntersection = vRayPos + (vRayDir * fT);