0

I'm trying to calculate the new width and height of an inner rotated rectangle. The bounding box dimensions are known also the initial values (w & h for rotaton 0deg) and so the current rotation angle (in this case 45 degrees).

Now, the user should be able to resize the bounding box. Therefore I need to recalculate its new height and width so I can save them properly.

I've tried several solutions including those two

How do I scale one rectangle to the maximum size possible within another rectangle?

and

Calculate rotated rectangle size from known bounding box coordinates

The last one represents my current state and I get weird small or sometimes negative results. (radians and degrees tested). I guess my whole approach is wrong so I don't really need complete solution. But, any hints or different solution approaches are highly appreciated.

enter image description here

YeppThat'sMe
  • 1,812
  • 6
  • 29
  • 45
  • You should be able to work this out with some basic math, see sin/cos functions and how to use them: https://en.wikipedia.org/wiki/Trigonometric_functions Think of the corners of the bounding box as two right angled triangles – Peter Oct 03 '17 at 19:37
  • But for this approach I need to know where at least 2 of 4 corners are located, I guess. Basically, I want to create that recangle with a given rotation and place it in the middle of the blue dashed lined box. Therefore I need to know which maxHeight and maxWidth I need. Imaginge you'll only get the boundingbox dimenstions and rotation. Then you\ll have to calculate the rectangle. – YeppThat'sMe Oct 03 '17 at 19:51

0 Answers0