|
|
Nicolas Alvarez wrote:
>> Any clearer? ;-)
>
> Thanks; shows I'm still too noob for this kind of things.
>
>
>
> (that's a no)
OK, well because I'm feeling bored, let me try again...
Light travels in essentially straight lines. If we assume a ray starts
at position S and travels parallel to the vector D, we can write
R(t) = Dt + S
That is, the vector D scaled by the scalar t, plus the vector S.
A sphere is the set of all points within a specific distance of a
certain point. So if C is the center of our sphere, and r is the radius
of the sphere, then the sphere consists of all points less than r units
from the point C. We're interested in the *surface* of the sphere, which
is the set of all points *exactly* r units away from C. We can write that as
|P - C| = r
Solving this equation for any vector P gives us the surface coordinates.
But that's not what we're trying to do. We want to know whether any
point in space lines on the surface of the sphere *and* on a given ray.
In other words, solve simultaneous equations. Non-linear ones!
But we'll get to that in a second. First, notice that the dot product of
a vector with itself is equal to the length of that vector squared. In
oter words,
vlength(V) = sqrt(V # V)
That means we can write
sqrt((P - C) # (P - C)) = r
Alternatively, we can avoid the expensive square root operation by
(P - C) # (P - C) = r^2
Finally, with a tiny bit of rearranging, we have
((P - C) # (P - C)) - r^2 = 0
(If the thing on the left *equals* the thing on the right, then
subtracting one from the other must logically result in zero.)
I'm going to be fanciful and write the above in shorthand:
(P - C)^2 - r^2 = 0
It's a slight abuse of notation, but it's less typing.
Now if we replace our unknown point P with our ray equation R(t) we get
(Dt + S - C)^2 - r^2 = 0
If I put X = S - C, we get
(Dt + X)^2 - r^2 = 0
Opening the brackets as per the standard binomial theorum, we have
D^2 t^2 + 2 D X t + X^2 - r^2 = 0
By which of course I actually mean
(D # D) t^2 + 2 (D # X) t + (X # X) - r^2 = 0
This matches the form of the standard quadratic
a t^2 + b t + c = 0
if we set
a = D # D
b = 2 (D # X)
c = (X # X) - r^2
We can now apply the usual formula
t = (-b +/- sqrt(b^2 + 4ac)) / 2a
Assuming that the square root part (the "determinant") is strictly
positive, we obtain two purely-real solutions. These are the values for
t where the ray "enters" and "leaves" the sphere. If the determinant is
negative, that basically means the ray doesn't touch the sphere at all.
Assuming we *do* have an intersection, just calculate
Dt + S
for the two values of t to obtain the actual points of intersection.
Is *that* any clearer? ;-)
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|