Sign in to follow this  
elis-cool

Two polygons, finding point of collision

Recommended Posts

Hey guys, Im using Seperating Axis Theorem (SAT) to detect if two polygons intersect, which works great.. but now I need to find the point where they collide. How would I go about doing this? the two polygons are moving at their own individual velocities vx,vy. Obviously where they intersect there is going to be a patch of intersection, so ideally id like to be able to shift the objects back in "time" along their velocity vectors to the point where they collide, and use the first vertex to intersect with an edge of the other polygon as the point of intersection. The SAT provides a way of finding a minimumTranslationVector which can be used to shift the objects back enough so that they dont touch, but along the side which has the minimum overlap, but this doesnt take into account the objects velocities, thus yeilds an innaccurate result in determining a point of first intersection. Here is an image I threw together quickly to clarify: The blue poly has collided with the larger one, and the green poly would be the blue one shifted back along its velocity vector to the point where it first intersects. Free Image Hosting at www.ImageShack.us I had the idea of taking each vertex in both of the polygons and calculating a line segment between the current point=(x,y) and the old point (at time when not intersecting)=(x-vx, y-vy) for each polygon, where vx and vy is the relative velocity between the two objects (ie. polyA.vx-polyB.vx, etc) and testing that line segment against each edge of the other polygon. Not sure if im on the right track or not (espeically with the [relative]velocities), or if there is a better/standard way? Any help would be appreicated. Thanks.

Share this post


Link to post
Share on other sites
Look at Erin Catto's Box2D presentation. He presents an algorithm how to find the full contact manifold using a clipping approach.

www.gphysics.com

Basically you first identify the axis of minimum penetration which gives you the associated reference face. Next you find the incident face and clip the incidcent face against the side planes of the reference face. This is very simple and very robust. It is all there with documentation and souce so it should be fairly simple to adopt this for your problem.

He also presents a conservative advancement (CA) approach how to find the time of impact (TOI). Still you need to build the manifold at the TOI as described above. CA also considers angular velocity what might be not needed in your context. IIRC Christer Ericson has a presentation about GJK for moving objects on his site. There might also be a presentation about SAT for moving objects. Not sure though. You find the presentations here:

www.realtimecollisiondetection.net


Cheers,
-Dirk

Share this post


Link to post
Share on other sites
you can just transpose the SAT with linear velocities. If you project the velocities on the separation axes, that will give you the time of impact. You need to be careful about the time intervals.

clicky.

Share this post


Link to post
Share on other sites
If you only need an approximate collision point to do some collision response you might try sampling along the line segment until it you find a point inside the other polygon. Then use binary search to improve accuracy if needed.

Share this post


Link to post
Share on other sites
Quote:
Original post by oliii
you can just transpose the SAT with linear velocities. If you project the velocities on the separation axes, that will give you the time of impact. You need to be careful about the time intervals.

clicky.


Wow, very awesome examples and tutorial! this would have saved me days of work, haha! is it published anywhere? i'm sure there would be a ton of people who would find it useful.

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