How to calculate the new $x$, and $y$ coordinates of a scaled rotated rectangle?

685 Views Asked by At

I want to scale a rotated rectangle around it's centre point and find the new $x$ and $y$ coordinates - In this diagram given I know $(x, y), \theta , w , h , nw$, and $nh$ - does anyone ideas how I calculate $(nx, ny)$?

I'm not massively familiar with vector math or vector notation so please bear with me.

Updated diagram including axis for clarification

EDIT: Sorry, I've updated the diagram to show the rotation origin is not (0,0) - it is unknown.

4

There are 4 best solutions below

3
On BEST ANSWER

This assumes the center has coordinates (0,0). The op does not specify where the origin is actually, and which way x and y point to.

Split the path to the corner into two vectors (blue and red) and take their horizontal and vertical projections

fig1

$$ \begin{aligned} x &= x_1 - x_2 \\ y & = y_1 + y_2 \\ \end{aligned} $$

I have marked the congruent angles (same measure) in order to find that

$$ \begin{aligned} x_1 & = \left( \tfrac{h}{2} \right) \sin \theta \\ y_1 & = \left( \tfrac{h}{2} \right) \cos \theta \\ x_2 & = \left( \tfrac{w}{2} \right) \cos \theta \\ y_2 & = \left( \tfrac{w}{2} \right) \sin \theta \end{aligned}$$

Now you can put it all together.

0
On

I am assuming the x- and y-axis run through the point of rotation. The rotation matrix for an angle $\theta$ is as follows:

$$\begin{bmatrix}{\cos{\theta}} & {\sin{\theta}}\\{-\sin{\theta}} & {\cos{\theta}}\end{bmatrix}$$

To rotate your x coordinates you multiply them by this matrix:

$$\begin{bmatrix}{\cos{\theta}} & {\sin{\theta}}\\{-\sin{\theta}} & {\cos{\theta}}\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix}=\begin{bmatrix}{x\cos{\theta}+y\sin{\theta}}\\{y\cos{\theta}-x\sin{\theta}}\end{bmatrix}$$

Then you just multiply them by your scaling factor n which is just $n=nw/w$:

$$x_{new}=(x\cos{\theta}+y\sin{\theta})n$$ $$y_{new}=(y\cos{\theta}-x\sin{\theta})n$$

The factor n is the same for all lengths because all lengths scale the same which is why you can just multiply by the factor you get from the ratio of nw to w (you could also use $n=nh/h$, it doesn't make a difference).

0
On

Define $\alpha = \dfrac{nw}{w} $, and $\beta = \dfrac{nh}{h} $

Attach a reference frame to the rectangle, and let its origin be the center of both rectangles $(x_0, y_0)$, then for the unscaled rectangle, the relation between coordinates with respect to the unscaled rectangle and the $xy$ plane is given by

$ r = r_0 + R(\theta) r' $

where $r = (x, y) $,$r_0 = (x_0, y_0) $ and $r' = (x', y') $ the coordinates with respect to the unscaled rectangle (in its own reference frame), and

$R(\theta) = \begin{bmatrix} \cos \theta && - \sin \theta \\ \sin \theta && \cos \theta \end{bmatrix} $

Now, apply the scale, by replacing $r'$ with $ S r' $ where

$ S= \begin{bmatrix} \alpha && 0 \\ 0 && \beta \end{bmatrix} $

Putting it all together

$r_2 = r_0 + R S ( R^T (r_1 - r_0) ) = R S R^T r_1 + (I_2 - R S R^T) r_0$

where $r_1 = (x_1, y_1) $ is the original (unscaled) point in the $xy$ plane and $r_2$ is the scaled point.

If this seems too complicated, you can simply first unrotate the rectangle by appling a negative rotation, i.e. a rotation by $(-\theta)$, then scale using $\alpha $ and $\beta$, and finally rotate again by $\theta$. And this is essentially what the equation above is stating. Let's do these three steps:

First negative rotation, this is a rotation by $(-\theta)$, so the corresponding rotation matrix is the inverse of $R(\theta)$ which is equal to the transpose of $R(\theta) $, hence the image of $r_1$ is

$ r_1' = r_0 + R^T (r_1 - r_0) $

Secondly, we'll apply scaling using the matrix $S$ where the center of scaling is $r_0$ (i.e. $r_0$ is the invariant point), then the image of $r_1' $ is

$r_1'' = r_0 + S (r_1' - r_0 ) = r_0 + S R^T (r_1 - r_0) $

Finally, we'll rotate $r_1"$ about $r_0$ by $\theta$ to bring it back. The final image is

$r_2 = r_0 + R (r_1'' - r_0) = r_0 + R S R^T (r_1 - r_0) $

And this proves the equation stated above.

2
On

ScaledRotatedRectangle

We start by drawing the line segments $AP$, $A_nP$, $AQ$, and $A_nQ$, which are parallel to $AD$, $CD$, $x$-axis, and $y$-axis respectively.

Now, we determine the lengths of the two line segments $AP$ and $A_nP$ as shown below.

$$ AP = \dfrac{\left(n-1\right)}{2}h\space$$ $$A_nP = \dfrac{\left(n-1\right)}{2}w$$

We, then, apply Pythagoras theorem to the right angled triangle $APA_n$ to obtain, $$AA_n = \dfrac{\left(n-1\right)}{2}\sqrt{h^2+w^2}.$$

Finally, we use the right angled triangle $A_nQA$ to find the lengths of the two line segments $A_nQ$ and $AQ$.

$$AQ = AA_n\cos\left(\theta\right)=\dfrac{\left(n-1\right)}{2}\sqrt{h^2+w^2}\cos\left(\theta\right)$$

$$A_nQ = AA_n\sin\left(\theta\right)=\dfrac{\left(n-1\right)}{2}\sqrt{h^2+w^2}\sin\left(\theta\right)$$

Therefore, we have, $$x_n = x - AQ = x - \dfrac{\left(n-1\right)}{2}\sqrt{h^2+w^2}\cos\left(\theta\right) \qquad\text{and}$$

$$y_n = y + A_nQ = y+ \dfrac{\left(n-1\right)}{2}\sqrt{h^2+w^2}\sin\left(\theta\right).\qquad\quad\space$$