# Scale Matrix

In which you learn how a scale matrix is structured.

Earlier you saw that scaling could be expressed with these dot products:

\begin{aligned} p'_x &= \begin{bmatrix}\textrm{factors}_x & 0 & 0\end{bmatrix} \cdot \mathbf{p} \\ p'_y &= \begin{bmatrix}0 & \textrm{factors}_y & 0\end{bmatrix} \cdot \mathbf{p} \\ p'_z &= \begin{bmatrix}0 & 0 & \textrm{factors}_z\end{bmatrix} \cdot \mathbf{p} \\ \end{aligned}

But then you added a homogeneous coordinate to $$\mathbf{p}$$ to make translation work. For the matrix-based transformation scheme to be complete, the dot products used to scale must also recognize the homogeous coordinate. It does not contribute to $$p'_x$$, $$p'_y$$, or $$p'_z$$, so its paired coefficients are 0:

\begin{aligned} p'_x &= \begin{bmatrix}\textrm{factors}_x & 0 & 0 & 0\end{bmatrix} \cdot \mathbf{p} \\ p'_y &= \begin{bmatrix}0 & \textrm{factors}_y & 0 & 0\end{bmatrix} \cdot \mathbf{p} \\ p'_z &= \begin{bmatrix}0 & 0 & \textrm{factors}_z & 0\end{bmatrix} \cdot \mathbf{p} \\ \end{aligned}

As with translation, you add a fourth dot product to produce the homogeneous coordinate of $$\mathbf{p'}$$:

\begin{aligned} 1 &= \begin{bmatrix}0 & 0 & 0 & 1\end{bmatrix} \cdot \mathbf{p} \end{aligned}

All four dot products will be evaluated simultaneously when you assemble the vectors into this matrix:

\begin{aligned} \begin{bmatrix} \textrm{factors}_x & 0 & 0 & 0 \\ 0 & \textrm{factors}_y & 0 & 0 \\ 0 & 0 & \textrm{factors}_z & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \end{aligned}

Scaling now becomes a matrix-vector multiplication, just like translation:

\begin{aligned} \begin{bmatrix}p'_x \\ p'_y \\ p'_z \\ 1\end{bmatrix} &= \begin{bmatrix} \textrm{factors}_x & 0 & 0 & 0 \\ 0 & \textrm{factors}_y & 0 & 0 \\ 0 & 0 & \textrm{factors}_z & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \times \begin{bmatrix}p_x \\ p_y \\ p_z \\ 1\end{bmatrix} \\ \end{aligned}

All that remains is to figure out the matrix for rotation.