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

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

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

I appreciate any help.


2 Answers 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 hereUnified frameworks of elementary geometric transformations.

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. 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'$$


$$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.


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.

  • $\begingroup$ Can we describe that in terms of matrices? $\endgroup$
    – s.ouchene
    Jan 16, 2020 at 14:55
  • $\begingroup$ Yes, a diagonal matrix with non-equal elements: $a_{ii} \ne a_{jj}, i \ne j$. $\endgroup$
    – lightxbulb
    Jan 16, 2020 at 15:19
  • $\begingroup$ @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$ $\endgroup$
    – s.ouchene
    Jan 16, 2020 at 15:23
  • $\begingroup$ 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. $\endgroup$
    – lightxbulb
    Jan 16, 2020 at 15:31
  • $\begingroup$ 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? $\endgroup$
    – s.ouchene
    Jan 16, 2020 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.