Calculate height and width of rotated rectangle

$\begingroup$

I hope this is an easy one.

I need to calculate the new height and width of a scaled rotated rectangle.

enter image description here

I know all its corners $(A, B, C, D)$, its rotation angle ($o$) and its center ($M$). Now one corner is dragged to a new location ($C'$ in the picture). And i need to calculate the new rectangles (blue) height and width from the new corner ($C'$) and the unchanged corner ($A$).

How can i calculate these new dimensions?

Note: The y axis is in the opposite direction. And the source rectangle is rotated and translated like this:

| cos(o) sin(o) Mx |
| -sin(o) cos(o) My |
| 0 0 1 |

Thanks

$\endgroup$

1 Answer

$\begingroup$

I think a vector representation might help. Assume you scale $AD$ by a factor $k$, and $AB$ by $l$, which you need to calculate. $$\vec D'=\vec A+k(\vec D-\vec A)\\\vec B'=\vec A+l(\vec B-\vec A)\\\vec C'=\vec D'+(\vec B'-\vec A)$$So $$\vec C'-\vec A=k(\vec D-\vec A)+l(\vec B-\vec A)$$Now we know that $\vec D-\vec A$ and $\vec B-\vec A$ are perpendicular vectors. So just use scalar multiplications by the two vectors.$$(\vec C'-\vec A)\cdot(\vec D-\vec A)=k|\vec D-\vec A|^2$$and similarly for the other direction. Once you know $k$ and $l$ just multiply the original length/width by those numbers.

$\endgroup$

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like