<p>The transformation is non-uniform scale - it does not preserve angles. The only reason the angles for the other shape were preserved was because the scaling was in the same direction as the edge. To get the result that you want, you either have to scale by the same amount in each direction, or just rescale the "viewing window" and not the shapes.</p>

CC BY-SA 4.0
2020-01-16T14:55:01.057Z
Can we describe that in terms of matrices?
s.ouchene
CC BY-SA 4.0
2020-01-16T15:19:30.433Z
Yes, a diagonal matrix with non-equal elements: $a_{ii} \ne a_{jj}, i \ne j$.
lightxbulb
CC BY-SA 4.0
2020-01-16T15:23:53.557Z
@I tried that but it dodn't seem to work. it looks like the eigenvalues are the stretching factors and the eigenvectors are (1, 0), (0, 1) by using diagonalization of a matrix we have $P^{-1} D P$
s.ouchene
CC BY-SA 4.0
2020-01-16T15:31:36.363Z
You tried what? The normalized eigenvectors of a 2x2 diagonal matrix are indeed $(1,0), (0,1)$, what's the issue there? And the scaling factors are the eigenvalues. I don't get what your issue with that is, it's a non-uniform matrix as I said. The initial image didn't have its angles changed, because the rectangle's edges are parallel to the eigenvectors. If you had a circle initially, you would have gotten an ellipse stretched along the $Y$ axis.
lightxbulb
CC BY-SA 4.0
2020-01-16T15:40:40.487Z
I mean I tried to multiply the rotated shape with multiple scaling matrices but that didn't seems to work at all. What do you mean exactly the matrix is not uniform?
s.ouchene
CC BY-SA 4.0
2020-01-16T15:59:47.540Z
Non-uniform scale matrix $a_{ii} \ne a_{jj}, i \ne j$, zero everywhere else. Assume that your image was stretched along $Y$ by a factor of $2$, then you have to rescale your rectangle by a factor of $0.5$ along $Y$ if you want it to keep its size, but this will change to which $Y$ it corresponds to on the measure bar on the left. Example matrix:
$$M(1,0; 0, 0.5)$$
Note, you have to know what the image was rescaled with, in order to put the correct value in $a_{22}$.
lightxbulb
CC BY-SA 4.0
2020-01-16T16:31:34.483Z
Could we find the stretching factors from the image sizes? I mean by cropping the image to the outer black rectangle of the figure.
s.ouchene
CC BY-SA 4.0
2020-01-16T16:48:04.067Z
@Navaro Not necessarily - the margins and scaling may be different. If this was generated by matplotlib then there's probably a way to retrieve that information from it, or even make it work like you want through some option. I cannot help you further though, since I am not that well-versed in matplotlib anyways.
lightxbulb
CC BY-SA 4.0
2020-01-16T18:39:47.513Z
Are you familiar with Matlab?
s.ouchene
CC BY-SA 4.0
2020-01-16T19:24:38.660Z
@Navaro Not enough to help you with that.
lightxbulb
CC BY-SA 4.0
2020-01-16T19:55:10.257Z
Thank you. I have asked this question several times but didn't get an answer.
s.ouchene
CC BY-SA 4.0
2020-01-17T04:07:11.460Z
@Navaro A simple solution is rather than stretch your image, allow different bounds for your axes.
lightxbulb
CC BY-SA 4.0
2020-01-16T14:49:16.780Z
2020-01-16T14:49:16.780Z
lightxbulb
<p>Let's talk about linear geometric transformations in homogeneous coordinates.  In your question there are mainly two kind of geometric transformations involved: planar rotation and planar scaling, the computation-friendly analytical re-definitions of which are found here<a href="https://arxiv.org/abs/1307.0998" rel="nofollow noreferrer">Unified frameworks of elementary geometric transformations</a>.</p>

<p>The 2D homogenous rotation matrix that rotates 2D objects clockwise by <span class="math-container">$\theta$</span> radians is as below:</p>

<p><span class="math-container">$$R=\left[
\begin{array}{ccc}
 \cos \theta &amp; \sin \theta&amp; 0 \\
 -\sin\theta &amp; \cos\theta &amp; 0 \\
 0 &amp; 0 &amp; 1 \\
\end{array}
\right]$$</span></p>

