Sign in to follow this  

Separating axis test and distance calculation

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

Hello,

I implemented a separating axis test for 3D collision detection with oriented bounding boxes.
I can get the collision depth by looking for the minimum overlap on the axes.

Now I also need to get the distance of non colliding boxes but I can't figure out if there is a way to calculate it from the projections of the separating axis test.

So is there a way which uses the available data from the separating axis test or do I have to implement a distance calculation algorithm separately?

I would be glad if you have any ideas...

Share this post


Link to post
Share on other sites
[quote name='wildbunny' timestamp='1336418857' post='4938157']
Its the minimum positive separating axis distance, isn't it?
[/quote]

No, it's not. Think of the boxes [x1, x1+e] x [y1, y1+e] x [z1, z1+e] and [x2, x2+e] x [y2, y2+e] x [z2, z2+e]. The limit of the distance between them when e -> 0 has to be sqrt(pow(x1-x2, 2) + pow(y1-y2, 2) + pow(z1-z2, 2)). Edited by alvaro

Share this post


Link to post
Share on other sites
Ahh yes, of course - I'd forgotten it worked differently for separation compared with penetration. With separation you need to account for more than just the separating axis themselves, you also need to account for the geometry of the faces and edges.

Penetration is different because you only need to worry about the actual axis formed by the faces of both objects and the cross-products of the edges.

In this article I wrote, you can see the problem you need to address:

[url="http://www.wildbunny.co.uk/blog/2011/04/20/collision-detection-for-dummies/"]http://www.wildbunny.co.uk/blog/2011/04/20/collision-detection-for-dummies/[/url]

Scroll down to the section on OBB vs OBB - there is a little applet demonstrating the difference I was describing. The axis is shown as the line from the centre of the applet to a face on B-A. When this axis is aligned with a face of A or B, the minimum distance is aligned with a separating axis. However, when that axis is not aligned, the distance is actually that of two vertices. In 3d there is vertex vs vertex and edge vs edge distance as well.

Hope that helps!

Cheers, Paul.

Share this post


Link to post
Share on other sites
Thanks for your ideas.

[quote name='alvaro' timestamp='1336411199' post='4938116']
Is this what you want?

[code]sqrt(pow(x_separation, 2) + pow(y_separation, 2) + pow(z_separation, 2))[/code]
[/quote]

I think this only works for axis-aligned bounding boxes? I use oriented bounding boxes...

[quote name='wildbunny' timestamp='1336425074' post='4938191']
Ahh yes, of course - I'd forgotten it worked differently for separation compared with penetration. With separation you need to account for more than just the separating axis themselves, you also need to account for the geometry of the faces and edges.

Penetration is different because you only need to worry about the actual axis formed by the faces of both objects and the cross-products of the edges.

In this article I wrote, you can see the problem you need to address:

[url="http://www.wildbunny.co.uk/blog/2011/04/20/collision-detection-for-dummies/"]http://www.wildbunny...on-for-dummies/[/url]

Scroll down to the section on OBB vs OBB - there is a little applet demonstrating the difference I was describing. The axis is shown as the line from the centre of the applet to a face on B-A. When this axis is aligned with a face of A or B, the minimum distance is aligned with a separating axis. However, when that axis is not aligned, the distance is actually that of two vertices. In 3d there is vertex vs vertex and edge vs edge distance as well.

Hope that helps!

Cheers, Paul.
[/quote]

Interesting approach. This might be a good solution for the problem but it would require a whole new implementation and I could discard my separating axis test.

My main question is:
Is the distance parallel to on of the 15 axes as if the penetration depth?
If so I could use the separating axis test results to calculate it...

Share this post


Link to post
Share on other sites
[quote name='Nokobon' timestamp='1336470342' post='4938330']
Thanks for your ideas.

[quote name='alvaro' timestamp='1336411199' post='4938116']
Is this what you want?

[code]sqrt(pow(x_separation, 2) + pow(y_separation, 2) + pow(z_separation, 2))[/code]
[/quote]

I think this only works for axis-aligned bounding boxes? I use oriented bounding boxes...
[/quote]

You are right. The word "oriented" threw me off: I thought an arbitrary bounding box would just be called a "bounding box". After a quick web search I see that your name is perfectly common.

I am pretty sure you cannot deduce the distance between two boxes from the projections alone, but perhaps there is something else I don't understand, since you seem to be testing 15 axes, and I can only think of 6 that matter. Would you mind explaining where the 15 axes come from?

Share this post


Link to post
Share on other sites
[quote name='alvaro' timestamp='1336477315' post='4938345']
You are right. The word "oriented" threw me off: I thought an arbitrary bounding box would just be called a "bounding box". After a quick web search I see that your name is perfectly common.

I am pretty sure you cannot deduce the distance between two boxes from the projections alone, but perhaps there is something else I don't understand, since you seem to be testing 15 axes, and I can only think of 6 that matter. Would you mind explaining where the 15 axes come from?
[/quote]

6 axes: face-normals of both boxes
9 axes: pairwise crossproducts of distinct edges of both boxes (3*3)

The projection of the boxes needs to be done on these 15 axes. If on at least one of them the projections don't overlap, there is a plane that separates both boxes.
If the projections overlap on all axes, the boxes intersect, too. The penetration depth is the smallest overlap on an axis. So the minimum translation vector to get out of the collision is parallel to the axis with the smallest overlap.

The problem is, that the smallest distance between two non-intersecting boxes is not necessarily parallel to one of the 15 axes (e.g. when the minimum distance is between two vertices).

So I don't know if there is a way to deduce the distance from the projections... Edited by Nokobon

Share this post


Link to post
Share on other sites
[quote name='Nokobon' timestamp='1336470342' post='4938330']
Interesting approach. This might be a good solution for the problem but it would require a whole new implementation and I could discard my separating axis test.

My main question is:
Is the distance parallel to on of the 15 axes as if the penetration depth?
If so I could use the separating axis test results to calculate it...
[/quote]

No the distance isn't parallel to a separating axis in all cases - you can see that in the demo when the vertices of the two OBBs are the closest features.

Share this post


Link to post
Share on other sites
[quote name='Nokobon' timestamp='1336483103' post='4938364']
6 axes: face-normals of both boxes
9 axes: pairwise crossproducts of distinct edges of both boxes (3*3)
[/quote]
Thanks, that makes sense.

I think wildbunny is right and you won't be able to measure distance based on the 15 projections.

Share this post


Link to post
Share on other sites

This topic is 2050 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.

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