user1482649
user1482649

Reputation: 45

computing overlapping of two square in collision

I am trying to compute the overlapping area of two colliding rectangles.

I found the Separating Axis Theorem to compute if they are in collision or not, but I'm not sure can I to use it for computing the area of the collision ?

If yes, please advise which computation do I have to perform?

Basically, I need to compute the percentage of hidden part of a picture (the rectangle A is a picture 256*256 for example), and one other picture overlaps it, I want to get the percentage of the hided part in comparison to the global surface of the picture.

Upvotes: 0

Views: 511

Answers (1)

MSalters
MSalters

Reputation: 179991

Check for intersections of edges. Either no edges intersect (easy, 100% or 0% overlap) or some edges overlap. In the latter case, you have an even number of intersection points (disregarding points where edges touch). Trace the resulting convex overlap polygon and calculate its area.

Upvotes: 2

Related Questions