|
|
Nicolas Alvarez wrote:
> As far as I know, the way POV-Ray does it (and probably most others) is
> by creating a transformation matrix of all the individual
> transformations, then inversing it, and using it to transform *rays*
> before doing the intersection calculations.
I believe that is correct. (Transforming the object equation would be
much harder...)
> But don't trust me on this. I still haven't managed to solve the
> ray-sphere intersection equation...
Suppose you have a sphere with center C [a vector] and radius r [a
scalar]. The equation for this is
(P - C)^2 - r^2 = 0
(Where squaring a vector *really* means taking the dot product of the
vector with itself.) Here P is your unknown - but it's a vector. If we
replace that with the ray equation
Ray(t) = Dt + S
then we obtain
(Dt + S - C)^2 - r^2 = 0
If we set V = S - C then we have
(Dt + V)^2 - r^2 = 0
and expanding we find
D^2t^2 + 2VDt + V^2 - r^2 = 0
Writing "#" to explicitly mean "dot product", what I really mean is
(D # D) t^2 + 2 (V # D) t + (V # V) - r^2 = 0
Notice this is a quadratic in one unknown - t, a scalar. In fact, what
we have is
a t^2 + b t + c = 0
where
a = D # D
b = 2 (V # D)
c = (V # V) - r^2
Solving this yields a value for t which satisfies the equation. If you
substitute this t back into the original ray equation, it gives you a
point in space for the intersection.
Notice that if you compute multiple intersections, the one with the
lowest value for t is guaranteed to be the "front" one [assuming that S
is the "start point" of the ray. Oh, and if t is negative, the
intersection is "behind" the camera or whatever, and you should ignore
that intersection...]
Any clearer? ;-)
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|