0

I need to be able to calculate the size of rectangle 2

To illustrate my problem here is a diagram:

enter image description here

  • I know the width and height of rectangle 1
  • I know the aspect ratio of rectangle 2 along with a minimum height and width which will always be larger than rectangle 1
  • I know the origin of the rotation which is always the centre of rectangle 1
  • I know the angle of rotation in radians
  • rectangle 1 must always be fully inside rectangle 2

Given the above variables I need to calculate the smallest size rectangle 2 can be, while maintaining its aspect ratio and rotation origin.

This excellent function calculates the largest possible rectangle within a rotated outer rectangle.

Calculate largest rectangle in a rotated rectangle

I have tried to use it as a base to achieve the behaviour i require but so far with no luck. I'm linking to it in case it is helpful to anyone with greater Math knowledge than I.

Any help would be greatly appreciated.

Community
  • 1
  • 1
gordyr
  • 6,078
  • 14
  • 65
  • 123
  • Is the angle of rotation between 0 and 1/2 radian? The angle will be present in all small adjacent triangles, so you can easily find the vertices of the new rectangle. – Timothy Ha Nov 11 '14 at 06:20
  • The angle can be anywhere in a half turn, so 0 - 1Pi radians. – gordyr Nov 11 '14 at 07:56
  • As for the idea about adjacent triangles, does that work for you? It's some trigonometry problem, not programming. – Timothy Ha Nov 11 '14 at 09:00
  • @TimothyHa Indeed it is a trigonometry problem. Which is why i'm srtruggling, given that I have such a poor grasp of this kind of math. – gordyr Nov 11 '14 at 09:07

1 Answers1

1

In the comments you said it's just a trigonometry problem, so I am writing only the formulas.

In your picture, the right bottom triangle will be part of the larger rectangle that you need.

If the smaller angle is x (it's equal to the angle of rotation), and side of inner rectangle is a, then sides of the triangle will be a * cos(x) and a * sin(x). When we move to next side of inner rectangle, the lower b, we will have b * cos(x), b * sin(x).

The picture will be symmetrical, so one side of the larger rectangle will be a * cos(x) + b * sin(x), another will be a * sin(x) + b * cos(x). These are the sizes you need.

You can check with x = 0 (no rotation), x = pi/2 or pi to see what would be the special cases and sizes in those cases.

Timothy Ha
  • 399
  • 3
  • 7