Rachel Chen
Back to Science for FUN

Linear Mapping & Image Transformation

Linear Algebra
cos(0.00)0sin(0.00)010-sin(0.00)0cos(0.00)
2.200002.200002.20
100.00010001

The math behind it

A linear map T:R3R3T:\mathbb{R}^3 \to \mathbb{R}^3 is a function that takes a 3D point and returns another 3D point, while preserving two simple rules:

T(u+v)=T(u)+T(v),T(cv)=cT(v).T(\mathbf{u} + \mathbf{v}) = T(\mathbf{u}) + T(\mathbf{v}), \qquad T(c\,\mathbf{v}) = c\,T(\mathbf{v}).

Every such map can be represented by a 3×33 \times 3 matrix AA, and applying the map to a point v=(x,y,z)\mathbf{v} = (x, y, z)^\top is just matrix–vector multiplication:

T(v)=Av.T(\mathbf{v}) = A\mathbf{v}.

A 3D mesh — like the cats above — is just a big collection of vertices. To transform the whole cat, we apply the same matrix AA to every vertex. Different choices of AA produce strikingly different effects.

1. Rotation

The first cat spins around the y-axis. The matrix is

Ry(θ)=[cosθ0sinθ010sinθ0cosθ].R_y(\theta) = \begin{bmatrix} \cos\theta & 0 & \sin\theta \\ 0 & 1 & 0 \\ -\sin\theta & 0 & \cos\theta \end{bmatrix}.

The middle row and column are fixed because the y-coordinate doesn’t change — points just swap between the x- and z-axes as θ\theta grows. This matrix is orthogonal (RR=IR^\top R = I) and has detR=1\det R = 1, which is the formal way of saying “rotations preserve lengths, angles, and orientation.” The cat doesn’t deform — it only turns.

2. Scaling

The second cat is driven by a diagonal matrix

S=[sx000sy000sz],S = \begin{bmatrix} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & s_z \end{bmatrix},

where sx,sy,szs_x, s_y, s_z each oscillate independently. Diagonal matrices act on each axis separately: the xx-coordinate of every vertex is multiplied by sxs_x, the yy by sys_y, and so on. When all three are equal we get a uniform scale (the cat just gets bigger or smaller); when they differ the cat squashes and stretches non-uniformly. The determinant detS=sxsysz\det S = s_x s_y s_z tells you exactly how its volume changes.

3. Shear

The third cat uses

H=[10k010001].H = \begin{bmatrix} 1 & 0 & k \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}.

The diagonal is left alone, but the lone off-diagonal entry kk shifts the xx-coordinate by an amount proportional to zz:

[xyz]=[x+kzyz].\begin{bmatrix} x' \\ y' \\ z' \end{bmatrix} = \begin{bmatrix} x + kz \\ y \\ z \end{bmatrix}.

Points high on the zz-axis slide one way, points on the opposite side slide the other. The result is a shear — the cat tilts as if pushed sideways. Notice detH=1\det H = 1, so volume is preserved even though shape isn’t: shearing rearranges material without compressing it.

Why this matters

Rotation, scaling, and shear are three of the basic building blocks of linear algebra, and any linear transformation in 3D can be decomposed into combinations of them (this is essentially the content of the singular value decomposition: A=UΣVA = U \Sigma V^\top, where UU and VV are rotations and Σ\Sigma is a scaling). Linear mapping is one of the foundations of computer graphics, image processing, neural network layers and etc.