Started by May 07 2012 10:09 AM

,
9 replies to this topic

Posted 07 May 2012 - 10:09 AM

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

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

Posted 07 May 2012 - 11:19 AM

Is this what you want?

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

Posted 07 May 2012 - 01:27 PM

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

Cheers, Paul.

Cheers, Paul.

Posted 07 May 2012 - 01:33 PM

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, 07 May 2012 - 01:34 PM.**

Posted 07 May 2012 - 03:11 PM

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:

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.

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:

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.

Posted 08 May 2012 - 03:45 AM

Thanks for your ideas.

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

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

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.

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

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

Posted 08 May 2012 - 05:41 AM

Thanks for your ideas.

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

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?

Posted 08 May 2012 - 07:18 AM

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, 08 May 2012 - 08:29 AM.**

Posted 08 May 2012 - 12:03 PM

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.

Posted 08 May 2012 - 12:33 PM

Thanks, that makes sense.6 axes: face-normals of both boxes

9 axes: pairwise crossproducts of distinct edges of both boxes (3*3)

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