title |
date |
abbrlink |
gitrep |
tags |
GAMES101-03 Transformation |
2021/5/1 22:46:25 |
games101-03 |
games101-note |
|
{% mmedia "bilibili" "bvid:BV1X7411F744" "page=3" %}
Modeling: translation, rotation, scaling
viewing: (3D to 2D) projection
Linear Transforms = Matrices(of the same dimension)
include Scale,Reflection,Shear,Rotate
$$
\begin{aligned}
x^{\prime} &=a x+b y \\
y^{\prime} &=c x+d y \\
{\left[\begin{array}{c}
x^{\prime} \ y^{\prime}
\end{array}\right] } &=
\left[\begin{array}{ll}
a & b \ c & d
\end{array}\right]
\left[\begin{array}{l}
x \ y
\end{array}\right] \\
\mathbf{x}^{\prime} &=\mathbf{M} \mathbf{x}
\end{aligned}
$$
cannot be represented in matrix form
$$
\left[\begin{array}{l}
x^{\prime} \ y^{\prime}
\end{array}\right]=\left[\begin{array}{ll}
a & b \ c & d
\end{array}\right]\left[\begin{array}{l}
x \ y
\end{array}\right]+\left[\begin{array}{l}
t_{x} \ t_{y}
\end{array}\right]
$$
So, translation is NOT linear transform
Add a third coordinate (w-coordinate)
- 2D point = $(x, y, 1)^T$
- 2D vector = $(x, y, 0)^T$
Matrix representation of translations
$$
\left(\begin{array}{c}
x^{\prime} \\
y^{\prime} \\
w^{\prime}
\end{array}\right)=\left(\begin{array}{ccc}
1 & 0 & t_{x} \\
0 & 1 & t_{y} \\
0 & 0 & 1
\end{array}\right) \cdot\left(\begin{array}{l}
x \\
y \\
1
\end{array}\right)=\left(\begin{array}{c}
x+t_{x} \\
y+t_{y} \\
1
\end{array}\right)
$$
Valid operation if w-coordinate of result is 1 or 0
- vector + vector = vector
- point – point = vector
- point + vector = point
- point + point = ??
In homogeneous coordinates
$$
\left(\begin{array}{c}
x \\
y \\
w
\end{array}\right) \text { is the 2D point }\left(\begin{array}{c}
x / w \\
y / w \\
1
\end{array}\right), w \neq 0
$$
so, point1 + point2, is also the center of the two point
Affine map = linear map + translation
$$
\left(\begin{array}{l}
x^{\prime} \\
y^{\prime}
\end{array}\right)=\left(\begin{array}{ll}
a & b \\
c & d
\end{array}\right) \cdot\left(\begin{array}{l}
x \\
y
\end{array}\right)+\left(\begin{array}{l}
t_{x} \\
t_{y}
\end{array}\right)
$$
$$
\left(\begin{array}{l}
x^{\prime} \\
y^{\prime} \\
1
\end{array}\right)=\left(\begin{array}{ccc}
a & b & t_{x} \\
c & d & t_{y} \\
0 & 0 & 1
\end{array}\right) \cdot\left(\begin{array}{l}
x \\
y \\
1
\end{array}\right)
$$
$$
\mathbf{S}\left(s_{x}, s_{y}\right)=\left(\begin{array}{ccc}
s_{x} & 0 & 0 \\
0 & s_{y} & 0 \\
0 & 0 & 1
\end{array}\right)
$$
$$
\mathbf{R}(\alpha)=\left(\begin{array}{ccc}
\cos \alpha & -\sin \alpha & 0 \\
\sin \alpha & \cos \alpha & 0 \\
0 & 0 & 1
\end{array}\right)
$$
$$
\mathbf{T}\left(t_{x}, t_{y}\right)=\left(\begin{array}{ccc}
1 & 0 & t_{x} \\
0 & 1 & t_{y} \\
0 & 0 & 1
\end{array}\right)
$$
Sequence of affine transforms A1, A2, A3, ...
- Compose by matrix multiplication
- Very important for performance
$$
\begin{aligned}
A_{n}\left(\ldots A_{2}\left(A_{1}(\mathbf{x})\right)\right)=& \mathbf{A}{n} \cdots \mathbf{A}{2} \cdot \mathbf{A}_{1} \cdot\left(\begin{array}{l}
x \
y \
1
\end{array}\right)
\end{aligned}
$$
Pre-multiply n matrices to obtain a single matrix representing combined transform
How to rotate around a given point c?
{% note info %}
the right matrix is first!then the left!$\mathbf{T}(\mathbf{c}) \cdot \mathbf{R}(\alpha) \cdot \mathbf{T}(-\mathbf{c})$
{% endnote %}