Categories
algorithms kotlin

Problem 5.11 from EPI -> Intersecting rectangles

Give a rectangle, does another rectangle intersects it? If it does print out the intersecting rectangle!
The tricks to detecting if they intersect is to treat x and y axis separately, and then combine both checks in to one.
The trick to getting the intersected rectangle is to realize that any of the two rectangles can be on the left or the right side, so taking max() and min() of both rectangle we can get a correct answer.
Take a look at this code

Leave a Reply

Your email address will not be published. Required fields are marked *