Scaling#

Scaling is a linear transformation that moves a point closer or further away from the origin by a certain scaling vector. Consider the diagram shown in Fig. 33 where the point at position \(\mathbf{u}= (u_x, u_y, u_z)\) has been scaled by the scaling vector \(\mathbf{s} = (s_x, s_y, s_z)\).

../_images/scaling.svg

Fig. 33 Scaling of the point \(\mathbf{u} = (u_x, u_y, u_z)\) by the scaling vector \(\mathbf{s} = (s_x, s_y, s_z)\).#

The co-ordinates of the scaled point \(\mathbf{v}\) are easily calculated using

\[\begin{split} \begin{align*} v_x &= s_xu_x, \\ v_y &= s_yu_y, \\ v_z &= s_zu_z, \end{align*} \end{split}\]

which can be written as the matrix equation

\[\begin{split} \begin{align*} \begin{pmatrix} v_x \\ v_y \\ v_z \end{pmatrix} = \begin{pmatrix} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & s_z \end{pmatrix} \begin{pmatrix} u_x \\ u_y \\ u_z \end{pmatrix}. \end{align*} \end{split}\]

Since the translation matrix requires homogeneous co-ordinates and we would like to combine transformations we can extend the square matrix above by adding the fourth row and column of the identity matrix to give the transformation matrix for scaling.

Definition 21 (Scaling in \(\mathbb{R}^3\))

The scaling of a set of points in \(\mathbb{R}^3\) expressed using homogeneous co-ordinates by the scaling vector \(\mathbf{s} = (s_x, s_y, s_z)\) is the linear transformation with the transformation matrix

(24)#\[\begin{split}S(\mathbf{s}) = \begin{pmatrix} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ 0 & 0 & s_z & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]

The transformation matrix for inverse scaling is

(25)#\[\begin{split}S(\mathbf{s}) = \begin{pmatrix} 1/s_x & 0 & 0 & 0 \\ 0 & 1/s_y & 0 & 0 \\ 0 & 0 & 1/s_z & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]

A scaling vector \(\mathbf{s} = (1, 1, 1)\) will result in \(S=I\) and the position of any point that is scaled will be unchanged.

Example 24

A polygon is defined by three points with position vectors \(\mathbf{p}_1 = (1, 0, 1)\), \(\mathbf{p}_2 = (3, 0, 1)\) and \(\mathbf{p}_3 = (2, 0, 3)\). The polygon is scaled by a the scaling vector \(\mathbf{s} = (3, 1, 2)\). Calculate the positions of the three points after the scaling has been applied.

Solution

The homogeneous co-ordinate matrix is

\[\begin{split} \begin{align*} P = \begin{pmatrix} 1 & 3 & 2 \\ 0 & 0 & 0 \\ 1 & 1 & 3 \\ 1 & 1 & 1 \end{pmatrix}. \end{align*} \end{split}\]

and the scaling matrix is

\[\begin{split} \begin{align*} S = \begin{pmatrix} 3 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 2 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}, \end{align*} \end{split}\]

Applying the transformation

\[\begin{split} \begin{align*} S \cdot P = \begin{pmatrix} 3 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 2 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} 1 & 3 & 2 \\ 0 & 0 & 0 \\ 1 & 1 & 3 \\ 1 & 1 & 1 \end{pmatrix} = \begin{pmatrix} 3 & 9 & 6 \\ 0 & 0 & 0 \\ 2 & 2 & 6 \\ 1 & 1 & 1 \end{pmatrix}. \end{align*} \end{split}\]

So the vertex co-ordinates of the transformed polygon are \((3, 0, 2)\), \((9, 0, 2)\) and \((6, 0, 6)\). The original triangle and the scaled triangle are plotted in Fig. 34 looking along the \(y\)-axis.

MATLAB code#

The following MATLAB code applies the translation from Example 24 and plots the original and scaled polygons.

% Define homogeneous co-ordinate matrix
P = [ 1, 3, 2 ;
      0, 0, 0 ;
      1, 1, 3 ;
      1, 1, 1 ];

% Define scaling matrix
S = @(s) [ s(1), 0, 0, 0 ; 
           0, s(2), 0, 0 ; 
           0, 0, s(3), 0 ; 
           0, 0, 0, 1 ];

% Apply scaling
s = [3 ; 1 ; 2];
P1 = S(s) * P;

% Plot polygons
figure
patch(P(1,:), P(3,:), 'b', FaceAlpha=0.5)
patch(P1(1,:), P1(3,:), 'r', FaceAlpha=0.5)
axis equal 
axis([0, 10, 0, 7])
xlabel("$x$", FontSize=12, Interpreter="latex")
ylabel("$z$", FontSize=12, Interpreter="latex")
box on
../_images/scaling_example.png

Fig. 34 Scaling a polygon about the origin.#

Scaling about the centre of a shape#

