Started by Aug 03 2011 02:49 PM

,
13 replies to this topic

Posted 03 August 2011 - 02:49 PM

So i've finished up my GJK algorithm and now im attempting to implement the EPA algorithm to determine penetration depth. From what i understand it returns a vector representing the direction and magnitude of the smallest penetration.

For me this isnt exactly what i want. I need an algorithm that would return the penetration depth for a specific direction. For example:

Lets says i have an object moving in a particular direction, i want to determine the penetration depth in that direction so i can rectify the proper position as seen in A, verses B which gives the minimum penetration depth.

I assume this would be simpler than the typical EPA algorithm in that it only needs to search in a particular direction to find the distance from the origin to the hull of the minkowski difference. Any suggestions about finding the distance as precisely as possible?

Im thinking something along the lines of searching for the farthest point in the opposite direction the object is travelling in. However that is confined to vertices and wont be too accurate in some cases. Any ideas?

For me this isnt exactly what i want. I need an algorithm that would return the penetration depth for a specific direction. For example:

Lets says i have an object moving in a particular direction, i want to determine the penetration depth in that direction so i can rectify the proper position as seen in A, verses B which gives the minimum penetration depth.

I assume this would be simpler than the typical EPA algorithm in that it only needs to search in a particular direction to find the distance from the origin to the hull of the minkowski difference. Any suggestions about finding the distance as precisely as possible?

Im thinking something along the lines of searching for the farthest point in the opposite direction the object is travelling in. However that is confined to vertices and wont be too accurate in some cases. Any ideas?

Posted 03 August 2011 - 03:54 PM

It sounds like using a portion of Minkowski Portal Refinement/XenoCollide would get you what you want.

The core of the algorithm is basically a ray cast from inside the minkowski difference to the surface in some given direction. For intersection queries, it checks to see if the ray hits the surface or the origin first. Adapting it to find penetration depths in arbitrary directions by casting from the origin is pretty simple.

The core of the algorithm is basically a ray cast from inside the minkowski difference to the surface in some given direction. For intersection queries, it checks to see if the ray hits the surface or the origin first. Adapting it to find penetration depths in arbitrary directions by casting from the origin is pretty simple.

Posted 03 August 2011 - 05:00 PM

It sounds like using a portion of Minkowski Portal Refinement/XenoCollide would get you what you want.

The core of the algorithm is basically a ray cast from inside the minkowski difference to the surface in some given direction. For intersection queries, it checks to see if the ray hits the surface or the origin first. Adapting it to find penetration depths in arbitrary directions by casting from the origin is pretty simple.

hmm i remember looking at the MPR example on the XenoCollide website and never really understood its benefits over GJK. Then again, i'm a complete noob.

My knowledge of ray casting is quite limited. Lets say i cast from the origin outwards to an edge:

How do i determine the magnitude of the ray to the edge when i only have vertex data?

Posted 03 August 2011 - 05:30 PM

MPR works on the extreme points of objects, just like GJK. The general idea of a surface cast in MPR is that you create a triangle from support maps through which the ray passes, then incrementally refine that triangle until you reach the surface.

The incremental refinement process finds the extreme point along the current triangle's normal. That point, combined with the three vertices of the previous triangle, forms three new triangles. The outer face of that tetrahedron which contains the ray is picked as the new triangle, and the process continues.

A more detailed explanation can be found in the Game Programming Gems 7 book where XenoCollide was published. The XenoCollide website also has some code samples I believe. Some other open source engines have implementations that you could look at too (including mine, BEPUphysics).

The incremental refinement process finds the extreme point along the current triangle's normal. That point, combined with the three vertices of the previous triangle, forms three new triangles. The outer face of that tetrahedron which contains the ray is picked as the new triangle, and the process continues.

A more detailed explanation can be found in the Game Programming Gems 7 book where XenoCollide was published. The XenoCollide website also has some code samples I believe. Some other open source engines have implementations that you could look at too (including mine, BEPUphysics).

