Properties of ellipses by matrix coefficients – I – Two defining matrices

This post requires Javascript to display formulas!

For my two current post series on multivariate normal distributions [MNDs] and on shear operations

Multivariate Normal Distributions – II – random vectors and their covariance matrix
Fun with shear operations and SVD

some geometrical and algebraic properties of ellipses are of interest. Geometrically, we think of an ellipse in terms of their perpendicular two principal axes, focal points, ellipticity and rotation angles with respect to a coordinate system. As elliptic data appear in many contexts of physics, chaos theory, engineering, optics … ellipses are well studied mathematical objects. So, why a post about ellipses in the Machine Learning section of a blog?

In my present working context ellipses appear as a side result of statistical multivariate normal distributions [MNDs]. The projections of multidimensional contour hyper-surfaces of a MND within the ℝn onto coordinate planes of an Euclidean Coordinate System [ECS] result in 2-dimensional ellipses. These ellipses are typically rotated against the axes of the ECS – and their rotation angles reflect data correlations. The general relations of statistical vector data with projections of multidimensional MNDs is somewhat intricate.

Data produced in numerical experiments, e.g. in a Machine Learning context, most often do not give you the geometrical properties of ellipses, which some theory may have predicted, directly. Instead you may get averaged values of statistical vector distributions which correspond to a kind of algebraic coefficients. These coefficients can often be regarded as elements of a matrix. The mathematical reason is that ellipses can in general be defined by matrices operating on position vectors. In particular: Coefficients of quadratic polynomial expressions used to describe ellipses as conic sections correspond to the coefficients of a matrix operating on position vectors.

So, when I became confronted with multidimensional MNDs and their projections on coordinate planes the following questions became interesting:

  • How can one derive the lengths σ1, σ2 of the perpendicular principal axes of an ellipse from data for the coefficients of a matrix which defines the ellipse by a polynomial expression?
  • By which formula do the matrix coefficients provide the inclination angle of the ellipse’s primary axes with the x-axis of a chosen coordinate system?

You may have to dig a bit to find correct and reproducible answers in your math books. Regarding the resulting mathematical expressions I have had some bad experiences with ChatGPT. But as a former physicist I take the above questions as a welcome exercise in solving quadratic equations and doing some linear algebra. So, for those of my readers who are a bit interested in elementary math I want to answer the posed questions step by step and indicate how one can derive the respective formulas. The level is moderate – you need some knowledge in trigonometry and/or linear algebra.

Centered ellipses and two related matrices

Below I regard ellipses whose centers coincide with the origin of a chosen ECS. For our present purpose we thus get rid of some boring linear terms in the equations we have to solve. We do not loose much of general validity by this step: Results of an off-center ellipse follow from applying a simple translation operation to the resulting vector data. But I admit: Your (statistical) data must give you some information about the center of your ellipse. We assume that this is the case.

Our ellipses can, however, be rotated with respect to a chosen ECS. I.e., their longer principal axes may be inclined by some angle φ towards the x-axis of our ECS.

There are actually two different ways to define a centered ellipse by a matrix:

  • Alternative 1: We define the (rotated) ellipse by a matrix AE which results from the (matrix) product of two simpler matrices: AE = RφDσ1, σ2. Dσ1, σ2 corresponds to a scaling operation applied to position vectors for points located on a centered unit circle. Aφ describes a subsequent rotation. AE summarizes these geometrical operations in a compact form.
  • Alternative 2: We define the (rotated) ellipse by a matrix Aq which combines the x- and y-elements of position vectors in a polynomial equation with quadratic terms in the components (see below). The matrix defines a so called quadratic form. Geometrically interpreted, a quadratic form describes an ellipse as a special case of a conic section. The coefficients of the polynomial and the matrix must, of course, fulfill some particular properties.

While it is relatively simple to derive the matrix elements from known values for σ1, σ2 and φ it is a bit harder to derive the ellipse’s properties from the elements of either of the two defining matrices. I will cover both matrices in this post. For many practical purposes the derivation of central elliptic properties from given elements of Aq is more relevant and thus of special interest in the following discussion.

Matrix AE of a centered and rotated ellipse: Scaling of a unit circle followed by a rotation

Our starting point is a unit circle C whose center coincides with our ECS’s origin. The components of vectors vc to points on the circle C fulfill the following conditions:

\[
\pmb{C} \::\: \left\{ \pmb{v}_c \:=\: \begin{pmatrix} x_c \\ y_c \end{pmatrix} \:=\: \begin{pmatrix} \operatorname{cos}(\psi) \\ \operatorname{sin}(\psi) \end{pmatrix}, \quad 0\,\leq\,\psi\, \le 2\pi \right\}
\]

and

\[
x_c^2 \, +\, y_c^2 \,=\; 1
\]

We define an ellipse E1, σ2) by the application of two linear operations to the vectors of the unit circle:

\[
\pmb{E}_{\sigma_1, \, \sigma_2} \::\: \left\{ \, \pmb{v}_e \:=\: \begin{pmatrix} x_e \\ y_e \end{pmatrix} \:=\: \pmb{\operatorname{R}}_{\phi} \circ \pmb{\operatorname{D}}_E \circ \pmb{v_c} , \quad \pmb{v_c} \in \pmb{C} \, \right\}
\]

DE is a diagonal matrix which describes a stretching of the circle along the ECS-axes, and Rφ is an orthogonal rotation matrix. The stretching (or scaling) of the vector-components is done by

\[
\pmb{\operatorname{D}}_E \:=\: \begin{pmatrix} \sigma_1 & 0 \\ 0 & \sigma_2 \end{pmatrix},
\]
\[
\pmb{\operatorname{D}}_E^{-1} \:=\: \begin{pmatrix} {1 \over \sigma_1} & 0 \\ 0 & {1 \over \sigma_2} \end{pmatrix},
\]

The coefficients σ1, σ2 obviously define the lengths of the principal axes of the yet unrotated ellipse. To be more precise: σ1 is half of the diameter in x-direction, σ1 is half of the diameter in y-direction.

The subsequent rotation by an angle φ against the x-axis of the ECS is done by

\[
\pmb{\operatorname{R}}_{\phi} \:=\:
\begin{pmatrix} \operatorname{cos}(\phi) & – \,\operatorname{sin}(\phi) \\ \operatorname{sin}(\phi) & \operatorname{cos}(\phi)\end{pmatrix}
\:=\: \begin{pmatrix} u_1 & -\,u_2 \\ u_2 & u_1 \end{pmatrix}
\]
\[
\pmb{\operatorname{R}}_{\phi}^T \:=\: \pmb{\operatorname{R}}_{\phi}^{-1} \:=\: \pmb{\operatorname{R}}_{-\,\phi}
\]

The combined linear transformation results in a matrix AE with coefficients ((a, b), (c, d)):

\[ \begin{align}
\pmb{\operatorname{A}}_E \:=\: \pmb{\operatorname{R}}_{\phi} \circ \pmb{\operatorname{D}}_E \:=\:
\begin{pmatrix} \sigma_1\,u_1 & -\,\sigma_2\,u_2 \\ \sigma_1\,u_2 & \sigma_2\,u_1 \end{pmatrix} \:=\:: \begin{pmatrix} a & b \\ c & d \end{pmatrix}
\end{align}
\]

These is the first set of matrix coefficients we are interested in.

Note:

\[ \pmb{\operatorname{A}}_E^{-1} \:=\:
\begin{pmatrix} {1 \over \sigma_1} \,u_1 & {1 \over \sigma_1}\,u_2 \\ -{1 \over \sigma_2}\,u_2 & {1 \over \sigma_2}\,u_1 \end{pmatrix}
\]
\[
\pmb{v}_e \:=\: \begin{pmatrix} x_e \\ y_e \end{pmatrix} \:=\: \pmb{\operatorname{A}}_E \circ \begin{pmatrix} x_c \\ y_c \end{pmatrix}
\]
\[
\pmb{v}_k \:=\: \begin{pmatrix} x_c \\ y_c \end{pmatrix} \:=\: \pmb{\operatorname{A}}_E^{-1} \circ \begin{pmatrix} x_e \\ y_e \end{pmatrix}
\]

We use

\[ \begin{align}
u_1 \,&=\, \operatorname{cos}(\phi),\quad u_2 \,=\,\operatorname{sin}(\phi), \quad u_1^2 \,+\, u_2^2 \,=\, 1 \\
\lambda_1 \,&: =\, \sigma_1^2, \quad\quad \lambda_2 \,: =\, \sigma_2^2
\end{align}
\]

and find

\[ \begin{align}
a \,&=\, \sigma_1\,u_1, \quad b \,=\, -\, \sigma_2\,u_2, \\
c \,&=\, \sigma_1\,u_2, \quad d \,=\, \sigma_2\,u_1
\end{align}
\]
\[
\operatorname{det}\left( \pmb{\operatorname{A}}_E \right) \:=\: a\,d \,-\, b\,c \:=\: \sigma_1\, \sigma_2
\]

σ1 and σ2 are factors which give us the lengths of the principal axes of the ellipse. σ1 and σ2 have positive values. We therefore demand:

\[
\operatorname{det}\left( \pmb{\operatorname{A}}_E \right) \:=\: a\,d \,-\, b\,c \:\ge\: 0
\]

