monoman
Master baiter - I fish!
- Joined
- Mar 23, 2004
- Messages
- 967
Given a bounding box of a shape, I can calculate the width and height of the bounding box after the object has been rotated with the following formulas:
Where H and W are the original height and width of the bounding box.
I need a formula for working in reverse. Given New Height, New Width and angle, I want to find H and W (for the same angle).
With some messing around, I came up with the following formulas:
These work for some angles but start misbehaving for other angles. Also, it can be seen that it wont work for certain angles, such as 45, because I'll be dividing by zero.
Any ideas how I can get it to work for any angle?
Code:
New Height = H * cos(angle) + W * sin(angle)
New Width = H * sin(angle) + W * cos(angle)
I need a formula for working in reverse. Given New Height, New Width and angle, I want to find H and W (for the same angle).
With some messing around, I came up with the following formulas:
Code:
temp = sqr(cos(angle)) - sqr(sin(angle))
H = (newHeight * cos(angle) - newWidth * sin(angle)) / temp
W = (newWidth * cos(angle) - newHeight * sin(angle)) / temp
Any ideas how I can get it to work for any angle?