Posted 03 August 2011 - 06:03 PM

MPR works on the extreme points of objects, just like GJK. The general idea of a surface cast in MPR is that you create a triangle from support maps through which the ray passes, then incrementally refine that triangle until you reach the surface.

The incremental refinement process finds the extreme point along the current triangle's normal. That point, combined with the three vertices of the previous triangle, forms three new triangles. The outer face of that tetrahedron which contains the ray is picked as the new triangle, and the process continues.

A more detailed explanation can be found in the Game Programming Gems 7 book where XenoCollide was published. The XenoCollide website also has some code samples I believe. Some other open source engines have implementations that you could look at too (including mine, BEPUphysics).

okay that makes a little more sense.

Sorry the question above about the ray casting was about your comment in the first post

Adapting it to find penetration depths in arbitrary directions by casting from the origin is pretty simple.

Lets say my GJK returns true, so i know the objects are intersecting, now to find the penetration depth i a particular direction all i need to do is find the distance from the origin to the farthest 'point' in the minkowski difference in that particular direction (or possibly the opposite direction, not sure yet). So for the the example below, considering that i onyl have vertex data, what would be the steps to get the magnitude of the vector from the origin to the hull of the minkowski difference?

Posted 03 August 2011 - 06:30 PM

That distance is obtained from the process I described in my previous post.

The triangle ("portal") is refined until it reaches the surface. Once you find the surface, you have a plane (from the portal) and a ray. Intersect the ray with that plane.

The triangle ("portal") is refined until it reaches the surface. Once you find the surface, you have a plane (from the portal) and a ray. Intersect the ray with that plane.

Posted 03 August 2011 - 06:48 PM

That distance is obtained from the process I described in my previous post.

The triangle ("portal") is refined until it reaches the surface. Once you find the surface, you have a plane (from the portal) and a ray. Intersect the ray with that plane.

well i figure if i know the direction im casting, i can find the plane by seaching for the 3 points on the minkowski difference farthest in the direction. I guess what im asking is how do i intersect the ray with that plane.

Posted 03 August 2011 - 07:01 PM

That will not work in general. Consider this 2d example:well i figure if i know the direction im casting, i can find the plane by seaching for the 3 points on the minkowski difference farthest in the direction.

It's just a regular old geometry test. Googling ray-plane intersection or line-plane intersection should come up with plenty of resources.I guess what im asking is how do i intersect the ray with that plane.

Posted 04 August 2011 - 03:24 PM

That will not work in general. Consider this 2d example:well i figure if i know the direction im casting, i can find the plane by seaching for the 3 points on the minkowski difference farthest in the direction.

It's just a regular old geometry test. Googling ray-plane intersection or line-plane intersection should come up with plenty of resources.I guess what im asking is how do i intersect the ray with that plane.

bugger... just when i thought it was going to be easy...

Im trying to think of a way to find the plane that would be intersected for my arbitrary direction. From what i understand MPR would give me a plane closests to the origin on the outside of the minkowski difference.

But in my case where i simply want to intersect the farthest plane in a certain direction, it wont necessarily be the plane given by MPR, because it may not be the closest plane to the origin, for example:

In this case i would still need to determine which plane would be intersected.

I guess what im trying to ask is a) can i use my boolean GJK test to first determine whether a intersection has occuredand then go about ray casting and determining the plane that will be intersected? Do i have to use an MPR implementation?

Is there a way to find which plane it would be intersecting wittout MPR?

Posted 04 August 2011 - 09:35 PM

A surface cast with MPR will give you the correct surface plane. Keep in mind when I'm talking about MPR, I am not talking about the specific implementation which computes boolean intersection.

I am referring to the slightly modified form which starts the ray at the origin (known to be in the minkowski difference if GJK returns intersection, barring numerical issues) and ray casts in an arbitrary direction. The portal is refined based on the ray direction you pick. Since the portals are incrementally refined based on the ray's direction, the final surface plane it finds will be the correct surface plane.