Ok, we have defined an ellipse via a matrix AE, whose coefficients are directly based on geometrical properties. But as said: Often an ellipse is described by a an equation with quadratic terms in x and y coordinates of data points. The quadratic form has its background in algebraic properties of conic sections. As a next step we derive such a quadratic equation and relate the coefficients of the quadratic polynomial with the elements of our matrix AE. The result will in turn define another very useful matrix Aq.

Quadratic forms – Case 1: Centered ellipse, principal axes aligned with ECS-axes

We start with a simple case. We take a so called axis-parallel ellipse which results from a scaling matrix DE, only. I.e., in this case, the rotation matrix is assumed to be just the identity matrix. We can omit it from further calculations:

\[
\pmb{\operatorname{R}}_{\phi} \:=\:
\begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} \,=\, \pmb{\operatorname{I}}, \quad u_1 \,=\, 1,\: u_2 \,=\, 0, \: \phi = 0
\]

We need an expression in terms of (xe, ye). To get quadratic terms of vector components it often helps to invoke a scalar product. The scalar product of a vector with itself gives us the squared norm or length of a vector. In our case the norms of the inversely re-scaled vectors obviously have to fulfill:

\[
\left[\, \pmb{\operatorname{D}}_E^{-1} \circ \begin{pmatrix} x_e \\ y_e \end{pmatrix} \, \right]^T \,\bullet \, \left[\, \pmb{\operatorname{D}}_E^{-1} \circ \begin{pmatrix} x_e \\ y_e \end{pmatrix} \,\right] \:=\: 1
\]

(The bullet represents the scalar product of the vectors.) This directly results in:

\[
{1 \over \sigma_1^2} x_e^2 \, + \, {1 \over \sigma_2^2} y_e^2 \:=\: 1
\]

We eliminate the denominator to get a convenient quadratic form:

