Spatial Transformations

Recall) Linear transformation

Linear transformation TLT_L is a mapping between vector spaces.
Linear combination is invariant under TLT_L.

TL(i=0Ncivi)=c0TL(v0)++cNTL(vN)T_L\left(\sum_{i=0}^{N}c_i\mathbf{v}_i\right) = c_0T_L(\mathbf{v}_0) + \cdots + c_NT_L(\mathbf{v}_N)

In 3D space, TLT_L can be represented by a 3x3 matrix AA.

TL(v)=A3×3v3×1T_L(\mathbf{v}) = A_{3 \times 3}\mathbf{v}_{3 \times 1}

Examples of linear transformation

  • 2D rotation [cosθsinθ sinθcosθ]\begin{bmatrix}\cos\theta & -\sin\theta\ \\ \sin\theta & \cos\theta \end{bmatrix}
  • 2D scaling [sx00sy]\begin{bmatrix}s_x & 0 \\ 0 & s_y \end{bmatrix}
  • 2D shear
    • along x-axis [1s01]\begin{bmatrix}1 & s \\ 0 & 1 \end{bmatrix}
    • along y-axis [10s1]\begin{bmatrix}1 & 0 \\ s & 1 \end{bmatrix}
  • 2D reflection
    • along x-axis [1001]\begin{bmatrix}1 & 0 \\ 0 & -1 \end{bmatrix}
    • along y-axis [1001]\begin{bmatrix}-1 & 0 \\ 0 & 1 \end{bmatrix}
  • 3D rotation
    • along x-axis (pitch) [1000cosθsinθ0sinθcosθ]\begin{bmatrix}1 & 0 & 0 \\ 0 & \cos\theta & -\sin\theta \\ 0 & \sin\theta & \cos\theta \end{bmatrix}
    • along y-axis (yaw) [cosψ0sinψ010sinψ0cosψ]\begin{bmatrix}\cos\psi & 0 & \sin\psi \\ 0 & 1 & 0 \\ -\sin\psi & 0 & \cos\psi \end{bmatrix}
    • along z-axis (roll) [cosϕsinϕ0sinϕcosϕ0001]\begin{bmatrix}\cos\phi & -\sin\phi & 0 \\ \sin\phi & \cos\phi & 0 \\ 0 & 0 & 1 \end{bmatrix}

Any linear transformation between 3D spaces can be represented as a combination of rotation, shear, and scaling.
In fact, rotation can be represented as a combination of scaling and two-axes shear, or as a combination of two one-axis shear transformation!
This can be efficient than computing cosine and sine values.

Linear transformation as a change of basis

Array is usually written as column-major Representation.

Av=[a1a2a3][xyz] \bm{A}\mathbf{v} = \begin{bmatrix} \mathbf{a}_1 & \mathbf{a}_2 & \mathbf{a}_3 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix}

In fact, each column is a linear tranform of basis.

a1=A[100],a2=A[010],a3=A[001]\mathbf{a}_1 = \bm{A}\begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}, \mathbf{a}_2 = \bm{A}\begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix}, \mathbf{a}_3 = \bm{A}\begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}

Change of basis

Instead of viewing linear transformation as transforming vector, we can view as changing basis.

xv0+yv1=xv0+yv1[v0v1][xy]=[v0v1][xy][v0v1]1[v0v1][xy]=A[xy]=[xy]\begin{align*} x\mathbf{v}_0 + y\mathbf{v}_1 &= x'\mathbf{v}'_0 + y'\mathbf{v}'_1 \\ \begin{bmatrix} \mathbf{v}_0 & \mathbf{v}_1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} &= \begin{bmatrix} \mathbf{v}'_0 & \mathbf{v}'_1 \end{bmatrix} \begin{bmatrix} x' \\ y' \end{bmatrix} \\ \begin{bmatrix} \mathbf{v}'_0 & \mathbf{v}'_1 \end{bmatrix}^{-1} \begin{bmatrix} \mathbf{v}_0 & \mathbf{v}_1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} &= A\begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} x' \\ y' \end{bmatrix} \end{align*}

Affine transformation

Affine transformation TAT_A is a mapping between affine spaces.
TAT_A maps vectors to vectors, and points to points.
TAT_A is a linear transformation on vectors.
Affine combination is invariant under TAT_A.

TA(i=0Ncipi)=c0TA(p0)++cNTA(pN)T_A\left(\sum_{i=0}^{N}c_i\mathbf{p}_i\right) = c_0T_A(\mathbf{p}_0) + \cdots + c_NT_A(\mathbf{p}_N)

In 3D space, TAT_A can be represented by a 3x3 matrix AA with a 3x1 translation vector.

TA(p)=A3×3p3×1+t3×1T_A(\mathbf{p}) = A_{3 \times 3}\mathbf{p}_{3 \times 1} + \mathbf{t}_{3 \times 1}

Homogeneous Coordinates

With homogeneous coordinates, any affine transformation between 3D spaces can also be represented by a 4x4 matrix.

TA(p)=[A3×3t3×101][p3×11]=[A3×3p3×1+t3×11]T_A(\mathbf{p}) = \begin{bmatrix} A_{3 \times 3} & \mathbf{t}_{3 \times 1} \\ 0 & 1 \end{bmatrix}\begin{bmatrix} \mathbf{p}_{3 \times 1} \\ 1 \end{bmatrix} = \begin{bmatrix} A_{3 \times 3}\mathbf{p}_{3 \times 1} + \mathbf{t}_{3 \times 1} \\ 1 \end{bmatrix}

