Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have 2 squares with the same orientation. I know the coordinate of their centers. They have the same size area.

They may intersect each other. I want to compute their area of their intersection as well as area of their union.

Let's say that their centers are (a, b) for the first square and (x, y) for the second square. The length of one of their sides is l. How can I compute their intersection and their union based on this?

share|improve this question
    
Do both squares have side length 1? –  Tom Oldfield Oct 31 '12 at 14:17
    
They have the same length L. –  Simon Oct 31 '12 at 14:21

1 Answer 1

up vote 1 down vote accepted

Call the distance between the centres $d=\sqrt{(x-a)^2+(y-b)^2}$ and the distance from the corner of one square to it's centre is $\frac{L}{\sqrt{2}}$. So if $$d\geq 2\frac{L}{\sqrt{2}} = \sqrt{2}L$$ Then the squares do not intersect and we are done. Otherwise, the squares intersect in a rectangle.

The base of the rectangle of intersection is $L-|x-a|$ and it's height is $L-|y-b|$ since, for example, the horizontal distance between the centres $(|x-a|)$ $+$ the horizontal overlap gives $L$ (draw a diagram if you can't see this.)

Everything should now be easy to calculate!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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