gordyr
gordyr

Reputation: 6276

How can I calculate the size of an outer rectangle when it is rotated and must encompass an inner rectangle totally

I have found many answered questions explaining how to calculate the bounding box of a rotated rectangle, however what I need to do is almost the reverse.

The red rectangle A is described as:

var box = {
        x : 0,
        y : 0,
        w : 100,
        h : 200
};

And the dimensions of the blue rectangle B are exactly the same when it is not rotated.

Given that rectangle B is rotated around its center point and that it's angle is provided in radians, how can I calculate the minimum size rectangle B can be when rectangle A must always fit inside it while maintaining its original aspect ratio (as previously mentioned, the same as rectangle A)

enter image description here

Upvotes: 2

Views: 739

Answers (1)

Andrew Morton
Andrew Morton

Reputation: 25013

If you label the sides of the rectangles and draw in an extra line (green in the diagram), you can see what you need to calculate:

enter image description here

So c = a * cos(θ) + b * sin(θ)

and d=b*c/a

Upvotes: 2

Related Questions