Sign in to follow this  
barakus

Check for intersection between a triangle and a square

Recommended Posts

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this