View Full Version : ray/triangle intersection + uv calculation
08-29-2005, 10:55 PM
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)
08-31-2005, 06:44 AM
Google a little about barycentric coordinate and I think that you can find all you want about this.
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 ...
08-31-2005, 10:13 PM
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 :)
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.