Jump to content
  • Advertisement
Sign in to follow this  
barakus

Check for intersection between a triangle and a square

This topic is 4714 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

Ive got bounding box collision detection in my game but now i need support for triangles in my collision detection. How would i go about doing this?

Share this post


Link to post
Share on other sites
Advertisement
Do a google search for "Half-Space Test". You basically take the half-space test for each edge of the triangle against the point, and if they are all less than 0 you know the point is within the triangle.

A half-space test is basically the dot product of the edge normal and the vector between from one of the edge's vertices to the test point. But Half-space tests are used for lots of 3d stuff, so learn it and learn it well!

hth
moe.ron

Share this post


Link to post
Share on other sites
You could try the separating axis theorem. I've only used it in 3d, so I'm not entirely sure how you'd generate potential axes in 2d (since some 3d axes are determined by cross products). Still, I think it would be a good choice.

The basic gist is that you project all the vertices from both objects onto an axis and look at the two regions on the axis represented by each shape's projected points. If the two regions don't overlap, there is definitely no intersection. If they do overlap, then you have to keep testing. If you've tested all the axes that SAT says to test, and can't rule out intersection, then they are definitely intersecting.

The thing with other approaches is that they'll fail on a lot of cases you hadn't thought of. One shape may completely contain the other, or no point from either polygon will lie in the interior of the other polygon, yet they can still be intersecting. etc.

Share this post


Link to post
Share on other sites
axes in 2D are the vectors perpendicular to edges.

http://www.harveycartel.org/metanet/tutorials/tutorialA.html

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!