Computer Graphics
Transformations
In computer graphics, transformations are used to manipulate objects in a scene. The most common transformations include translation, rotation, and scaling. These transformations can be represented using matrices, which allows for efficient computation and combination of multiple transformations.
2D
Scale
Suppose we hava a point $(x, y)$ in 2D space. To scale this point by a factor of $s$, we can use the following transformation matrix:
\[\begin{bmatrix} x'\\ y' \end{bmatrix} = \begin{bmatrix} s_x & 0 \\ 0 & s_y \end{bmatrix} \begin{bmatrix} x\\ y \end{bmatrix}\]Shear
Suppose we have a point $(x, y)$ in 2D space. To shear this point by factors $s_x$ and $s_y$ we can use the following transformation matrix:
\[\begin{bmatrix} x'\\ y' \end{bmatrix} = \begin{bmatrix} 1 & s_x \\ s_y & 1 \end{bmatrix} \begin{bmatrix} x\\ y \end{bmatrix}\]Rotate
To rotate a point $(x, y)$ around the origin by an angle $\theta$, we can use the following transformation matrix:
\[\begin{bmatrix} x'\\ y' \end{bmatrix} = \begin{bmatrix} \cos{\theta} & -\sin{\theta} \\ \sin{\theta} & \cos{\theta} \end{bmatrix} \begin{bmatrix} x\\ y \end{bmatrix}\]Translate
To translate a point $(x, y)$ by a vector $(t_x, t_y)$, we can use the following transformation matrix:
Add a third coordinate (w-coordinate) to represent the point in homogeneous coordinates:
- 2D point $[x, y]$ becomes $[x, y, 1]^{T}$.
- 2D vector $[x, y, 0]^{T}$
Affine
An affine transformation is a combination of linear transformations (like rotation, scaling, and shearing) and translation. It can be represented using a 3x3 matrix in homogeneous coordinates to operate a point in 2D space.
An affine transformation matrix in 2D can be represented as:
\[\begin{bmatrix} x' \\ y' \\ 1 \\ \end{bmatrix} = \begin{bmatrix} a & b & t_x \\ c & d & t_y \\ 0 & 0 & 1 \\ \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \\ \end{bmatrix}\]3D
Rotate
To rotate a point $(x, y, z)$ around the origin by angles $\alpha$, $\beta$, and $\gamma$ around the x, y, and z axes respectively, we can use the following transformation matrices:
\[\begin{align*} R_x(\alpha) &= \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos{\alpha} & -\sin{\alpha} & 0 \\ 0 & \sin{\alpha} & \cos{\alpha} & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \\ R_y(\beta) &= \begin{bmatrix} \cos{\beta} & 0 & \sin{\beta} & 0 \\ 0 & 1 & 0 & 0 \\ -\sin{\beta} & 0 & \cos{\beta} & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \\ R_z(\gamma) &= \begin{bmatrix} \cos{\gamma} & -\sin{\gamma} & 0 & 0 \\ \sin{\gamma} & \cos{\gamma} & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \\ R_{xyz}(\alpha, \beta, \gamma) &= R_z(\gamma) R_y(\beta) R_x(\alpha) \end{align*}\]Rodrigues’ Rotation Formula
Rotation by angle $\alpha$ around axis n
\[\bold{R}(\bold{n}, \alpha) = cos(\alpha)\bold{I} + (1 - \cos(\alpha)) \bold{nn^T} + \sin{\alpha} \bold{N}\]