We have seen in Example 24 that scaling the polygon resulted in the centre of the polygon shifting position and the aspect ratio of the polygon changed.. This was because scaling was applied to a shape whose centre was not at the origin. To preserve the position of the centre of a shape when scaling we first need to translate the points that define the shape to the origin, which means that the translation vector if \(-\mathbf{c}\) where \(\mathbf{c}\) is the centre of the shape. Then we can perform the scaling before using the inverse translation so that the centre of the shape is back at \(\mathbf{c}\) (Fig. 35).

../_images/scaling_about_centre.svg

Fig. 35 Steps required to rotate a polygon by its centre.#

So we have the following composite transformation matrix $\( \begin{align*} A = T^{-1} \cdot S \cdot T \end{align*} \)$

Example 25

Scale the polygon from Example 24 by a factor of 2 in all three directions.

Solution

The homogeneous co-ordinate matrix is

\[\begin{split} \begin{align*} P = \begin{pmatrix} 1 & 3 & 2 \\ 0 & 0 & 0 \\ 1 & 1 & 3 \\ 1 & 1 & 1 \end{pmatrix}, \end{align*} \end{split}\]

and since the polygon is a triangle the co-ordinates of the centre are the average of the vertices

\[\begin{split} \begin{align*} \mathbf{c} = \frac{1}{3} \left( \begin{pmatrix} 1 \\ 0 \\ 1 \end{pmatrix} + \begin{pmatrix} 3 \\ 0 \\ 1 \end{pmatrix} + \begin{pmatrix} 2 \\ 0 \\ 3 \end{pmatrix} \right) = \begin{pmatrix} 2 \\ 0 \\ 5/3 \end{pmatrix}. \end{align*} \end{split}\]

The individual transformation matrices are

\[\begin{split} \begin{align*} T(-\mathbf{c}) &= \begin{pmatrix} 1 & 0 & 0 & -2 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & -5/3 \\ 0 & 0 & 0 & 1 \end{pmatrix}, \\ S(\mathbf{s}) &= \begin{pmatrix} 2 & 0 & 0 & 0 \\ 0 & 2 & 0 & 0 \\ 0 & 0 & 2 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}, \\ T(\mathbf{c}) &= \begin{pmatrix} 1 & 0 & 0 & 2 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 5/3 \\ 0 & 0 & 0 & 1 \end{pmatrix}, \end{align*} \end{split}\]

which are multiplied to give the composite transformation matrix

\[\begin{split} \begin{align*} A &= T(\mathbf{c}) \cdot S(\mathbf{s}) \cdot T(-\mathbf{c}) = \begin{pmatrix} 2 & 0 & 0 & -2 \\ 0 & 2 & 0 & 0 \\ 0 & 0 & 2 & -5/3 \\ 0 & 0 & 0 & 1 \end{pmatrix} \end{align*} \end{split}\]

Applying the composite transformation

\[\begin{split} \begin{align*} A \cdot P &= \begin{pmatrix} 2 & 0 & 0 & -2 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 2 & -5/3 \\ 0 & 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} 1 & 3 & 2 \\ 0 & 0 & 0 \\ 1 & 1 & 3 \\ 1 & 1 & 1 \end{pmatrix} \\ &= \begin{pmatrix} 0 & 4 & 2 \\ 0 & 0 & 0 \\ 1/3 & 1/3 & 13/3 \\ 1 & 1 & 1 \end{pmatrix}. \end{align*} \end{split}\]

So the vertex co-ordinates of the translated polygon are \((0, 0, 1/3) \approx (0, 0, 0.33)\), \((4, 0, 1/3) \approx (4, 0, 0.33)\) and \((2, 0, 13/3) \approx (2, 0, 4.33)\). The original polygon and the scaled polygon are plotted in Fig. 36 looking along the \(y\) axis.

MATLAB code#

The following MATLAB code applies the translation from Example 25 and plots the original and scaled polygons.

% Define homogeneous co-ordinate matrix
P = [ 1, 3, 2 ;
      0, 0, 0 ;
      1, 1, 3 ;
      1, 1, 1 ];

% Calculate polygon centre
c = mean(P, 2);

% Define translation and scaling matrices
T = @(t) [ 1, 0, 0, t(1) ; 
           0, 1, 0, t(2) ; 
           0, 0, 1, t(3) ; 
           0, 0, 0, 1 ];

S = @(s) [ s(1), 0, 0, 0 ; 
           0, s(2), 0, 0 ; 
           0, 0, s(3), 0 ; 
           0, 0, 0, 1 ];

% Apply transformations
s = [2 ; 2 ; 2];
P1 = T(c) * S(s) * T(-c) * P;

% Plot polygons
figure
patch(P(1,:), P(3,:), 'b', FaceAlpha=0.5)
patch(P1(1,:), P1(3,:), 'r', FaceAlpha=0.5)
axis equal
axis([0, 6, 0, 5])
xlabel("$x$", FontSize=12, Interpreter="latex")
ylabel("$z$", FontSize=12, Interpreter="latex")
box on
../_images/scaling_about_centre_example.png

Fig. 36 Scaling a polygon about its centre.#