# Thread: how to determine rotated rectangle offset

1. ## how to determine rotated rectangle offset

If you look at the attachment, I have the green box. Say the green box is 117 pixels x 18 pixels. It is then rotated around the center point 280°. How can I find the length of lines t and u? Thank you!

2. ## Re: how to determine rotated rectangle offset

First determine the radius of the circle: R = sqrt((117/2)^2+(18/2)^2) = 59.2 pixels. The point you are interested in is initially the upper left hand corner of the box, which after rotation 280 degrees clockwise ends up at the botton left. The starting point of that corner is at angle pi-arctan(18/117) relative to the center of the circle, or 171.2 degrees (note - angle measurements are measured counter-clockwise from the positive x-axis). You rotate it 280 degrees clockwise (that's -280 degrees) and it ends up at 171.3 - 280 = -108.7 degrees. The (x,y) coordinates of the point relative to the center of the cicrle is (R cos(108.7), R sin(108.7)), which is (-19.0, -56.0). The dimension 't' in your figure is R+x, or 59.2-19 = 40.2 pixels, and the dimension 'u' is equal to y, or -56.0 pixels.

4. ## Re: how to determine rotated rectangle offset

Originally Posted by ebaines
The point you are interested in is initially the upper left hand corner of the box, which after rotation 280 degrees clockwise ends up at the botton left.
the dimension 'u' is equal to y, or -56.0 pixels
To me it looks like u is the (negated) y-coordinate of the bottom right point in the last picture.

It is possible to simplify the calculations somewhat by not computing the square root and arctangent. Namely, if a point initially has coordinates (x, y), then after rotation (counterclockwise) by angle φ its coordinates will be

x' = x cos(φ) - y sin(φ)
y' = x sin(φ) + y cos(φ)

When rotated by φ clockwise, the new coordinates are

x' = x cos(φ) + y sin(φ)
y' = -x sin(φ) + y cos(φ)