TA(v)=[A3×3t3×101][v3×10]=[A3×3v3×10]T_A(\mathbf{v}) = \begin{bmatrix} A_{3 \times 3} & \mathbf{t}_{3 \times 1} \\ 0 & 1 \end{bmatrix}\begin{bmatrix} \mathbf{v}_{3 \times 1} \\ 0 \end{bmatrix} = \begin{bmatrix} A_{3 \times 3}\mathbf{v}_{3 \times 1}\\ 0 \end{bmatrix}

Examples of affine transformation

Obviously linear transformations (rotation, scaling, shear, reflection) are affine transformations

  • 2D translation [10tx01ty001]\begin{bmatrix}1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1\end{bmatrix}

Composite transformation

  • 2D translation T(t2)T(t1)=T(t2+t1)T(\mathbf{t}_2) \cdot T(\mathbf{t}_1) = T(\mathbf{t}_2 + \mathbf{t}_1)
  • 2D scaling S(s2)S(s1)=S(s2s1)S(\mathbf{s}_2) \cdot S(\mathbf{s}_1) = S(\mathbf{s}_2 \odot \mathbf{s}_1) (\odot is hadamard product, i.e. element-wise multiplication)
  • 2D rotation R(θ2)R(θ1)=R(θ2+θ1)R(\theta_2) \cdot R(\theta_1) = R(\theta_2 + \theta_1)

Order of matrix multiplication

Let T(p)=Tx(3)R(90°)pT(\mathbf{p}) = T_x(3) \cdot R(-90\degree) \cdot \mathbf{p}.

R to L multiplication

R to L multiplication interpret operations with respect to world coordinates.

L to R multiplication

L to R multiplication interpret operations with respect to moving local coordinates.

Using translation

  • Pivot-point rotation T(p)R(θ)T(p)T(\mathbf{p}) \cdot R(\theta) \cdot T(-\mathbf{p})
  • Fixed-point scaling T(p)S(s)T(p)T(\mathbf{p}) \cdot S(\mathbf{s}) \cdot T(-\mathbf{p})
  • Scaling along arbitrary axis R(θ)S(s)R(θ)R(-\theta) \cdot S(\mathbf{s}) \cdot R(\theta)

Properties of affine transformations

Any affine transformation between 3D spaces can be represented as a combination of linear transformation followed by translation.

  • Maps parallel lines to parallel lines
  • Preserves ratios of distance along a line
  • Does not preserve absolute distances and angles
  • Does not preserve the origin

Affine transformation as a change of frame

xv0+yv1+o=xv0+yv1+o[v0v1o][xy1]=[v0v1o][xy1][v0v1o]1[v0v1o][xy1]=[xy1]\begin{align*} x\mathbf{v}_0 + y\mathbf{v}_1 + \mathbf{o} &= x'\mathbf{v}'_0 + y'\mathbf{v}'_1 + \mathbf{o}' \\ \begin{bmatrix} \mathbf{v}_0 & \mathbf{v}_1 & \mathbf{o} \end{bmatrix} \begin{bmatrix} x \\ y \\ 1\end{bmatrix} &= \begin{bmatrix} \mathbf{v}'_0 & \mathbf{v}'_1 & \mathbf{o}' \end{bmatrix} \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} \\ \begin{bmatrix} \mathbf{v}'_0 & \mathbf{v}'_1 & \mathbf{o}' \end{bmatrix}^{-1} \begin{bmatrix} \mathbf{v}_0 & \mathbf{v}_1 & \mathbf{o} \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} &= \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} \end{align*}

Rigid transformation

Rigid transformation TRT_R is a special case of affine transformation that consists of rotation and translation.

  • TRT_R preserves distances between all points. (Therefore preserves angles as well - SSS Congruence)
  • TRT_R preserves cross product for all vectors. (i.e. TRT_R is not reflection)

In 3D space, TRT_R can be represented by a 3x3 rotation matrix RR with a 3x1 translation vector.

TR(p)=R3×3p3×1+t3×1T_R(\mathbf{p}) = R_{3 \times 3}\mathbf{p}_{3 \times 1} + \mathbf{t}_{3 \times 1}

Rotation matrix

Rotation matrix rotates basis, so column vectors should be normalized and orthogonal.
Therefore RTR=IR^TR = I, i.e. R1=RTR^{-1} = R^T.

Also, we only choose matrices with a determinant of 1. Determinant of -1 means reflection!
In mathematics, rotation matrices in 3D space are called SO(3) (Special orthogonal group).

Euler angles

Any rotation matrix can be decomposed as a product of three elemental rotation matrices!

R=Rx(θ)Ry(ψ)Rz(ϕ)R = R_x(\theta)R_y(\psi)R_z(\phi)

c.f. In 2D sapce, degree of rotation is 1.
In 4D space, degree of rotation is 6???

Actually, 12 different combinations exists. Just don't rotate along same axis twice!
XYZ, XYX, XZY, XZX, YZX, YZY, YXZ, YXY, ZXY, ZXZ, ZYX, ZYZ

Problems of Euler angles

Gimbal Lock: In certain alignments of the axes, we lose degree of freedom.
Not unique: Two different euler angles can represent the same rotation.