2
\$\begingroup\$

I've just implemented collision detection using SAT and this article as reference to my implementation. The detection is working as expected but I need to know where both rectangles are colliding.

I need the center of the intersection More examples

I need to find the center of the intersection, the black point on the image above. I've found some articles about this but they all involve avoiding the overlap or some kind of velocity, I don't need this.

I just need to put a image on top of it. Like two cars crashed so I put an image on top of the collision. Any ideas?

## Update

The information I've about the rectangles are the four points that represents them, the upper right, upper left, lower right and lower left coordinates. I'm trying to find an algorithm that can give me the intersection of these points.

\$\endgroup\$
2
  • \$\begingroup\$ Why can't you just take the midpoint of the two rectangles' centers? \$\endgroup\$
    – you786
    Oct 2 '12 at 18:18
  • \$\begingroup\$ Would this work with rotated rectangles? I've updated the question with more examples \$\endgroup\$ Oct 2 '12 at 18:26
1
\$\begingroup\$

You dont actually want the center of collision, generally. The term to look for is "polygon clipping." I'll try to give a quick description.

The idea is to clip one polygon's edges against the incident edge (the axis you separated on), as well as the edge's ends. The clip points you end up with (usually two) will be the contact points to use for physics. You can join these with any interior vertices in the collision if you need a shape rather than just points, by you generally don't need that.

\$\endgroup\$
2
  • \$\begingroup\$ polygon clipping would be the same as finding the intersection area ? \$\endgroup\$ Oct 2 '12 at 19:24
  • \$\begingroup\$ It's a subset of it, basically. For game physics, you generally just want those contact points, not the whole area, so you can simplify and avoid calculating the whole area. \$\endgroup\$ Oct 2 '12 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.