PDA

View Full Version : ray/triangle intersection + uv calculation

divide
08-29-2005, 10:55 PM
Hello,

What is the most direct way to intersect a ray with a triangle and compute the associated uv coordinates at this point ?

(something less consuming than matrix operations if possible)

little-body
08-31-2005, 06:44 AM

little-body
08-31-2005, 08:59 AM
Or more simple (but not really more speed) if you have already your proper algorithm for to find the point of intersection (say P) of a triangle ABC and a line from P0 to P1 ...

First, you compute distances from P to A, B and C:

dA = distance from A to P
dB = distance from B to P
dC = distance from C to B

sum = dA + dB + dC
coefA = dA / sum
coefB = dB / sum
coefC = dC / sum

So, the texture coordinate at point P is :

uP = uA * coefA + uB * coefB + uC * coefC
vP = vA * coefA + vB * coefB + vC * coefC

Note too that you can apply this to alls points P into the triangle ABC and to be applied to another style of coordinates such as color componants for example ...

divide
08-31-2005, 10:13 PM
Thanks !
I first calculated my own barycentric formulas, however it requires far more operations than yours. But yours involve square roots operation, so.. Well I have to give it a try :)