# Determine contact edge of 2 boxes

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

## Recommended Posts

Hello!

I have a "simple" problem, yet I could not figure out how to solve this. Assume I have 2 boxes, 1 is static (the black one), the other one is moving (please look at the attachment).

I have sketched 3 cases in the picture. All 3 moving boxes have the same movement direction. I want to determine WHICH edge of the static black box is hit first by the moving box (I need this to resolve the collision)
So in my sketch the green and blue box will hit +Y edge of the black box. The red box will hit the -X edge of the black box. If the blue box was smaller, it would hit the -X edge. So its obvious that the contact edge depends on the extent of the static box, the moving box and the direction.

Do you know a "simple" algorithm to detect the contact edge (the edge where the first contact occurs)?

##### Share on other sites

Hello!

I have a "simple" problem, yet I could not figure out how to solve this. Assume I have 2 boxes, 1 is static (the black one), the other one is moving (please look at the attachment).

I have sketched 3 cases in the picture. All 3 moving boxes have the same movement direction. I want to determine WHICH edge of the static black box is hit first by the moving box (I need this to resolve the collision)
So in my sketch the green and blue box will hit +Y edge of the black box. The red box will hit the -X edge of the black box. If the blue box was smaller, it would hit the -X edge. So its obvious that the contact edge depends on the extent of the static box, the moving box and the direction.

Do you know a "simple" algorithm to detect the contact edge (the edge where the first contact occurs)?

Yes

For each pair of boxes:

* Expand the large box by the extents of the smaller box
* Shrink the smaller box down to a point
* Ray-cast from the point along the velocity of the smaller box
* Intersection point is the first point of contact between the boxes, get the edge from this

Cheers, Paul.

##### Share on other sites
Thats just brilliant! I got it working now!

Thank you very much wildbunny!

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633686
• Total Posts
3013324
×