<p>A 2D scaling due to unequal aspect ratio <span class="math-container">$\rho$</span> in this case is a stereohomology with <span class="math-container">$x$</span> axis <span class="math-container">$(0,1,0)^T$</span> as the stereohomology interface (a line of invariant points), and the normal direction <span class="math-container">$(0,1,0)^T$</span> as its stereohomology center per definition 3.9 in page 12 and line No. 5 in Table 1, page 9 of the article <a href="https://arxiv.org/abs/1307.0998" rel="nofollow noreferrer">Unified frameworks of elementary geometric transformations</a>. Then its scaling matrix can be obtained as below:</p>

<p><span class="math-container">$$S=\color{gray}{\left[
\begin{array}{ccc}
 1 &amp; 0 &amp; 0 \\
 0 &amp; 1 &amp; 0 \\
 0 &amp; 0 &amp; 1 \\
\end{array}
\right]+\left(\rho-1\right)\dfrac{\left[
\begin{array}{c}
 0 \\
 1 \\
 0 \\
\end{array}
\right]\cdot \left[
\begin{array}{ccc}
 0 &amp; 1 &amp; 0 \\
\end{array}
\right]}{\left[
\begin{array}{ccc}
 0 &amp; 1 &amp; 0 \\
\end{array}
\right]\cdot \left[
\begin{array}{c}
 0 \\
 1 \\
 0 \\
\end{array}
\right]}=}\left[
\begin{array}{ccc}
 1 &amp; 0 &amp; 0 \\
 0 &amp; \rho  &amp; 0 \\
 0 &amp; 0 &amp; 1 \\
\end{array}
\right]$$</span></p>

<p>When aspect ratio normally is <span class="math-container">$\rho=1$</span>, suppose under this circumstance the original object has the homogeneous coordinates of <span class="math-container">$n$</span> points in <span class="math-container">$3\times n$</span> matrix <span class="math-container">$X$</span>, and the transformed object in <span class="math-container">$3\times n$</span> matrix <span class="math-container">$Y$</span>, then the geometric transformation between them is the rotation you have mentioned:</p>

<p><span class="math-container">$$Y=R\cdot X$$</span></p>

<p>When the aspect ratio abnormally is <span class="math-container">$\rho\ne 1$</span>, both <span class="math-container">$X$</span> and the <span class="math-container">$Y$</span> after rotation are as a matter of fact scaled along the <span class="math-container">$y$</span> axis:</p>

<p><span class="math-container">$$X'=S\cdot X$$</span>
<span class="math-container">$$Y'=S\cdot Y$$</span></p>

<p>Now you want to find the geometric transformation <span class="math-container">$T$</span>  which satisfies <span class="math-container">$Y'=T\cdot X'$</span>. Since:</p>

<p><span class="math-container">$$Y'=S\cdot Y=S\cdot R\cdot X =S\cdot R\cdot S^{-1}\cdot X'$$</span></p>

<p>then</p>

<p><span class="math-container">$$T=S\cdot R\cdot S^{-1}$$</span> 
<span class="math-container">$$=\color{gray}{\left[
\begin{array}{ccc}
 1 &amp; 0 &amp; 0 \\
 0 &amp; \rho  &amp; 0 \\
 0 &amp; 0 &amp; 1 \\
\end{array}
\right]
\cdot
\left[
\begin{array}{ccc}
 \cos \theta &amp; \sin \theta&amp; 0 \\
 -\sin\theta &amp; \cos\theta &amp; 0 \\
 0 &amp; 0 &amp; 1 \\
\end{array}
\right]\cdot
\left[
\begin{array}{ccc}
 1 &amp; 0 &amp; 0 \\
 0 &amp; \dfrac{1}\rho  &amp; 0 \\
 0 &amp; 0 &amp; 1 \\
\end{array}
\right]=}\left[
\begin{array}{ccc}
 \cos \theta &amp; \dfrac{\sin \theta}{\rho } &amp; 0 \\
 -\rho  \sin\theta &amp; \cos \theta&amp; 0 \\
 0 &amp; 0 &amp; 1 \\
\end{array}
\right]$$</span></p>

<p>It is a rotation under the generalized meaning.</p>

