Jump to content
  • Advertisement
Sign in to follow this  

Severe help with ray-triangle intersection

This topic is 4555 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been working many many hours trying to do collision detection. I'd like to have a setup where I can make everything collidible without labeling it a wall or floor and such. I've been trying ray-trangle collision but I can't seem to get it to work. I have a feeling that if I get this all my problems will be solved but I've never done anything like this. I'm completely lost! If someone could explain that from the top or recommend another method that'd be very very swell! Thanks in advance! Note: If you find something out of place ehh sorry! I'm over half sleep while I'm typing this.

Share this post

Link to post
Share on other sites
A ray/triangle hit computation could be done as follows (perhaps there is a more efficient way):

Let the ray be originate at a point R0 and travel along a track r, then
R(t) := R0 + t * r
denotes the ray's current point at a travel distance of t.

Let the triangle be defined by 3 points
{ P0, P1, P2 }
so that a plane is spanned out as
P(u,v) := P0 + u * ( P1 - P0 ) + v * ( P2 - P0 )
and the triangle in this plane is given by the constraints
0 <= (u,v) <= 1 and u+v<=1

The plane's perpendicular vector
p := ( P1 - P0 ) x ( P2 - P0 )
where x denotes the cross product, can then be used to define the plane's unit length normal
n := p / |p|

We are searching for the point on the ray that is 0 length units away from the plane, so that from the Hessian formula of planes the equation
( R(t') - P0 ) . n = 0
has to be solved for t'
t' = ( ( P0 - R0 ) . n ) / ( r . n )
what could obviously done only if
r . n != 0
or else the ray is parallel to the plane and has none or infinite many hit points.

Now, solve
P(u',v') = R(t')
for u' and v' and check for the condition
0 <= (u',v') <= 1 and u'+v'<=1

If true, then P(u',v') = R(t') is the hit point, and comparing the "current" point's R(k) parameter k with t' tells whether it is located before, onto, or behind the triangle w.r.t. the ray's track.

[Edited by - haegarr on April 2, 2006 8:33:21 AM]

Share this post

Link to post
Share on other sites
HA Finally got it! Thanks for the help! I went to this website for a little more input but I had to figure out on my own that I had to subtract the direction from the origin. (sigh) Maybe I should have taken that last year of geometry. Thanks again

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!