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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With