Joseph Kirtman
Joseph Kirtman

Reputation: 401

Can rectangle be placed inside other rectangle?

I was given width and height of two rectangles and have to determine if the first one has enough space to be inside the second one.

I checked the obvious horizontal and vertical cases, but what about rotation?

Can someone give me a little hint?

Upvotes: 3

Views: 650

Answers (1)

MBo
MBo

Reputation: 80287

You can calculate dimensions of bounding box for rotated rectangle depending on rotation angle as shown here

H = w * Abs(Sin(Fi)) + h * Abs(Cos(Fi))
W = w * Abs(Cos(Fi)) + h * Abs(Sin(Fi))

where w, h are rotated rectangle dimensions and H, W are bounding box dimensions.

There might exist some intervals of angles where H<Height2 and some intervals with W<Width2. If these intervals do intersect, so rotated rectangle fits into the second one.

Upvotes: 3

Related Questions