# Check for intersection between a triangle and a square

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

## 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 on other sites
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 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 on other sites
axes in 2D are the vectors perpendicular to edges.

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

##### Share on other sites
Thanks a lot guys. Looks like I will be learning a lot of math today!

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 9
• 15
• 14
• ### Forum Statistics

• Total Topics
634070
• Total Posts
3015333
×