2

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

3
  • sigh as you may be able to tell math is not my strong point. That makes perfect sense thank you. If you'd like to write it up as an answer I will of course award it to you.
    – gordyr
    Oct 28, 2014 at 11:23
  • @AndrewMorton I don't think so. he is not searching for arbitrary bounding box but for rectangle with the same aspect ratio instead. so it is not the same problem. but yes you're right if he rotate it back, found the minimal bounding rectangle then he can take one side of it and resize the other to match aspect ratio. do the same with the other side and choose the smaller choice as final result ...
    – Spektre
    Oct 28, 2014 at 11:26
  • @Spektre you are correct... my comment was premature and I am still indeed searching for the answer. with regards to where the aspect ratio is mentioned, it is where I state that rectangle B has exactly the same dimensions as rectangle A when they are not rotated. I will clarify the question somewhat.
    – gordyr
    Oct 28, 2014 at 11:34

1 Answer 1

2

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

2
  • I think even with this you have to try both choices and choose the smallest one. (the space can be also on sides instead of above/under)
    – Spektre
    Oct 28, 2014 at 12:36
  • Yep, in order for this to work at all angles it requires a check.
    – gordyr
    Oct 28, 2014 at 12:44

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.