find if one rectangle fits into another

Let's talk about algorithms!

Moderator: Board moderators

Post Reply
abductor
New poster
Posts: 8
Joined: Sat Jan 18, 2003 6:43 pm
Location: Canada

find if one rectangle fits into another

Post by abductor »

Can anyone please explain to me how to find out if one rectangle can fit into another(rotation is possible) given length and width of each?

thank you
Ivor
Experienced poster
Posts: 150
Joined: Wed Dec 26, 2001 2:00 am
Location: Tallinn, Estonia

Post by Ivor »

r1 fits into r2 if:
w1 < w2 and h1 < h2
or
w1 < h2 and h1 < w2

Is this what you want?
There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.
makbet
New poster
Posts: 44
Joined: Tue Nov 26, 2002 11:01 pm
Location: Wejherowo

Post by makbet »

You have to notice, that there are
only 2 possibilities to fit it.
One is that the two rectangles' sides are parallel to each other,
and this case is easy. The other
one is a bit complicated:
You have to rotate the smaller rectangle, so that two opposite
corners touch the bottom and top side of the bigger rectangle, and then see if the other corners are inside or outside. This also divides into 2 cases (the big rectangle can be vertical or horizontal), so the whole thing can be checked in constant time.
Post Reply

Return to “Algorithms”