|
![](/i/fill.gif) |
"Warp" <war### [at] tag povray org> wrote:
> I have never read or thought about the details of raytracing a triangle,
> but the basic algorithm is:
> [...]
> 2. See if the intersection point is inside the boundaries defined by the
> triangle (the first fast test is if t<0, then the ray did not hit the
> triangle).
> [...]
> I can't say right now how step 2 is implemented.
May I help?
You have the plane defined by three points A,B,C.
You also have the intersection of the ray and the plane at point P.
Now you simply try to represent P by a linear combination of (C-A) and (B-A):
P=u*(C-A)+v*(B-A)
If, and only if,
a) A,B,C are forming a plane, and
b) P lies in the plane
this equation has exactly one solution for u and v.
now simply compare, if u and v are between 0 and 1 (including). if so, P is
inside the triangle and the ray hits the triangle.
IIRC, there was a shortcut, to combine your step 1 and 2, to speed up some
calculations, but concerning the current time, I'm simply to lazy and tired to
look it up now ...
Post a reply to this message
|
![](/i/fill.gif) |