# Separating axis test and distance calculation

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

## 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 on other sites
Is this what you want?

sqrt(pow(x_separation, 2) + pow(y_separation, 2) + pow(z_separation, 2))

##### Share on other sites
Its the minimum positive separating axis distance, isn't it?

Cheers, Paul.

##### Share on other sites

Its the minimum positive separating axis distance, isn't it?

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 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.

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

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 on other sites

Is this what you want?

sqrt(pow(x_separation, 2) + pow(y_separation, 2) + pow(z_separation, 2))

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

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.

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

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.

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 on other sites

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

sqrt(pow(x_separation, 2) + pow(y_separation, 2) + pow(z_separation, 2))

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 on other sites

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?

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 on other sites

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...

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 on other sites

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

Thanks, that makes sense.

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

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 14
• 9
• 10
• 12
• ### Forum Statistics

• Total Topics
633003
• Total Posts
3009830
• ### Who's Online (See full list)

There are no registered users currently online

×