CC BY-SA 4.0
2020-02-15T10:14:56.777Z
2020-02-15T10:22:00.643Z
2020-02-15T10:22:00.643Z
user106688
<p>I have a geometric shape (assuming that is a rectangle). I want to rotate it about it geometric center by an angle of 45° and plot the result using matplotlib with an equal aspect ratio, I get something like this:</p>
<p><a href="https://i.sstatic.net/iXe7B.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/iXe7B.png" alt="enter image description here" /></a></p>
<p>However for some reason, I want to plot the result in a figure with a non-equal aspect, I am getting this result:</p>
<p><a href="https://i.sstatic.net/3V3VD.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3V3VD.png" alt="enter image description here" /></a></p>
<p>As you can see, the rotated shape is deformed (skewed). But the original shape seems to be scaled only in the y direction.</p>
<p>I am trying to understand what kind of transformation is occuring to the orange shape from a linear algebra perspective: Is it a shear? a combination of scaling and shear (Affine transformation)? if not what kind of transformation is that?</p>
<p>My goal is to identify the type of transformation, then finding it's inverse to get the following result:</p>
<p><a href="https://i.sstatic.net/yhn2Z.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/yhn2Z.png" alt="enter image description here" /></a></p>
<p>I appreciate any help.</p>

<transformations><affine-transformations>
What kind of transformation when the aspect is changed for a rotated shape?
s.ouchene
# What kind of transformation when the aspect is changed for a rotated shape?

(Asked by: username_0 on 2020-01-16)

I have a geometric shape (assuming that is a rectangle). I want to rotate it about it geometric center by an angle of 45° and plot the result using matplotlib with an equal aspect ratio, I get something like this:

