0

I have two rectangles on a grid, defined by x, y, width, and height (all integers).

I want to tell if one of them bisects the other. That is, not just overlaps, but goes all the way through so as to create three rectangles.

Example: Overlap vsbisect

Is there a relatively time-efficient algorithm to do this?

0

1 Answer 1

2

If we look at the second example in your question, we can find the following conditions to determine if rectangle A bisects rectangle B vertically:

xA <= xB && xA + widthA >= xB + widthB && yA > yB && yA + heightA < yB + heightB

Similarly, there are three more cases (horizontal and the same for the other way around). If any of these cases apply, you have a bisection.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.