So:

Off the top of my head, I can't think of another alternative which is as simple/fast as MPR while still giving correct results. There probably exists something out there in undiscovered (or at least unknown to me at the moment) algorithm space, and you could look for that if you really wanted

However, there are probably a lot of workarounds- algorithms which may not be quite as direct, simple, or fast, but should do the trick. Here's one I just thought up- haven't implemented anything like it, but I don't see a reason why it wouldn't work:

If you have GJK ray casting implementation, you should be able to do a similar, reversed operation. Pick a ray origin using direction * X, where X is a number large enough to guarantee that the ray origin is outside of the convex shape. Then, for the ray direction, use the negative direction you would have used for an MPR cast since we're pointing back at the shape. The distance from the minkowski space origin and the surface of the minkowski difference is then X - T, where T is the distance along the GJK ray direction to the impact location.

I am referring to the slightly modified form which starts the ray at the origin (known to be in the minkowski difference if GJK returns intersection, barring numerical issues) and ray casts in an arbitrary direction. The portal is refined based on the ray direction you pick. Since the portals are incrementally refined based on the ray's direction, the final surface plane it finds will be the correct surface plane.

So:

Yes, the GJK test can be used to determine the containment of the origin.can i use my boolean GJK test to first determine whether a intersection has occuredand then go about ray casting and determining the plane that will be intersected?

Do i have to use an MPR implementation?

Is there a way to find which plane it would be intersecting wittout MPR?

Off the top of my head, I can't think of another alternative which is as simple/fast as MPR while still giving correct results. There probably exists something out there in undiscovered (or at least unknown to me at the moment) algorithm space, and you could look for that if you really wanted

However, there are probably a lot of workarounds- algorithms which may not be quite as direct, simple, or fast, but should do the trick. Here's one I just thought up- haven't implemented anything like it, but I don't see a reason why it wouldn't work:

If you have GJK ray casting implementation, you should be able to do a similar, reversed operation. Pick a ray origin using direction * X, where X is a number large enough to guarantee that the ray origin is outside of the convex shape. Then, for the ray direction, use the negative direction you would have used for an MPR cast since we're pointing back at the shape. The distance from the minkowski space origin and the surface of the minkowski difference is then X - T, where T is the distance along the GJK ray direction to the impact location.

Posted 05 August 2011 - 12:02 AM

ahh i kept thinking you were talking about using MPR to determine if there is a collision.

Using the MPR this way seems very similar to the EPA, if it were given a arbitrary search direction, i guess ill have to fish around to figure out how the algortihm determines which plane is the correct plane.

Thank you for all of your time and help, its is greatly appretiated!

Using the MPR this way seems very similar to the EPA, if it were given a arbitrary search direction, i guess ill have to fish around to figure out how the algortihm determines which plane is the correct plane.

Thank you for all of your time and help, its is greatly appretiated!

Posted 05 August 2011 - 06:16 AM

Nice topic name

EDIT: I can be of no further help Norbo seems to have covered it all.

EDIT: I can be of no further help Norbo seems to have covered it all.

WARNING: I edit my posts constantly.

Posted 12 August 2011 - 09:11 AM

Is this in 2d?

If so, I would just compute the full minkowski difference and have done with it - it will end up being faster and more robust in the long run

http://www.wildbunny.co.uk/blog/2011/04/20/collision-detection-for-dummies/

Cheers, Paul.

If so, I would just compute the full minkowski difference and have done with it - it will end up being faster and more robust in the long run

http://www.wildbunny.co.uk/blog/2011/04/20/collision-detection-for-dummies/

Cheers, Paul.

Posted 15 August 2011 - 04:11 PM

Is this in 2d?

If so, I would just compute the full minkowski difference and have done with it - it will end up being faster and more robust in the long run

http://www.wildbunny...on-for-dummies/

Cheers, Paul.

Unfortunately it;s in 3D