\[
\lambda_2\,x_e^2 \,+\, \lambda_1\, y_e^2 \:=\: \lambda_1 \lambda_2 \quad \left( = \, \operatorname{det}\left(\pmb{\operatorname{D}}_E\right) \right) \phantom{\huge{(}}
\]

If we were given the quadratic form more generally by coefficients α, β and γ

\[
\alpha \,x_e^2 \,+\, \beta\, x_e y_e \,+\, \gamma\, y_e^2 \:=\: \delta
\]

we could directly relate these coefficients with the geometrical properties of our ellipse:

Axis-parallel ellipse:

\[ \begin{align}
\alpha \,&=\, c^2 \,=\, \sigma_2^2 \,=\, \lambda_2 \\
\gamma \,&=\, a^2 \,=\, \sigma_1^2 \,=\, \lambda_1 \\
\beta \,&=\, b \,=\, c \,=\, 0 \\
\delta \,&=\, a^2\, d^2 \,=\, \sigma_1^2 \, \sigma_2^2 \,=\, \lambda_1 \lambda_2 \\
\phi &= 0
\end{align}
\]

I.e., we can directly derive σ1, σ2 and φ from the coefficients of the quadratic form. But an axis-parallel ellipse is a very simple ellipse. Things get more difficult for a rotated ellipse.

Quadratic forms – Case 2: General centered and rotated ellipse

We perform the same trick to get a quadratic polynomial with the vectors ve of a rotated ellipse:

\[
\left[ \,\pmb{\operatorname{A}}_E^{-1} \circ \begin{pmatrix} x_e \\ y_e \end{pmatrix} \, \right]^T \, \bullet \,
\left[ \, \pmb{\operatorname{A}}_E^{-1} \circ \begin{pmatrix} x_e \\ y_e \end{pmatrix} \,\right] \:=\: 1
\]

I skip the lengthy, but simple algebraic calculation. We get (with our matrix elements a, b, c, d):

\[
\left( c^2 \,+\, d^2 \right)\,x_e^2 \,\, – \,\, 2\left( a\,c\, +\, b\,d \right)\,x_e y_e \,\, + \,\, \left(a^2 \,+\, b^2\right)\,y_e^2
\:=\: \sigma_1^2 \, \sigma_2^2
\]

The rotation has obviously lead to mixing of components in the polynomial. The coefficient for xeye is > 0 for the non-trivial case.

Quadratic form: A matrix equation to define an ellipse

We rewrite our equation again with general coefficients α, β and γ

\[
\alpha\,x_e^2 \, + \, \beta \, x_e y_e \, + \, \gamma \, y_e^2 \:=\: \delta
\]

These are coefficients which may come from some theory or from averages of numerical data. The quadratic polynomial can in turn be reformulated as a matrix operation with a symmetric matrix Aq:

\[
\pmb{v}_e^T \circ \pmb{\operatorname{A}}_q \circ \pmb{v}_e^T \:=\: \delta
\]

with

\[ \pmb{\operatorname{A}}_q \:=\:
\begin{pmatrix} \alpha & \beta / 2 \\ \beta / 2 & \gamma \end{pmatrix}
\]
\[ \pmb{\operatorname{A}}_q \:=\:
\begin{pmatrix} c^2 \,+\, d^2 & a\,c \, +\, b\,d \\ a\,c \, +\, b\,d & a^2 \,+\, b^2 \end{pmatrix}
\]
\[ \begin{align}
\alpha \:&=\: c^2 \,+\, d^2 \:=\: \sigma_1^2 u_2^2 \, + \, \sigma_2^2 u_1^2 \\
\gamma \:&=\: a^2 \,+\, b^2 \:=\: \sigma_1^2 u_1^2 \, + \, \sigma_2^2 u_2^2 \\
\beta \:&=\: – 2\left(a c \,+\, b d \right) \:=\: -2 \left( \sigma_1^2 u_1 u_2 \, + \, \sigma_2^2 u_1 u_2 \right) \\
\delta \:&=\: \left(ad \,-\, bc\right)^2 \:=\: \sigma_1^2 \, \sigma_2^2
\end{align}
\]

Note also:

\[ \begin{align}
\alpha \,+\, \gamma \:&=\: a^2 \,+\, b^2 \,+\, c^2 \,+\, d^2 \:=\: \sigma_1^2 \, + \, \sigma_2^2 \\
\alpha \,-\, \gamma \:&=\: a^2 \,+\, b^2 \,-\, c^2 \,-\, d^2 \:=\: \sigma_1^2 \, \operatorname{cos}\left(2\phi\right) \, + \, \sigma_2^2 \, \operatorname{cos}\left(2\phi\right) \end{align}
\]

These terms are intimately related to the geometrical data; expect them to play a major role in further considerations.

With the help of the coefficients of AE we can also show that det(Aq) > 0:

\[
\operatorname{det}\left( \pmb{\operatorname{A}}_q \right) \:=\: \left(\alpha\gamma \,-\, {1\over 4}\beta^2\right) \:=\: \left(bc \,-\, ad\right)^2 \, \ge \, 0
\]

Thus Aq is an invertible matrix (as was to be expected).

Above we have got α, β, γ, δ as some relatively simple functions of a, b, c, d. The inversion is not so trivial and we do not even try it here. Instead we focus on how we can express σ1, σ2 and φ as functions of either (a, b, c, d) or (α, β, γ, δ).

How to derive σ1, σ2 and φ from the coefficients of AE or Aq in the general case?

Let us assume we have (numerical) data for the coefficients of the quadratic form. Then we may want to calculate values for the length of the principal axes and the rotation angle φ of the corresponding ellipse. There are two ways to derive respective formulas:

  • Approach 1: Use trigonometric relations to directly solve the equation system.
  • Approach 2: Use an eigenvector decomposition of Aq.

Both ways are fun!

Direct derivation of σ1, σ2 and φ by using trigonometric relations

We start with the hard tour, namely by solving equations for λ1, λ2 and φ directly. This requires some knowledge in trigonometry. So far, we know the following:

\[ \begin{align}
\gamma \:&=\: a^2 \,+\, b^2 \:=\: \lambda_1 \operatorname{cos}^2\phi \, + \, \lambda_2 \operatorname{sin}^2\phi \\
\alpha \:&=\: c^2 \,+\, d^2 \:=\: \lambda_2 \operatorname{sin}^2\phi \, + \, \lambda_2 \operatorname{cos}^2\phi \\
\beta \:&=\: – 2\left(a c \,+\, b d \right) \:=\: -2 \left( \lambda_1 \,-\, \lambda_2 \right) \operatorname{cos}\phi \, \operatorname{sin}\phi \\
\delta \:&=\: \lambda_1 \, \lambda_2
\end{align}
\]

Trigonometric relations which we can use are:

\[ \begin{align}
\operatorname{sin}(2 \phi) \:&=\: 2 \,\operatorname{cos}(\phi)\, \operatorname{sin}(\phi) \\
\operatorname{cos}(2 \phi) \:&=\: 2 \,\operatorname{cos}^2(\phi)\, -\, 1 \\
\:&=\: 1 \,-\, 2\,\operatorname{sin}^2(\phi) \\
\:&=\: \operatorname{cos}^2(\phi)\, -\, \operatorname{sin}^2(\phi)
\end{align}
\]

Without loosing generality we assume

\[
\lambda_1 \:\ge \lambda_2
\]

In the end results would only differ by a rotation of π/2, if we had chosen otherwise. This leads to

\[ \begin{align}
2 \gamma \:&=\: 2\left( a^2 \,+\, b^2 \right) \:=\: \lambda_1 \left( 1 \,+\, \operatorname{cos}(2\phi) \right) \, + \,
\lambda_2 \left( 1 \,-\, \operatorname{cos}(2\phi) \right) \\
2 \alpha \:&=\: 2 \left( c^2 \,+\, d^2 \right) \:=\: \lambda_1 \left( 1 \,-\, \operatorname{cos}(2\phi) \right) \, + \,
\lambda_2 \left( 1 \,+\, \operatorname{cos}(2\phi) \right) \\
– \beta \:&=\: 2 \left(a c \,+\, b d \right) \:=\: \left( \lambda_1 \,-\, \lambda_2 \right) \operatorname{sin}(2\phi)
\end{align}
\]

We rearrange terms and get:

\[ \begin{align}
\left( \lambda_1 \,-\, \lambda_2 \right) \operatorname{cos}(2\phi) \,+\, \lambda_1 \,+\, \lambda_2 \:&=\: 2 \left( a^2 \,+\, b^2 \right) \\
\left( \lambda_1 \,-\, \lambda_2 \right) \operatorname{cos}(2\phi) \,-\, \lambda_1 \,-\, \lambda_2 \:&=\: – 2 \left( c^2 \,+\, d^2 \right) \\
\left( \lambda_1 \,-\, \lambda_2 \right) \operatorname{sin}(2\phi) \:&=\: 2 \left( a\,c \,+\, b\,d \right)
\end{align}
\]

Let us define some further variables before we add and subtract the first two of the above equations:

\[ \begin{align}
r \:&=\: {1 \over 2} \left( a^2 \,+\, b^2 \,+\, c^2 \,+\, d^2 \right) \:=\: {1 \over 2} \left( \gamma \,+\, \alpha \right) \\
s_1 \:&=\: {1 \over 2} \left( a^2 \,+\, b^2 \,-\, c^2 \,-\, d^2 \right) \:=\: {1 \over 2} \left( \gamma \,-\, \alpha \right) \\
s_2 \:&=\: \left( a\,c \,+\, b\,d \right) \:=\: – {1 \over 2} \, \beta \\
\pmb{s} \:&=\: \begin{pmatrix} s_1 \\ s_2 \end{pmatrix} \:=\: {1 \over 2} \begin{pmatrix} \gamma \,-\, \alpha \\ – \beta \end{pmatrix} \phantom{\Huge{(}} \\
s \:&=\: \sqrt{ s_1^2 \,+\, s_2^2 } \:=\: {1 \over 2} \left[ \, \beta^2 \,+\, \left( \gamma \,-\, \alpha \right)^2 \,\right]^{1/2} \phantom{\huge{(}}
\end{align}
\]

Then adding two of the equations with the sin2φ and cos2φ above and using the third one results in:

\[
{1 \over 2} \left( \lambda_1 \,-\, \lambda_2 \right) \begin{pmatrix} \operatorname{cos}(2\phi) \\ \operatorname{sin}(2\phi) \end{pmatrix} \:=\: \begin{pmatrix} s_1 \\ s_2 \end{pmatrix}
\]

Taking the vector norm on both sides (with λ1 ≥ λ2) and adding two of the equations above results in:

\[ \begin{align}
\lambda_1 \,\, – \,\, \lambda_2 \:&=\: 2 s \:\:=\: \left[ \, \beta^2 \,+\, \left( \gamma \,-\, \alpha \right) \,\right]^{1/2} \\
\lambda_1 \, + \, \lambda_2 \:&=\: 2 r \:\:=\: \gamma \,+\, \alpha
\end{align}
\]

This gives us:

\[ \begin{align}
\sigma_1^2 \,=\, \lambda_1 \:&=\: r \,+\, s \\
\sigma_2^2 \,=\, \lambda_2 \:&=\: r \,-\, s
\end{align}
\]

In terms of a, b, c, d:

\[ \begin{align}
\sigma_1^2 \,=\, \lambda_1 \:&=\: {1 \over 2} \left[ \, a^2+b^2+c^2 +d^2 \,+\, \left[ 4 (ac + bd)^2 \, +\, \left( c^2+d^2 -a^2 -b^2\right)^2 \, \right]^{1/2} \right] \\
\sigma_2^2 \,=\, \lambda_2 \:&=\: {1 \over 2} \left[ \, a^2+b^2+c^2 +d^2 \,-\, \left[ 4 (ac + bd)^2 \, +\, \left( c^2+d^2 -a^2 -b^2\right)^2 \, \right]^{1/2} \right]
\end{align}
\]

Who said that life has to be easy? In terms of α, β, γ, δ it looks a bit better:

\[ \begin{align}
\sigma_1^2 \,=\, \lambda_1 \:&=\: {1 \over 2} \left[ \, \left( \gamma \,+\, \alpha \right) \,+\, \left[ \beta^2 \, +\, \left( \gamma \,-\, \alpha \right)^2 \, \right]^{1/2} \right] \\
\sigma_2^2 \,=\, \lambda_2 \:&=\: {1 \over 2} \left[ \, \left( \gamma \,+\, \alpha \right) \,-\, \left[ \beta^2 \, +\, \left( \gamma \,-\, \alpha \right)^2 \, \right]^{1/2} \right]
\end{align}
\]

The reader can convince himself that with the definitions above we do indeed reproduce

\[
\lambda_1 \, \lambda_2 \:=\: r^2 \,-\, s^2 \:=\: \left(a\, d\,+\, b\,c \right)^2 \,=\, \operatorname{det}\left(\pmb{\operatorname{A}}_E\right)^2
\]

Determination of the inclination angle φ

For the determination of the angle φ we use:

\[
\begin{pmatrix} \operatorname{cos}(2\phi) \\ \operatorname{sin}(2\phi) \end{pmatrix} \:=\: {1 \over s} \begin{pmatrix} s_1 \\ s_2 \end{pmatrix}
\]

If we choose

\[
-\pi/2 \,\lt\, \phi \le \pi/2
\]

we get:

\[
\phi \:=\: {1 \over 2} \operatorname{arctan}\left({s_2 \over s_1}\right) \:=\: – {1 \over 2} \operatorname{arctan}\left( { – 2\left(ac \,+\, bd\right) \over (a^2 \,+\, b^2 \,-\, c^2 \,-\, d^2) } \right)
\]
\[
\phi \:=\: – {1 \over 2} \operatorname{arctan}\left( {\beta \over \gamma \,- \alpha } \right)
\]

Or equivalently with respect to α, β, γ:

\[
\operatorname{sin}\left(2\phi\right) \:=\: – \, {\beta \over \left[ \beta^2 \, +\, \left( \gamma \,-\, \alpha \right)^2 \, \right]^{1/2} }
\]
\[
\phi \:=\: {1 \over 2} \operatorname{arcsin}\left({s_2 \over s}\right) \:=\: – {1 \over 2} \operatorname{arcsin}\left( {\beta \over \left[ \beta^2 \, +\, \left( \gamma \,-\, \alpha \right)^2 \, \right]^{1/2} } \right)
\]

Note: All in all there are four different solutions. The reason is that we alternatively could have requested λ2 ≥ λ1 and also chosen the angle π + φ. So, the ambiguity is due to a selection of the considered principal axis and rotational symmetries.

In the special case that we have a circle

\[
\lambda_1 \,=\, \lambda_2 \,=\, r
\]

and then, of course, any angle φ will be allowed.

2nd way to a solution for σ1, σ2 and φ via eigendecomposition

For our second way of deriving formulas for σ1, σ2 and φ we use some linear algebra. This way is interesting for two reasons: It indicates how we can use the Python “linalg”-package together with Numpy to get results numerically. In addition we get familiar with a representation of the ellipse in a properly rotated ECS.

Above we have written down a symmetric matrix Aq describing an operation on the position vectors of points on our rotated ellipse:

\[
\pmb{v}_e^T \circ \pmb{\operatorname{A}}_q \circ \pmb{v}_e^T \:=\: \delta
\]

We know from linear algebra that every symmetric matrix can be decomposed into a product of orthogonal matrices O, OT and a diagonal matrix. This reflects the so called eigendecomposition of a symmetric matrix. It is a unique decomposition in the sense that it has a uniquely defined solution in terms of the coefficients of the following matrices:

\[
\pmb{\operatorname{A}}_q \:=\: \pmb{\operatorname{O}} \circ \pmb{\operatorname{D}}_q \circ \pmb{\operatorname{O}}^T
\]

with

\[
\pmb{\operatorname{D}}_{q} \:=\: \begin{pmatrix} \lambda_{u} & 0 \\ 0 & \lambda_{d} \end{pmatrix}
\]

The coefficients λu and λd are eigenvalues of both Dq and Aq. Reason: Orthogonal matrices do not change eigenvalues of a transformed matrix. So, the diagonal elements of Dq are the eigenvalues of Aq. Linear algebra also tells us that the columns of the matrix O are given by the components of the normalized eigenvectors of Aq.

We can interpret O as a rotation matrix Rψ for some angle ψ:

\[
\pmb{v}_e^T \circ \pmb{\operatorname{A}}_q \circ \pmb{v}_e^T \:=\: \pmb{v}_e^T \circ
\pmb{\operatorname{R}}_{\psi} \circ \pmb{\operatorname{D}}_q \circ \pmb{\operatorname{R}}_{\psi}^T \circ \pmb{v}_e \:=\: \delta
\]

This means

\[
\left[ \pmb{\operatorname{R}}_{-\psi} \circ \pmb{v}_e \right]^T \circ
\pmb{\operatorname{D}}_q \circ \left[ \pmb{\operatorname{R}}_{-\psi} \circ \pmb{v}_e \right] \:=\: \delta \:=\: \sigma_1^2\, \sigma_2^2
\]
\[
\pmb{v}_{-\psi}^T \circ \pmb{\operatorname{D}}_q \circ \pmb{v}_{-\psi} \:=\: \sigma_1^2\, \sigma_2^2
\]

The whole operation tells us a simple truth, which we are already familiar with:

By our construction procedure for a rotated ellipse we know that a rotated ECS exists, in which the ellipse can be described as the result of a scaling operation (along the coordinate axes of the rotated ECS) applied to a unit circle. (This ECS is, of course, rotated by an angle φ against our working ECS in which the ellipse appears rotated.)

Indeed:

\[
\left(\, x_{-\psi}, \,y_{-\psi}\,\right) \circ \begin{pmatrix} \lambda_u & 0 \\ 0 & \lambda_d \end{pmatrix} \circ \begin{pmatrix} x_{-\psi} \\ y_{-\psi} \end{pmatrix} \:=\: \sigma_1^2\, \sigma_2^2
\]
\[
{\lambda_u \over \sigma_1^2\, \sigma_2^2} \, x_{-\psi}^2 \, + \, {\lambda_d \over \sigma_1^2\, \sigma_2^2} \, y_{-\psi}^2 \:=\: 1
\]

We know exactly what angle ψ by which we have to rotate our ECS to get this result: ψ = φ. Therefore:

\[ \begin{align}
x_{-\psi} \:&=\: x_c, \\
y_{-\psi} \:&=\: y_c, \\
\lambda_u \:&=\: \lambda_2 \,=\, \sigma_2^2, \\
\lambda_d \:&=\: \lambda_1 \,=\, \sigma_1^2
\end{align}
\]

This already makes it plausible that the eigenvalues of our symmetric matrix Aq are just λ1 and λ2.

Mathematically, a lengthy calculation will indeed reveal that the eigenvalues of a symmetric matrix Aq with coefficients α, 1/2*β and γ have the following form:

\[
\lambda_{u/d} \:=\: {1 \over 2} \left[\, \left(\alpha \,+\, \gamma \right) \,\pm\, \left[ \beta^2 + \left(\gamma \,-\, \alpha \right)^2 \,\right]^{1/2} \, \right]
\]

This is, of course, exactly what we have found some minutes ago by directly solving the equations with the trigonometric terms.

We will prove the fact that these indeed are valid eigenvalues in a minute. Let us first look at respective eigenvectors ξ1/2. To get them we must solve the equations resulting from

\[
\left( \begin{pmatrix} \alpha & \beta / 2 \\ \beta / 2 & \gamma \end{pmatrix} \,-\, \begin{pmatrix} \lambda_{1/2} & 0 \\ 0 & \lambda_{1/2} \end{pmatrix} \right) \,\circ \, \pmb{\xi_{1/2}} \:=\: \pmb{0},
\]

with

\[
\pmb{\xi_1} \,=\, \begin{pmatrix} \xi_{1,x} \\ \xi_{1,y} \end{pmatrix}, \quad \pmb{\xi_2} \,=\, \begin{pmatrix} \xi_{2,x} \\ \xi_{2,y} \end{pmatrix}
\]

Again a lengthy calculation shows that the following vectors fulfill the conditions (up to a common factor in the components):

\[ \begin{align}
\lambda_1 \: &: \quad \pmb{\xi_1} \:=\: \left(\, {1 \over \beta} \left( (\alpha \,-\, \gamma) \,-\, \left[\, \beta^2 \,+\, \left(\gamma \,-\, \alpha \right)^2\,\right]^{1/2} \right), \: 1 \, \right)^T \\
\lambda_2 \: &: \quad \pmb{\xi_2} \:=\: \left(\, {1 \over \beta} \left( (\alpha \,-\, \gamma) \,+\, \left[\, \beta^2 \,+\, \left(\gamma \,-\, \alpha \right)^2\,\right]^{1/2} \right), \: 1 \, \right)^T
\end{align}
\]

for the eigenvalues

\[ \begin{align}
\lambda_1 \:&=\: {1 \over 2} \left(\, \left(\alpha \,+\, \gamma \right) \,+\, \left[ \beta^2 \,+\, \left(\gamma \,-\, \alpha \right)^2 \,\right]^{1/2} \, \right) \\
\lambda_2 \:&=\: {1 \over 2} \left(\, \left(\alpha \,+\, \gamma \right) \,-\, \left[ \beta^2 \,+\, \left(\gamma \,-\, \alpha \right)^2 \,\right]^{1/2} \, \right) \\
\end{align}
\]

The T at the formulas for the vectors symbolizes a transposition operation.

Note that the vector components given above are not normalized. This is important for performing numerical checks as Numpy and linear algebra programs would typically give you normalized eigenvectors with a length = 1. But you can easily compensate for this by working with

\[ \begin{align}
\lambda_1 \: &: \quad \pmb{\xi_1^n} \:=\: {1 \over \|\pmb{\xi_1}\|}\, \pmb{\xi_1} \\
\lambda_2 \: &: \quad \pmb{\xi_2^n} \:=\: {1 \over \|\pmb{\xi_2}\|}\, \pmb{\xi_2}
\end{align}
\]

Proof for the eigenvalues and eigenvector components

We just prove that the eigenvector conditions are e.g. fulfilled for the components of the second eigenvector ξ2 and λ2 = λd.

\[ \begin{align}
\left(\alpha \,-\, \lambda_2 \right) * \xi_{2,x} \,+\, {1 \over 2} \beta * \xi_{2,y} \,&=\, 0 \\
{1 \over 2} \beta * \xi_{2,x} \,+\, \left( \gamma \,-\, \lambda_2 \right) * \xi_{2,y} \,&=\, 0
\end{align}
\]

(The steps for the first eigenvector are completely analogous).

We start with the condition for the first component

\[ \begin{align}
&\left( \alpha \,-\,
{1\over 2}\left[\,\left(\alpha \, + \, \gamma\right) \,+\, \left[ \beta^2 \,+\, \left( \alpha \,-\, \gamma \right)^2 \right]^{1/2} \right] \right) * \\
& {1 \over \beta}\,
\left[\, \left(\alpha \,-\, \gamma\right) \,+\, \left[ \beta^2 \,+\, \left(\alpha \,-\, \gamma \right)^2 \right]^{1/2} \,\right] \,+\, {\beta \over 2 }
\,=\, 0
\end{align}
\]
\[ \begin{align}
& {1 \over 2 } \left[ \left(\alpha \,-\,\gamma\right) \,+\, \left[ \beta^2 \,+\, \left( \alpha \,-\, \gamma \right)^2 \right]^{1/2} \right] * \\
& {1 \over \beta}\,
\left[\, \left(\alpha \,-\, \gamma\right) \,+\, \left[ \beta^2 \,+\, \left(\alpha \,-\, \gamma \right)^2 \right]^{1/2} \,\right] \,+\, {\beta \over 2 }
\,=\, 0
\end{align}
\]
\[
{1 \over 2 \beta} \left[ (\alpha \,-\,\gamma)^2 \,-\, \beta^2 \,-\, (\alpha \,-\,\gamma)^2 \right] \,+\, {\beta \over 2 } \,=\, 0
\]

The last relation is obviously true. You can perform a similar calculation for the other eigenvector component:

\[ \begin{align}
{1 \over 2} \, \beta & {1 \over \beta}\,
\left[\, \left(\alpha \,-\, \gamma\right) \,+\, \left[ \beta^2 \,+\, \left(\alpha \,-\, \gamma \right)^2 \right]^{1/2} \,\right] \,+\, \\
&
\left( \gamma \, -\,
{1\over 2}\left[\,\left(\alpha \, + \, \gamma\right) \,+\, \left[ \beta^2 \,+\, \left( \alpha \,-\, \gamma \right)^2 \right]^{1/2} \right] \right) * 1 \,=\, 0
\end{align}
\]

Thus:

\[ \begin{align}
&{1 \over 2} \, \left(\alpha \,-\, \gamma\right) \,+\, {1 \over 2} \left[ \beta^2 \,+\, \left(\alpha \,-\, \gamma \right)^2 \right]^{1/2} \,-\, \\
&{1\over 2}\left(\alpha \,-\, \gamma\right) \,-\, {1\over 2}\left[ \beta^2 \,+\, \left( \alpha \,-\, \gamma \right)^2 \right]^{1/2} \,=\, 0
\end{align}
\]

True, again. In a very similar exercise one can show that the scalar product of the eigenvectors is equal to zero:

\[ \begin{align}
& {1 \over \beta}\,
\left[\, \left(\alpha \,-\, \gamma\right) \,+\, \left[ \beta^2 \,+\, \left(\alpha \,-\, \gamma \right)^2 \right]^{1/2} \,\right] \,+\, {\beta \over 2 } \,*\, \\
& {1 \over \beta}\,
\left[\, \left(\alpha \,-\, \gamma\right) \,-\, \left[ \beta^2 \,+\, \left(\alpha \,-\, \gamma \right)^2 \right]^{1/2} \,\right] \,+\, {\beta \over 2 } \,+\, 1\,*\,1 \\
&\, {1 \over \beta^2}\, *\, (-\beta^2) \,+\, 1 \,=\, 0
\end{align}
\]

I.e.:

\[
\pmb{\xi_1} \bullet \pmb{\xi_1} \,=\, \left( \xi_{1,x}, \, \xi_{1,y} \right) \circ \begin{pmatrix} \xi_{2,x} \\ \xi_{2,y} \end{pmatrix} \,= \, 0,
\]

which means that the eigenvectors are perpendicular to each other. Exactly, what we expect for the orientations of the principal axes of an ellipse against each other.

Rotation angle from coefficients of Aq

We still need a formula for the rotation angle(s). From linear algebra results related to an eigendecomposition we know that the orthogonal (rotation) matrices consist of columns of the normalized eigenvectors. With the components given in terms of our un-rotated ECS, in which we basically work. These vectors point along the principal axes of our ellipse. Thus the components of these eigenvectors define our aspired rotation angles of the ellipse’s principal axes against the x-axis of our ECS.

Let us prove this. By assuming

\[ \begin{align}
\operatorname{cos}(\phi_1) \,&=\, \xi_{1,x}^n \\
\operatorname{sin}(\phi_1) \,&=\, \xi_{1,y}^n
\end{align}
\]

and using

\[
\operatorname{cos}(2\phi_1) \,=\, 2\, \operatorname{sin}(\phi_1) \, \operatorname{cos}(\phi_1)
\]

we get:

\[ \begin{align}
\operatorname{sin}(2 \phi_1) \,=\,
2 * { \xi_{1,x} * \xi_{1,y} \over \left[\, \xi_{1,x}^2 \, + \, \xi_{1,y}^2 \,\right]^{1/2} }
\end{align}
\]

and thus

\[ \begin{align}
\operatorname{sin}(2 \phi_1) \,&=\,
2 \, { {1 \over \large{\beta}} \left( (\alpha \,-\, \gamma) \,-\, \left[\, \beta^2 \,+\, \left(\gamma \,-\, \alpha \right)^2\,\right]^{1/2} \right) \,*\, 1
\over
\left[\, \left( {1 \over \large{\beta}} \left( (\alpha \,-\, \gamma) \,-\, \left[\, \beta^2 \,+\, \left(\gamma \,-\, \alpha \right)^2\,\right]^{1/2} \right) \right)^2
\,+\, 1^2 \right]^{1/2} } \\
&=\, 2\, { {1 \over \large{\beta}} \left( t \,-\, z \right)
\over
{1 \over \large{\beta}^2 \phantom{\large{]}} } \left[\, \beta^2 \,+\, \left(\, t \,-\, z \,\right)^2 \right]^2 }
\end{align}
\]

with

\[ \begin{align}
t \,&=\, (\alpha \,-\, \gamma) \\
z \,&=\, \left[\, \beta^2 \,+\, \left(\gamma \,-\, \alpha \right)^2\,\right]^{1/2}
\end{align}
\]

This looks very differently from the simple expression we got above. And a direct approach is cumbersome. The trick is multiply nominator and denominator by a convenience factor

\[
\left( t \,+\, z \right),
\]

and exploit

\[ \begin{align}
\left( t \,-\, z \right) \, \left( t \,+\, z \right) \,&=\, t^2 \,-\, z^2 \\
\left( t \,-\, z \right) \, \left( t \,+\, z \right) \,&=\, – \beta^2
\end{align}
\]

to get

\[ \begin{align}
&2 * \beta { (t\,-\, z) * ( t\,+\, z) \over \left[ \beta^2 \, + \,( t \,-\, z )^2 \right] * (t \,+\, z) } \\
=\, &2 * \beta { – \beta^2 \over \beta^2 (t\,+\,z) \,-\, \beta^2 (t\,-\,z) } \\
=\, & – {\beta \over \left[\, \beta^2 \,+\, (\alpha \,-\, \gamma)^2 \,\right]^{1/2} }
\end{align}
\]

This means that our 2nd solution approach provides the result

\[
\operatorname{sin}(2 \phi_1) \, =\, – \, { \beta \over \left[\, \beta^2 \,+\, (\alpha \,-\, \gamma)^2 \,\right]^{1/2} }\,,
\]

which is of course identical to the result we got with our first solution approach. It is clear that the second axis has an inclination by φ +- π / 2:

\[
\phi_2\, =\, \phi_1 \,\pm\, \pi/2.
\]

In general the angles have a natural ambiguity of π.

Conclusion

In this post I have shown how one can derive essential properties of centered, but rotated ellipses from matrix-based representations. Such calculations become relevant when e.g. experimental or numerical data only deliver the coefficients of a quadratic form for the ellipse.

We have first established the relation of the coefficients of a matrix that defines an ellipse by a combined scaling and rotation operation with the coefficients of a matrix which defines an ellipse as a quadratic form of the components of position vectors. In addition we have shown how the coefficients of both matrices are related to quantities like the lengths of the principal axes of the ellipse and the inclination of these axes against the x-axis of the Euclidean coordinate system in which the ellipse is described via position vectors. So, if one of the matrices is given we can numerically calculate the ellipse’s main properties.

In the next post of this mini-series

Properties of ellipses by matrix coefficients – II – coordinates of points with extremal y-values

we have a look at the x- and y-coordinates of points on an ellipse with extremal y-values. All in terms of the matrix coefficients we are now familiar with.

 

Fun with shear operations and SVD – III – Shearing of circles

This post requires Javascript to display formulas!

In the two previous posts of this series

Fun with shear operations and SVD – I – shear matrices and examples created with Blender
Fun with shear operations and SVD – II – Shearing of rectangles and cubes with Python and Matplotlib

we have clarified some basic properties of shear transformations [SHT]. We got interested in this topic, because Autoencoders can produce latent multivariate normal vector distributions, which in turn result from linear transformations of multivariate standard normal distributions. When we want to analyze such latent vector distributions we should be aware transformations of quadratic forms. An important linear transformation is a shear operation. It combines aspects of scaling with rotations.

The objects we applied SHTs to were so far only squares and cubes. Both (discrete) rotational and plane symmetries of the squares and cubes were broken by SHTs. We also saw that this symmetry breaking could not be explained by a pure scaling operation in another rotated Euclidean Coordinate System [ECS]. But cubes do not have a continuous rotational symmetry. The distances of surface points of a cube to its symmetry center show no isotropy.

However, already in the first post when we superficially worked with Blender we got the impression that the shearing of a sphere seemed to produce a figure with both plane and discrete rotational symmetries – namely ellipsoids, wich appeared to be rotated. We still have to prove this, mathematically. With this post we move a first step in this direction: We will apply a shear operation to a 2D-body with perfect continuous rotational symmetry in all directions, namely a circle. A circle is a special example of a quadratic form (with respect to the vector component values). We center our Euclidean Coordinate System [ECS] at the center of the circle. We know already that this point remains a fix-point of our transformations. As in the previous post I use Python and Matplotlib to produce visual results. But we support our impression also by some simple math.

We first check via plotting that the shear operations move an extremal point of the circle (with respect to the y-coordinate) along a line ymax = const. (Points of other layers for other values yl = const also move along their level-lines.) We then have to find out whether the produced figure really is an ellipse. We do so by mathematically deriving its quadratic form with respect to the coordinates of the transformed points. Afterward, we derive the coordinate values of points with extremal y-values after the shear transformation.

In addition we calculate the position of the points with maximum and minimum distance from the center. I.e., we derive the coordinates of end-points of the main axes of the ellipse. This will enable us to calculate the angle, by which the ellipse is rotated against the x-axis.

The astonishing thing is that our ellipse actually can be created by a pure scaling operation in a rotated ECS. This seems to be in contrast to our insight in previous posts that a shear matrix cannot be diagonalized. But it isn’t … It is just the rotational symmetry of the circle that saves us.

Shearing a circle

We define a circle with radius r = a = 2.

I have indicated the limiting line at the extremal y-values. From the analysis in the last post we expect that a shear operation moves the extremal points along this line.

We now apply a shearing matrix with a x/y-shearing parameter λ = 2.0

\[ M_{sh} \: = \: \begin{pmatrix} 1.0 & 2.0 \\ 0.0 & 1.0\end{pmatrix}
\]

The result is:

As expected! This really looks like an ellipse. Can we proof it?

Transformation of the circle

We use the definition of a shear transformation in 2D (see the first post of this series):

\[ \begin{align}
x_s \: &= \: x \, + \, \lambda * y \\
y_s \: &= \: y
\end{align}
\]

and the definition of the original circle with radius a:

\[ \begin{align}
{x^2 \over \, a^2} \, + \, {y^2 \over \, a^2} \:&=\: 1 \\
\Rightarrow \: {x_s^2 \,-\, λ y_s \over \, a^2} \, + \, {y_s^2 \over \, a^2} \:&=\: 1 \phantom{\Huge{(}}
\end{align}
\]

This actually gives us a quadratic expression in the new coordinate values:

\[
x_s^2 \, + \, \left(\,1\,+\,\lambda^2\, \right)*y_s^2 \:-\: {2 \lambda \over 1\,+\,\lambda^2}*x_s*y_s \:=\: a^2
\]

Thus, we have indeed produced a rotated ellipse! We see this from the fact that the term mixing the xs and the yl coordinates does not vanish.

Position of maximum absolute y-values

We know already that the y-coordinates of the extremal points (in y-direction) are preserved. And we know that these points were located at x = 0, y = a. So, we can calculate the coordinates of the shifted point very easily:

\[ x_s \:=\: 0 \, + \, \lambda * a \:\Rightarrow \: x_s \:=\: \lambda * a \quad (\, = 4\,)
\]

In our case this gives us a position at (4, 2). But for getting some experience with the quadratic form let us determine it differently, namely by rewriting the above quadratic equation and by a subsequent differentiation. Quadratic supplementation gives us:

\[
\left[\, y_s \,- \, {\lambda \over 1\,+\, \lambda^2} \, x_s^2 \, \right]^2 \:=\:
{ 1 \over \left( 1\,+\, \lambda^2 \right)^2} \left[\, a^2\left(\, 1\,+\,\lambda^2 \,\right) \, – \, x_s^2 \,\right],
\]
\[
y_s \:=\: {1 \over 1\,+\, \lambda^2}\, \left( \, \lambda x_s \, \pm \, \left[\, a^2\left(\, 1\,+\,\lambda^2 \,\right) \, – \, x_s^2 \,\right]^{1/2}\, \right)
\]

and

\[
{\partial y_s \over \partial x_s } \:=\: {1 \over 1\,+\, \lambda^2 }\, \left( \, \lambda \, \pm \, {(-x_s) \over \left[\, a^2\left(\, 1\,+\,\lambda^2 \,\right) \, – \, x_s^2 \,\right]^{1/2} } \, \right)
\]

We demand that the derivative becomes zero:

\[
{\partial y_s \over \partial x_s } \:=\: 0 \: \Rightarrow \: x_s^2 \, = \, \lambda^2 \, \left[\, a^2\left(\, 1\,+\,\lambda^2 \,\right) \, – \, x_s^2 \,\right]
\]

Thus – as expected :

\[
x_s^2 \, = \, \lambda^2 \, a^2
\]

Points with maximum radial distance

Let us also find the position of the end-points of the main axes of the ellipse. One method would be to express the ellipse in terms of the coordinates (xs, ys), calculate the squared radial distance rs of a point from the center and set the derivative with respect to xs to zero.

\[
r_s^2 \, = \, x_s^2 \, +\, \left(y_s(x_s)\right)^2, \quad {\partial r_s \over \partial x_s} \,= \, 0 \,.
\]

The “problem” with this approach is that we have to work with a lot of terms with square roots. Sometimes it is easier to just work in the original coordinates and express everything in terms of (x, y):

\[
r_s^2(x) \, = \, \left(x_s(x)\right)^2 \, +\, \left(y_s(x)\right)^2, \quad {\partial r_s(x) \over \partial x} \,= \, 0 \,.
\]

With the basic circle equation and the transformation rules this gives us:

\[
{\partial \over \partial x} \left[x^2 \,+\, 2 \lambda x y \,+\, \lambda^2 y^2 \,+\, y^2 \right] \,= \, 0
\]
\[
\quad {\partial \over \partial x} \left[a^2(1 \,+\ \lambda^2) \,-\, \lambda^2 x^2 + 2 \lambda x \left(a^2\,-\, x^2\right)^{1/2} \right] \,= \, 0
\]

We do not get rid of the square roots. But it is easy to handle. Sorting of terms and getting rid of the denominator leads us to

\[
\left( a^2\,-\ x^2 \right) \, =\, x^2 \,+\, \lambda x \left( a^2 \,-\, x^2 \right)^{1/2}
\]

Adding a quadratic supplementation term gives:

\[
\left( a^2\,-\ x^2 \right) \,+\, {\lambda^2 \over 4} \left( a^2\,-\ x^2 \right) \, =\, \left[ \, x \,+\, {\lambda \over 2 } \left( a^2 \,-\, x^2 \right)^{1/2} \, \right]^2
\]

Taking the square root and reordering results in:

\[
x \,=\, \left( a^2 \,-\, x^2 \right)^{1/2} \, \left[\,\pm\, \left( 1\,+\, {\lambda^2 \over 4} \right) ^{1/2} -\, {\lambda \over 2} \,\right]
\]

Squaring leads to:

\[ \begin{align}
x^2 \,&=\, \left( a^2 \,-\, x^2 \right) \, \left[\,1 \,+\, {1 \over 2} \lambda^2 \,\pm\, {\lambda \over 2} \left(4\,+\, \lambda^2\right)^{1/2} \,\right] \\
&:=\ \xi * \left( a^2 \,-\, x^2 \right)
\end{align}
\]

So, in the end, we get a very simple expression for the x-coordinate of the axes’ end-points:

\[
x \,=\, \pm\, a\, \sqrt{\eta \phantom{\large{(}} }, \quad \mbox{with} \quad \eta \,=\, {\xi \over 1\, +\, \xi }
\]

This gives us all in all 4 solutions as ξ got two values:

\[ \begin{align}
\xi_1 \,&=\, \left[\,1 \,+\, {1 \over 2} \lambda^2 \,-\, {\lambda \over 2} \left(4\,+\, \lambda^2\right)^{1/2} \,\right], \quad \eta_1 \, = \, {\xi_1 \over 1\, +\, \xi_1} \\
\xi_2 \,&=\, \left[\,1 \,+\, {1 \over 2} \lambda^2 \,+\, {\lambda \over 2} \left(4\,+\, \lambda^2\right)^{1/2} \,\right], \quad \eta_2 \, = \, {\xi_2 \over 1 \,+\, \xi_2}
\end{align}
\]

This was to be expected as there are 4 end-points of 2 main axes of an ellipse.

Of course, we need the transformed coordinates. A small calculation shows:

End points of 1st main axis

\[ \begin{align}
x_{s1} \,&=\,\, \: a\, \sqrt{\eta_1 \phantom{\large{(}} } \,+\, \lambda a \, \sqrt{1 \,-\,\eta_1 \phantom{\large{(}} }, \quad
y_{s1} \,=\, \: a\, \sqrt{1 \,-\,\eta_1 \phantom{\large{(}} } \\
x_{s2} \,&=\, – a \, \sqrt{\eta_1 \phantom{\large{(}} } \,-\, \lambda a \, \sqrt{1 \,-\,\eta_1 \phantom{\large{(}} }, \quad
y_{s2} \,=\, – a \, \sqrt{1 \,-\,\eta_1 \phantom{\large{(}} }
\end{align}
\]

End points of 2nd main axis

\[ \begin{align}
x_{s3} \,&=\,\,\: a \, \sqrt{\eta_2 \phantom{\large{(}} } \,-\, \lambda a \, \sqrt{1 \,-\,\eta_2 \phantom{\large{(}} }, \quad
y_{s3} \,=\, – \, a \, \sqrt{1 \,-\,\eta_2 \phantom{\large{(}} } \\
x_{s4} \,&=\, – a \, \sqrt{\eta_2 \phantom{\large{(}} } \,+\, \lambda a \, \sqrt{1 \,-\,\eta_2 \phantom{\large{(}} }, \quad
y_{s4} \,=\,\, \: a \, \sqrt{1 \,-\,\eta_2 \phantom{\large{(}} } \\
\end{align}
\]

These formulas enable us also to calculate the length-values of our ellipse’s main axes (half-diameters!), as and bs :

\[ \begin{align}
a_s \,&=\,\,\: \sqrt{\,x_{s1}^2 \, + \, y_{s1}^2 \phantom{\large{(}} }, \quad \left(\,\approx 4.83 \,\right) \\
b_s \,&=\,\,\: \sqrt{\,x_{s3}^2 \, + \, y_{s3}^2 \phantom{\large{(}} }, \quad \left(\,\approx 0.83\, \right)
\end{align}
\]

For our shearing in x-direction as gives us the longer axis. The rotational angle α between the longer main axis and the x-axis can be calculated via:

\[
\alpha \,=\, \arctan \left( { y_{s1} \over x_{s1} } \right) , \quad \left( \,\approx 22.5 \deg \right)
\]

Plot of main axes, their end-points and of the points with maximum y-value

The coordinate data found above help us to plot the respective points and the axes of the produced ellipse. The diameters’ end-points are plotted in red, the points with extremal y-value in green:

It becomes very clear that the points with maximum y-values are not identical with the end-points of the ellipse’s main symmetry axes. We have to keep this in mind for a discussion of higher dimensional figures and vector distributions as multidimensional spheres, ellipsoids and multivariate normal distributions in later posts.

Rotated ECS to produce the ellipse?

The plot above makes it clear that we could have created the ellipse also by switching to an ECS rotated by the angle α. Followed by a simple scaling in x- and y-direction by the factors as and bs in the rotated ECS. This seems to be a contradiction to a previous statement in this post series, which said that a shear matrix cannot be diagonalized. We saw that in general we cannot find a rotated ECS, in which the shear transformation reduces to pure scaling along the coordinate axes. We assumed from linear algebra that we in general need a first rotation plus a scaling and afterward a second different rotation.

But the reader has already guessed it: For a fully rotation-symmetric, i.e. isotropic body any first rotation does not change the figure’s symmetry with respect to the new coordinate axes. In contrast e.g. to squares or rectangles any rotated coordinate system is as good as any other with respect to the effect of scaling. So, it is just scaling and rotating or vice versa. No second rotation required. We shall in a later post see that this holds in general for isotropically shaped bodies.

Conclusion

Enough for today. We have shown that a shear transformation applied to a circle always produces an ellipse. We were able to derive the vectors to the points with maximum y-values from the parameters of the original circle and of the shear matrix. We saw that due to the circle’s isotropy we could reduce the effect of shearing to a scaling plus one rotation or vice versa. In contrast to what we saw for a cube in the previous post.

In the next post

Fun with shear operations and SVD – IV – Shearing of ellipses

we will apply a shearing transformation to an ellipse.

 

Fun with shear operations and SVD – II – Shearing of rectangles and cubes with Python and Matplotlib

This post requires Javascript to display formulas!

This post series is about shear transformations and related matrices.

In the end we want to better understand the effect of shear operations on “multivariate standard normal distributions” [MSND]. A characteristic property of a MNSD is that its contour hyper-surfaces of constant density are nested spheres. We want to understand the impact of a shear operation on such a random vector distribution.

In the first post of this series
Fun with shear operations and SVD – I – shear matrices and examples created with Blender
we have already had a preliminary look on shear transformations. We have seen that shear transformations are a special class of affine transformations. They are represented by square unipotent, upper (or lower) triangular matrices. The eigenspace is 1-dimensional and the only eigenvalue is 1.

We have also understood that a shear operation can not be reduced to a simple scaling operation with different factors by choosing some special rotated Euclidean coordinate system [ECS], whose origin coincides with volume and symmetry center of the original figure.

Due to its matrix properties which are very different from orthogonal matrices a shear operation is neither a rotation, nor a scaling. Instead we suspect that it might only be decomposed into a combination of a rotation plus a scaling – whatever coordinate system we choose. We still have to prove this in a forthcoming post.

In this post we want to explicitly apply shear matrices to simple 2D- and 3D-figures, namely squares and cubes. We use Python to control the operations and visualize the results with the help of Matplotlib. We will check that the position and orientation of all extremal points in y-direction (2D-case) and z-direction (3D-case) are preserved during shearing. We will depict this by applying the transformations to position-vectors, which point to elements of distinct vertical layers. In 3D I also test the effects of shearing on cubes by just using the 8 corner points of the cube to define 6 faces, which then get transformed.

Afterward we briefly look at the chaining of shear operations and the resulting product of their respective matrices. As some people may think that one could use combinations of shears induced by a mix of upper triagonal and lower triagonal matrices, we investigate the effects of such combinations. We see that such combinations hurt conditions we have already defined for pure shear operations. Even a symmetric matrix, which has the same shear factors in the upper and lower triangular parts of the matrix has a different effect than a real shearing: It distorts a body in the sense of a pure scaling with different factors in potentially all orthogonal directions.

Hint: I omit Python code in this post. If I find the time I will deliver some code snippets at the end of this post series. However, it is really easy to set up your own programs to reproduce the results of my experiments and respective plots with the help of Numpy and Matplotlib.

Before showing results of numerical experiments I first list up some general affine properties and other specific properties of shear transformations.

Affine properties of shear transformations

Important properties of all affine transformations are:

  • Collinearity: points on a line are transformed into points on a line.
  • Parallelism: Parallel lines remain parallel lines. Lines remain lines. Planes are transformed into planes.
  • Preservation of sub-dimensionality: Affine transformations preserve the dimensionality of objects confined to a sub-space of the “affine” space they operate on.
  • Convexity: Convex figures remain convex – i.e. the sign of a curvature radius does not change.
  • Proportionality: Distance ratios on parallel line segments are preserved.

Extremal points on convex surfaces may remain extremal with respect to distances to the origin, but not with respect to a specific coordinate axis (rotation!). Note that the third point holds for convex (hyper-) surfaces – as e.g. that of a sphere or ellipsoid.

Properties of shear transformations and their matrices Msh

I list some properties which I have already discussed in my previous post:

  • Fix point: When we omit a translation it is natural to choose an Euclidean coordinate system [ECS] such, that its origin coincides with the symmetry center of the body to be sheared. This point then remains a fixed point of the transformation.
  • Msh is a unipotent matrix with non-zero-elements only in its upper (or lower) triangular part. The matrix elements on the diagonal are just 1.
  • det(Msh) = 1. A shear transformation is invertible. Its rank is rank(Msh) = n.
  • The only eigenvalue ε is ε = 1. Its multiplicity in the ℝn is n.
  • The eigenspace ESsh has a dimension dim(ESsh) = 1.
  • A single pure shear mediated by a unipotent upper (or lower) matrix can not be reduced to a pure scaling operation in some cleverly chosen, rotated coordinate system.

For reasons of convenience we below again chose an Euclidean coordinate system [ECS] whose origin coincides with the center of volume or the symmetry center of a body which we apply a shear transformation to. This not only guarantees a central fixed point. The structure of the diagonal matrix and the 1s on the diagonal

\[ \begin{align} \pmb{\operatorname{M}}_{sh} \, &= \,
\begin{pmatrix}
1 & m_{12} &\cdots & m_{1n} \\
0 & 1 &\cdots & m_{2n} \\
\vdots &\vdots &\ddots &\vdots \\
0 & 0 &\cdots & 1 \end{pmatrix}, \\
\pmb{v}^{sh} \: &= \: \pmb{\operatorname{M}}_{sh} \circ \pmb{v} \phantom{\Huge{(}}
\end{align}
\]

make it clear that the last component of any affected vector remains constant during a shear transformation:

\[
\begin{align}
\pmb{v} \: &= \: (\, v_1, \, v_2, \,\cdots \, v_n)^T, \\
\pmb{v}^{sh} \: &= \: (\, v_1^{sh}, \, v_2^{sh}, \,\cdots \, v_n^{sh})^T \phantom{\huge{(}} \\
v^{sh}_n \: &= \: 1.0 \, *\, v_n \phantom{\huge{(}}
\end{align}
\]

This is independent of the linear coupling between other components. Therefore, an important feature of a shear operation is:

Extremal points on the surface of a sheared body in the n-th coordinate direction remain extremal and are moved within a hyper-plane orthogonal to the sub-space ℝ1 of the ℝn.

And, more generally:

Points of a sheared body lying in a (n-1)-dimensional sub-space of the ℝn, which are defined by vn = const, are moved within the sub-space, only, during shearing.

In 3D with coordinates (x, y, z) such a sub-space is a hyper-plane defined by z = const.. E.g. for a cube the points of the top face in z-direction are elements who just move within this plane during a shearing-operation. The same holds for any layer of points defined by other values z = const. Actually, the extremal points in z-direction even move along defined straight lines within the plane. In the general case these lines cross the (n-1)-dimensional sub-space.

It is time to take Python to perform some numerical experiments in 2D and 3D – and visualize the above statements. As said, in this post we concentrate on the shearing of squares and cubes. And the behavior of extremal points and other points located on layers with a constant value of the preserved vector component. I admit that squares and cubes are a bit boring, but this post is just a preparational step towards a closer investigation of the the impact of shear operations on statistical vector distributions controlled by Gaussians.

2D: Shearing of a square/rectangle

The figure below shows the end-points of position-vectors, which define data points on a rectangular meshes within a square. All the points reside inside and on the boundary of the square and reflect horizontal layers of the square:

Now we apply a shear matrix with the following elements [[1.0, 1.5], [0.0, 1.0]]. As we only work in two dimensions our matrix just has 4 elements with values ≠ 0. We name the undisturbed vectors of our square vsq. The resulting vectors after the shear operation will be called vsh. I.e.:

\[ \pmb{\operatorname{M}}_{sh} \: = \: \begin{pmatrix} 1.0 & 1.5 \\ 0.0 & 1.0\end{pmatrix}
\]

and

\[ \pmb{v}_{sh} \: = \: \pmb{\operatorname{M}}_{sh} \circ \pmb{v}_{sq}
\]

A plot of all the vsh gives us:

Exactly, what we expected. We directly see the constant shift of layers against each other. And we also see the linearity of the overall effect in the diagonal lines between the new edges. The overall result is a parallelogram.

The points on all the layers were moved along hyper-surfaces with y = const., which in our 2D case are just lines parallel to the x-axis.

Note that the symmetry center at the origin of our figure remained fixed. Point symmetries with respect to the original symmetry center have been preserved. However, original symmetries with respect to the coordinate axes have been broken.

For a rectangle we get analogous, stretched images:

Shear transformation of a cube

The last plots were simple, but visualized the very nature of a shear transformation: Linear differences of (position) vectors between layers. Breaking of plane symmetries for polytopes, while point symmetries are preserved. Let us try to demonstrate something similar in 3D. Once again an illustrative method to do this is to produce multiple planes on different z-levels filled with points on a regular mesh. During plotting we allow for some transparency of these points.

All images show the situation before shearing. You see the flat squares (extending in x- and y-direction) on 4 different z-levels. It can be seen that the dimensions are -15 ≤ vi ≤ 15, for i ∈ {1, 2, 3}. We now apply a shear matrix Msh = [[1.0, 0.7, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]

\[ \pmb{\operatorname{M}}_{sh} \: = \: \begin{pmatrix} 1.0 & 0.7 & 0.0
\\ 0.0 & 1.0 & 0.0 \\
0.0 & 0.0 & 1.0
\end{pmatrix}
\]

to the position-vectors of our layer points. I.e. we only induce a linear effect of the y-components onto the x-components of our vectors. The result is:

We get a systematic y-dependent change of the x-coordinate values of our points. The z-level of our layer points, however, remain unchanged. Now, we repeat our experiment, but this time we add an additional shear via a linear dependency of x- and y-component values of our vectors on their z-component by

\[ \pmb{\operatorname{M}}_{sh} \: = \: \begin{pmatrix} 1.0 & 0.7 & 1.2
\\ 0.0 & 1.0 & 1.0 \\
0.0 & 0.0 & 1.0
\end{pmatrix}
\]

The shift of the layers against each other in x- and y-direction gets a clearly visible z-dependence:

But, again and of course, all elements of our 4 layers remain on their respective z-level.

Shearing of a cube: Surface layers

An alternative method to visualize the impact of a shear-transformation on a cube with the help of Matplotlib is based on 8 vectors that span the 6 surface elements of the cube. We also make the cube-faces a bit transparent in some plots. The original cube then looks like:

The result for our last shear matrix

\[ \pmb{\operatorname{M}}_{sh} \: = \: \begin{pmatrix} 1.0 & 0.7 & 1.2
\\ 0.0 & 1.0 & 1.0 \\
0.0 & 0.0 & 1.0
\end{pmatrix}
\]

is:

Here wee see again that the z-level of the upper and lower limiting plates of the cube remained constant. They were just moved in x- and y-direction:

Our shear operation has produced a parallelepiped or a spat. This is consistent to the results of Blender experiments depicted in my previous post.

Remarks on a significant deficit of Matplotlib for 3D

A significant problem that one stumbles into with plots like those above is that Matplotlib does not offer us a real 3D engine. Meaning: It often calculates the so called z-order of objects like hyper-planes (or parts of such), curved manifolds, bodies along our fictitious line of visibility wrongly. So, the shading of e.g. transparent and opaque surfaces according to overlaps in 3D along your line of sight is almost always depicted in a wrong way.

For complex bodies this can drive you crazy and makes you wonder if it would be better to learn controlling Blender with Python. For our relatively simple cases I solved the z-order problem by disabling the computed z-order

ax = fig.add_subplot(111, projection=’3d’, computed_zorder=False)

and by manually assigning a z-order-value to each of the cube’s faces.

Still: As soon as we distort a simple body as a cube strongly (see below) you need a really good overview about the order of your surfaces and their colors after rotations. It is worthwhile to make sketches or to create a similar body with Blender first to clearly see, what happens during a sequence of rotations.

Combinations of shear transformations

Shearing transformations can, of course, be chained in an orderly sequence of operations. Let us take a 2D example of two shear matrices with the same shear-parameter:

\[ \begin{align} \pmb{\operatorname{M}}_{sh} \circ \pmb{\operatorname{M}}_{sh} \: &= \:
\begin{pmatrix} 1 & \lambda \\ 0 & 1 \end{pmatrix} \circ
\begin{pmatrix} 1 & \lambda \\ 0 & 1 \end{pmatrix}
\\
&= \: \begin{pmatrix} 1 & 2\lambda \\ 0 & 1 \end{pmatrix} \phantom{\Huge{(}^T}
\end{align}
\]

For different shear parameters we get

\[ \begin{align} \pmb{\operatorname{M1}}_{sh} \circ \pmb{\operatorname{M2}}_{sh} \: &= \:
\begin{pmatrix} 1 & \lambda \\ 0 & 1 \end{pmatrix} \circ
\begin{pmatrix} 1 & \mu \\ 0 & 1 \end{pmatrix}
\\
&= \: \begin{pmatrix} 1 & \lambda \, +\, \mu \\ 0 & 1 \end{pmatrix} \phantom{\Huge{(}^T}
\end{align}
\]

I.e., we just increase the shearing effect by performing two shear operations after another. If we had taken the negative value (μ = – λ) we would just have inverted the shearing. Note:

A chaining of pure shear matrices, which we had defined as upper triangular matrices in the first post, is a symmetric operation with respect to the order of the matrices.

Combination of upper and lower triangular shear matrices?

However, what happens if we combine an unipotent upper triangular shear matrix with a lower triangular matrix with the same shearing coefficient?

\[ \begin{align} \pmb{\operatorname{M}}_{sh} \circ \pmb{\operatorname{M}}_{sh}^T \: &= \:
\begin{pmatrix} 1 & \lambda \\ 0 & 1 \end{pmatrix} \circ
\begin{pmatrix} 1 & 0 \\ \lambda & 1 \end{pmatrix}
\\
&= \: \begin{pmatrix} 1 \,+\, \lambda^2 & \lambda \\ \lambda & 1 \end{pmatrix} \phantom{\Huge{(}^T}
\end{align}
\]

We get a symmetric matrix. This is not surprising, as this always is the case for product of a matrix with its transposed counterpart. But, in addition, a scaling is superimposed. Note also that the combined operation is not symmetric regarding the order of matrix application:

\[ \begin{align} \pmb{\operatorname{M}}_{sh}^T \circ \pmb{\operatorname{M}}_{sh} \: &= \:
\begin{pmatrix} 1 & 0 \\ \lambda & 1 \end{pmatrix} \circ
\begin{pmatrix} 1 & \lambda \\ 0 & 1 \end{pmatrix}
\\
&= \: \begin{pmatrix} 1 & \lambda \\ \lambda & 1 \,+\, \lambda^2 \end{pmatrix} \phantom{\Huge{(}^T}
\end{align}
\]

Let us apply the second variant to our square (see above) for λ = 1.5:

As expected we get a stronger distortion in y-direction. Note also that in contrast to a normal shear operation z-levels of our 4 level-rows were not preserved. Instead the individual levels appear rotated and stretched. Actually, in one of the next posts we will see that our combined matrix can be factorized into a combination of a rotation, then pure scaling, then back-rotation (by the same angle used in the first rotation). But this corresponds to nothing else than a pure scaling in a rotated ECS.

The funny thing with chaining is that using a simple symmetric matrix from the start for λ = 1.5

\[ \pmb{\operatorname{M}}_{symm} \: = \:
\begin{pmatrix} 1 & \lambda \\ \lambda & 1 \end{pmatrix}
\]

would give us a different result than a sequence of MshT * Msh:

Note:

Combining a shear matrix with its transposed is something different than just using a matrix with filling in (transposed) elements in the lower part with the same value as their mirrored elements in the upper triangular part.

By combining upper and lower triangular shear matrices we leave the group of pure shear operations

We could call the application of a symmetric matrix a kind of symmetric shearing. But even with a symmetric matrix we loose the central property of a normal shear operation, namely that the z-levels of body-layers parallel to the x/y-plane are preserved. All in all we get into trouble as soon as we combine original shear matrices and their transposed counterparts. Regarding my definition of a shear matrix in my previous post, we obviously leave the group of shear operations by such a combination. Some reader may regard this as an exaggeration. But it makes sense:
Even the symmetric matrix of the combined operation can be reduced to a pure scaling operation in a rotated coordinate system. And this simply is not shearing.

Just for fun: “Symmetric shearing” applied to a cube

Just for the fun of it, let us apply a symmetric version of a 3D-shearing matrix to our cube:
shear = [[1.0, 0.6, 1.0], [0.6, 1.0, 1.2], [1.0, 1.2, 1.0]]

\[ \pmb{\operatorname{M}}_{symm} \: = \: \begin{pmatrix}
1.0 & 0.6 & 1.0 \\
0.6 & 1.0 & 1.2 \\
1.0 & 1.2 & 1.0
\end{pmatrix}
\]

We expect all layers to be stretched into all coordinate directions now; z-levels of the original layers parallel to the x/y-plane will not be preserved. The normal vector to the transformed layers will be inclined to all axes after the operation.

The following plots were done with intransparent, opaque surfaces. Due to the extreme stretching we would otherwise loose the overview – which is nevertheless difficult. I have kept the order of colors for the cubes side-layers the same as for the unstretched cube: sf_color=[‘yellow’, ‘blue’, ‘red’, ‘green’, ‘magenta’, ‘cyan’]. I first give you some selected perspectives:

The distortion in all directions is obvious. Note that the point-symmetries of all corners with respect to the origin are preserved. The following sequence reflects views from a circle around the vertical axis:













What we learn is that even scaling alone can distort a symmetric body quite a lot.

Conclusion

In this post I have visualized the effect of shear operations on squares and cubes. We saw that working with points on layers and with respective vectors is helpful when we want to demonstrate a central property of real shear operations: One vector component stays as it is. Nevertheless, the symmetry breaking of shearing transformations was clearly visible. We also saw that we should represent shear transformations either by upper or lower triangular matrices, but we should not mix these types of matrices.

As a side effect we have seen that a combination of shear matrix with its transposed induces strong deformations in specific coordinate directions by enhanced scaling factors. Symmetric matrices also lead to relativ strong distortions. We have claimed that these distortions can be explained by pure scaling operations in a rotated coordinate system. A proof has to be delivered yet.

In the next post
Fun with shear operations and SVD – III – Shearing of circles
we take a first step in the direction of shearing multivariate normal vector distributions. We keep it simple and just study the impact of shearing transformations on circles.