Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I calculate the Minkowski Difference between two AABBs (with no vector math)?

I'm implementing the second version of my collision detection library. This particular library should deal with axis-aligned boxes (AABBs). I'd like to start tracking fast-moving boxes on this version. I think calculating the Minkowski Difference between the two would be a good starting point for that.

When I say Minkowsky Difference I mean the geometric operation described in Collision detection for Dummies.

The catch is: The process and algorithm described there is very generic. It uses fairly advanced vector math to calculate the MD of any two polygons.

In my case I have AABBs. Given their numerical simplicity, the library so far has not needed a Vector concept - for example, I have not needed to compute a single dot product. I'd like it to stay that way if at all possible.

So my question is:

Given two AABBs by their top,left,width and height ({t1,l1,w1,h1} and {t2,l2,w2,h2}), how do I calculate their MD, (without getting vector math if possible)?

Just by playing with the widget on Collision detection for Dummies, I'm almost certain that the MD width will be a box of width w1+w2 and height h1+h2. But I have no idea about how to calculate its top or left corner.

like image 412
kikito Avatar asked Nov 21 '12 23:11

kikito


1 Answers

The Minkowski difference for two axes-aligned rectangles {t1, l1, w1, h1} and {t2, l2, w2, h2} is itself an axes-aligned rectangle:

l = l1 - l2 - w2
t = t2 - t1 - h1
w = w1 + w2
h = h1 + h2

The following is a short javascript demo to show this in action. You can drag any of the two rectangles. They will change color when overlapping

Demo: http://jsbin.com/afojes/2/

Code: http://jsbin.com/afojes/2/edit

No collision

Collision detected

like image 176
Oren Trutner Avatar answered Oct 19 '22 08:10

Oren Trutner