[![enter image description here](https://i.sstatic.net/iXe7B.png)](https://i.sstatic.net/iXe7B.png)

However for some reason, I want to plot the result in a figure with a non-equal aspect, I am getting this result:

[![enter image description here](https://i.sstatic.net/3V3VD.png)](https://i.sstatic.net/3V3VD.png)

As you can see, the rotated shape is deformed (skewed). But the original shape seems to be scaled only in the y direction.

I am trying to understand what kind of transformation is occuring to the orange shape from a linear algebra perspective: Is it a shear? a combination of scaling and shear (Affine transformation)? if not what kind of transformation is that?

My goal is to identify the type of transformation, then finding it's inverse to get the following result:

[![enter image description here](https://i.sstatic.net/yhn2Z.png)](https://i.sstatic.net/yhn2Z.png)

I appreciate any help.

**Tags:** transformations, affine-transformations


---

## 2 answers

### Answer by username_2 on 2020-02-15. Score: 2

Let's talk about linear geometric transformations in homogeneous coordinates. In your question there are mainly two kind of geometric transformations involved: planar rotation and planar scaling, the computation-friendly analytical re-definitions of which are found here[Unified frameworks of elementary geometric transformations](https://arxiv.org/abs/1307.0998).

The 2D homogenous rotation matrix that rotates 2D objects clockwise by $\theta$ radians is as below:

$$R=\left[
\begin{array}{ccc}
\cos \theta & \sin \theta& 0 \\
-\sin\theta & \cos\theta & 0 \\
0 & 0 & 1 \\
\end{array}
\right]$$

A 2D scaling due to unequal aspect ratio $\rho$ in this case is a stereohomology with $x$ axis $(0,1,0)^T$ as the stereohomology interface (a line of invariant points), and the normal direction $(0,1,0)^T$ as its stereohomology center per definition 3.9 in page 12 and line No. 5 in Table 1, page 9 of the article [Unified frameworks of elementary geometric transformations](https://arxiv.org/abs/1307.0998). Then its scaling matrix can be obtained as below:

$$S=\color{gray}{\left[
\begin{array}{ccc}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
\end{array}
\right]+\left(\rho-1\right)\dfrac{\left[
\begin{array}{c}
0 \\
1 \\
0 \\
\end{array}
\right]\cdot \left[
\begin{array}{ccc}
0 & 1 & 0 \\
\end{array}
\right]}{\left[
\begin{array}{ccc}
0 & 1 & 0 \\
\end{array}
\right]\cdot \left[
\begin{array}{c}
0 \\
1 \\
0 \\
\end{array}
\right]}=}\left[
\begin{array}{ccc}
1 & 0 & 0 \\
0 & \rho & 0 \\
0 & 0 & 1 \\
\end{array}
\right]$$

When aspect ratio normally is $\rho=1$, suppose under this circumstance the original object has the homogeneous coordinates of $n$ points in $3\times n$ matrix $X$, and the transformed object in $3\times n$ matrix $Y$, then the geometric transformation between them is the rotation you have mentioned:

$$Y=R\cdot X$$

When the aspect ratio abnormally is $\rho\ne 1$, both $X$ and the $Y$ after rotation are as a matter of fact scaled along the $y$ axis:

$$X'=S\cdot X$$
$$Y'=S\cdot Y$$

Now you want to find the geometric transformation $T$ which satisfies $Y'=T\cdot X'$. Since:

$$Y'=S\cdot Y=S\cdot R\cdot X =S\cdot R\cdot S^{-1}\cdot X'$$

then

$$T=S\cdot R\cdot S^{-1}$$
$$=\color{gray}{\left[
\begin{array}{ccc}
1 & 0 & 0 \\
0 & \rho & 0 \\
0 & 0 & 1 \\
\end{array}
\right]
\cdot
\left[
\begin{array}{ccc}
\cos \theta & \sin \theta& 0 \\
-\sin\theta & \cos\theta & 0 \\
0 & 0 & 1 \\
\end{array}
\right]\cdot
\left[
\begin{array}{ccc}
1 & 0 & 0 \\
0 & \dfrac{1}\rho & 0 \\
0 & 0 & 1 \\
\end{array}
\right]=}\left[
\begin{array}{ccc}
\cos \theta & \dfrac{\sin \theta}{\rho } & 0 \\
-\rho \sin\theta & \cos \theta& 0 \\
0 & 0 & 1 \\
\end{array}
\right]$$

It is a rotation under the generalized meaning.


---

### Answer by username_1 on 2020-01-16. Score: 0

The transformation is non-uniform scale - it does not preserve angles. The only reason the angles for the other shape were preserved was because the scaling was in the same direction as the edge. To get the result that you want, you either have to scale by the same amount in each direction, or just rescale the "viewing window" and not the shapes.

> **Comments:**
> **username_0**: Can we describe that in terms of matrices?  
> **username_1**: Yes, a diagonal matrix with non-equal elements: $a_{ii} \ne a_{jj}, i \ne j$.  
> **username_0**: @I tried that but it dodn't seem to work. it looks like the eigenvalues are the stretching factors and the eigenvectors are (1, 0), (0, 1) by using diagonalization of a matrix we have $P^{-1} D P$  
> **username_1**: You tried what? The normalized eigenvectors of a 2x2 diagonal matrix are indeed $(1,0), (0,1)$, what's the issue there? And the scaling factors are the eigenvalues. I don't get what your issue with that is, it's a non-uniform matrix as I said. The initial image didn't have its angles changed, because the rectangle's edges are parallel to the eigenvectors. If you had a circle initially, you would have gotten an ellipse stretched along the $Y$ axis.  
> **username_0**: I mean I tried to multiply the rotated shape with multiple scaling matrices but that didn't seems to work at all. What do you mean exactly the matrix is not uniform?  
> **username_1**: Non-uniform scale matrix $a_{ii} \ne a_{jj}, i \ne j$, zero everywhere else. Assume that your image was stretched along $Y$ by a factor of $2$, then you have to rescale your rectangle by a factor of $0.5$ along $Y$ if you want it to keep its size, but this will change to which $Y$ it corresponds to on the measure bar on the left. Example matrix: $$M(1,0; 0, 0.5)$$ Note, you have to know what the image was rescaled with, in order to put the correct value in $a_{22}$.  
> **username_0**: Could we find the stretching factors from the image sizes? I mean by cropping the image to the outer black rectangle of the figure.  
> **username_1**: @Navaro Not necessarily - the margins and scaling may be different. If this was generated by matplotlib then there's probably a way to retrieve that information from it, or even make it work like you want through some option. I cannot help you further though, since I am not that well-versed in matplotlib anyways.  
> **username_0**: Are you familiar with Matlab?  
> **username_1**: @Navaro Not enough to help you with that.  
> **username_0**: Thank you. I have asked this question several times but didn't get an answer.  
> **username_1**: @Navaro A simple solution is rather than stretch your image, allow different bounds for your axes.  

---

