# Scaling

Scaling is a Deformative Transformation that causes expansion or shrinking of an object. Scaling involves multiplying a coordinate points of an object by some scale factors. For example in 2D if the coordinate point of an object given by $$(x,y)$$ is scaled by a factor of $$(k_x,k_y)$$, then the new point becomes $$(k_x \times x,k_y \times y)$$. Similarly in 3D if the coordinate point of an object given by $$(x,y,z)$$ is scaled by a factor of $$(k_x,k_y,k_z)$$, then the new point becomes $$(k_x \times x,k_y \times y,k_z \times z)$$. Here $$k_x, k_y$$ and $$k_z$$ are scale factors in direction of x,y and z coordinate axes. These scale factors can only have numerical values greater than zero. Values lesser than 1 in any direction shrink the object in that direction, and values greater than 1 expand it in that direction. A value of 1 keeps the scaling in the corresponding direction unchanged.

The following summerises Scaling when the object is represented by their coordinate points:

 Scaling Type Equation Form Matrix Form Scaling in 2D $$x' = k_x \times x$$ $$y' = k_y \times y$$ $$\begin{bmatrix} k_x & 0 \\0 & k_y \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} x' \\ y' \end{bmatrix}\hspace{.5cm} OR \hspace{.5cm} \begin{bmatrix} x & y \end{bmatrix} \begin{bmatrix} k_x & 0 \\0 & k_y \end{bmatrix} = \begin{bmatrix} x' & y' \end{bmatrix}$$ Scaling in 3D $$x' = k_x \times x$$ $$y' = k_y \times y$$ $$z' = k_z \times z$$ $$\begin{bmatrix} k_x & 0 & 0 \\0 & k_y & 0\\0 & 0 & k_z\end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix}\hspace{.5cm} OR \hspace{.5cm} \begin{bmatrix} x & y & z \end{bmatrix} \begin{bmatrix} k_x & 0 & 0 \\0 & k_y & 0\\0 & 0 & k_z \end{bmatrix} = \begin{bmatrix} x' & y' & z' \end{bmatrix}$$

However, when an object is represented by an equation the new equation can be found out by dividing by the scale factors. For example let us take the object represented by following equation:
1. $$(x-5)^2 + (y-3)^2 = 25$$
On expanding the object by (2,2) (i.e. dividing by scale factor $$(2,2)$$) the new equation shall become
1. $$\Rightarrow (\frac{x}{2} -5)^2 + (\frac{y}{2}-3)^2 = 25$$
$$\Rightarrow (x-10)^2 + (y-6)^2 = 100$$
Now lets consider the object represented by following equation:
1. $$(x-10)^2 + (y-6)^2 = 100$$
On shrinking the object by (2,2) (i.e. dividing by scale factor $$(\frac{1}{2},\frac{1}{2})$$) the new equation shall become
1. $$\Rightarrow (2x -10)^2 + (2y-6)^2 = 25$$
$$\Rightarrow (x-5)^2 + (y-3)^2 = 25$$

Scaling transformation may cause unwanted Translation. To prevent it from occurring the object to be scaled must be anchored to a point. Following are the steps involved in scaling an object anchored to a particular point $$(o_x,o_y)$$ (or $$(o_x,o_y,o_z)$$ in 3D).
1. Shift the origin to point $$(o_x,o_y)$$ (or $$(o_x,o_y,o_z)$$ in 3D)
2. Perform the required scaling
3. Undo Shifting the origin i.e shift the origin back to point $$(0,0)$$ (or $$(0,0,0)$$ in 3D)
The following gives the derivation of 2D Anchored Scaling matrix:
 Matrix Type Matrix Post Multiplication $$\begin{bmatrix} 1 & 0 & o_x \\ 0 & 1 & o_y \\0 & 0 & 1\end{bmatrix} \begin{bmatrix} k_x & 0 & 0 \\ 0 & k_y & 0 \\0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & -o_x \\ 0 & 1 & -o_y \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} = \begin{bmatrix} k_x & 0 & -k_x \times o_x + o_x\\0 & k_y & -k_y \times o_y + o_y\\0 & 0 & 1\end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}$$ Pre Multiplication $$\begin{bmatrix} x & y & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\-o_x & -o_y & 1 \end{bmatrix} \begin{bmatrix} k_x & 0 & 0\\ 0 & k_y & 0\\ 0 & 0 & 1\end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ o_x & o_y & 1 \end{bmatrix} = \begin{bmatrix} x & y & 1 \end{bmatrix} \begin{bmatrix} k_x & 0 & 0\\0 & k_y & 0\\ -k_x \times o_x + o_x & -k_y \times o_y + o_y & 1\end{bmatrix}$$ Equation $$x' = (k_x \times x) - (k_x \times o_x) + o_x$$ $$y' = (k_y \times y) - (k_y \times o_y) + o_y$$

The following gives the derivation of 3D Anchored Scaling matrix:
 Matrix Type Matrix Post Multiplication $$\begin{bmatrix} 1 & 0 & 0 & o_x \\ 0 & 1 & 0 & o_y \\0 & 0 & 1 & o_z \\0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} k_x & 0 & 0 & 0 \\ 0 & k_y & 0 & 0 \\0 & 0 & k_z & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & -o_x \\ 0 & 1 & 0 & -o_y \\ 0 & 0 & 1 & -o_z \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} = \begin{bmatrix} k_x & 0 & 0 & -k_x \times o_x + o_x\\0 & k_y & 0 & -k_y \times o_y + o_y\\0 & 0 & k_z & -k_z \times o_z + o_z\\0 & 0 & 0 & 1\end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}$$ Pre Multiplication $$\begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\0 & 0 & 1 & 0 \\ -o_x & -o_y & -o_z & 1 \end{bmatrix} \begin{bmatrix} k_x & 0 & 0 & 0 \\ 0 & k_y & 0 & 0 \\0 & 0 & k_z & 0 \\ 0 & 0 & 0 & 1\end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\o_x & o_y & o_z & 1 \end{bmatrix} = \begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix} k_x & 0 & 0 & 0 \\0 & k_y & 0 & 0 \\0 & 0 & k_z & 0 \\ -k_x \times o_x + o_x & -k_y \times o_y + o_y & -k_z \times o_z + o_z & 1\end{bmatrix}$$ Equation $$x' = (k_x \times x) - (k_x \times o_x) + o_x$$ $$y' = (k_y \times y) - (k_y \times o_y) + o_y$$ $$z' = (k_z \times z) - (k_z \times o_z) + o_z$$