Skip to main content
gamedev.net
🔒 Locked

Ray-Triangle intersection

Started by Code Fusion 0 replies 1.1k views
Original Post
Code Fusion
Code Fusion
this is ray-triangle intersection , from my prespective. if a ray parrel to one side of a triangle is projected from any point inside a triangle , it should intersect one side of the triangle , and another ray from the same point in the oppisite direction will intersect the other.so from the eqn of the line , t will be pos+ , and intersect one side , then t will be neg- , and intersect the other. P1 intersects one side with a pos+ t , and one side with a neg- t , so it's inside the triangle. P2 is below the triangle , and intersect with both edges infinite rays , but it intersects (v3-v1) , in it's Neg- t. so it's outside. p3 is above the triangle , and intersects with both edges infinite rays , but it intersects in the oppisite manner to p1 , so it's outside. p4 is on the right of the triangle , and intersects both sides with it's pos+ t. so it's outside. p5 is on the left of the triangle , and intersects both sides in it's neg- t. so it's outside. any points left will be on the triangle's edges , which sets the t of the ray to 0. that decision is taken when testing if t >< 0 , by simple adding an equal sign ,or not. first i test if a point on the ray i project is on the plane of the triangle , which requires one division. if it's on the ray , i test to see if t is between 0..1. now i test to see if the upper part of the ray-ray intersection (between the point , and (V2-V3) ) eqn yields a non-neg value (cause the donimonator is the mangitude squared , which can't yield a neg-value). if it does , i make an early out , cause that means it's either above the triangle , or on the right. if not, i make a ray-ray intersection (between the point , and (V3-V1)) , to see if it's a neg- value. if it is , i exit , cause that means it's on the left of the triangle.finally i get the upper part of the eqn for t2 (which is for the edge) , to see if it's neg , which means it's below the triangle. if all the tests are passed , then it's inside the triangle. i made a working example of this , so iam sure it works , but iam not sure about irregular scenarios. critcism is needed , and insults are welcomed.
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
Code Fusion
Code Fusion
com on ppl , just say your openion. do you think it's fast , is it going to
fail in some areas.
it takes 3 cross products , 1 division , and the normals aren't pre-computed.
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.