Add the rest of university notes
This commit is contained in:
366 files changed
+9844
-110
No files matched your search
@@ -0,0 +1,151 @@
|
||||
# Transformations
|
||||
|
||||
### Translation
|
||||
|
||||
Translation is done by adding/subtracting the translation distance to either the x or y (or both) component
|
||||
|
||||
A translation of $(3,2)$ done on vector $u=\begin{pmatrix} u_0\\u_1\end{pmatrix}$
|
||||
|
||||
$u'=\begin{pmatrix} u_0+3\\u_1+2\end{pmatrix}$
|
||||
|
||||
This can be applied to a triangle, where every vertex is translated by the same amount.
|
||||
|
||||
### Rotation
|
||||
|
||||
Vector $v$ can be rotated by angle $\theta$ radians anticlockwise as follows
|
||||
|
||||
$$
|
||||
rot(v) = \begin{pmatrix}
|
||||
cos\theta * v_0 - sin\theta * v_1 \\
|
||||
sin\theta * v_0 - cos\theta * v_1
|
||||
\end{pmatrix}
|
||||
$$
|
||||
|
||||

|
||||
|
||||
We can rotate triangles by rotating each vertex
|
||||
|
||||
### Scale
|
||||
|
||||
The vector $v$ can be scaled by scalar $s$ in each dimension independently
|
||||
|
||||
$$
|
||||
v \cdot s = \begin{pmatrix} v_0 \cdot s_0 \\ v_1\cdot s_1 \end{pmatrix}
|
||||
$$
|
||||
|
||||
We can scale triangles by scaling each of its vertices
|
||||
|
||||
### Transformation Matrix
|
||||
|
||||
#### Translation
|
||||
|
||||
This is where we represent a transformation in the form of a matrix
|
||||
|
||||
- The translation matrix, **T**, which translates by some vector **t** $= (t_x, t_y, t_z)$
|
||||
|
||||
$$
|
||||
T(t) = \begin{pmatrix}
|
||||
1 \quad 0 \quad 0 \quad t_x \\
|
||||
0 \quad 1 \quad 0 \quad t_y \\
|
||||
0 \quad 0 \quad 1 \quad t_z \\
|
||||
0 \quad 0 \quad 0 \quad 1
|
||||
\end{pmatrix}
|
||||
$$
|
||||
|
||||
#### Rotation
|
||||
|
||||
- The rotations around each axis by some angle $\theta$ are represented as matrices $R_x, R_y, R_z$
|
||||
- This is in 2 dimensions
|
||||
|
||||

|
||||
|
||||
#### Scale
|
||||
|
||||
$$
|
||||
S(t) = \begin{pmatrix}
|
||||
s_x \quad 0 \quad 0 \quad 0 \\
|
||||
0 \quad s_y \quad 0 \quad 0 \\
|
||||
0 \quad 0 \quad s_z \quad 0 \\
|
||||
0 \quad 0 \quad 0 \quad 1
|
||||
\end{pmatrix}
|
||||
$$
|
||||
|
||||
### Homogeneous Coordinates
|
||||
|
||||
- Vector defines a **direction** or a **position**
|
||||
- We can rotate directions and positions
|
||||
- We can scale directions and positions
|
||||
- We can only translate positions
|
||||
|
||||
A homogeneous vector is $p=(p_x, p_y, p_z, p_w)$
|
||||
|
||||
- Transforming a point $p$ is done by multiplying the vector (with $w$ set to 1) by the transformation matrix $M$
|
||||
- To transform vectors the $w$ must be set to 1
|
||||
|
||||

|
||||
|
||||
The translation matrix can be applied to point $p$ by multiplying the point by the matrix
|
||||
|
||||

|
||||
|
||||
The scale matrix can be applied to a point $p$ by multiplying the point by the matrix
|
||||
|
||||

|
||||
|
||||
The rotation around x matrix can be applied to a point $p$ by multiplying the point by the matrix
|
||||
|
||||

|
||||
|
||||
y:
|
||||
|
||||

|
||||
|
||||
z:
|
||||
|
||||

|
||||
|
||||
#### Combining Transformations
|
||||
|
||||
For example if point $p$ needs to be scaled by $s=(2,1,1)$ and then translated by $t=(1,0,0)$
|
||||
|
||||
$$
|
||||
S = \begin{pmatrix}
|
||||
2 \quad 0 \quad 0 \quad 0 \\
|
||||
0 \quad 1 \quad 0 \quad 0 \\
|
||||
0 \quad 0 \quad 1 \quad 0 \\
|
||||
0 \quad 0 \quad 0 \quad 1
|
||||
\end{pmatrix}
|
||||
\\\\
|
||||
T = \begin{pmatrix}
|
||||
1 \quad 0 \quad 0 \quad 1 \\
|
||||
0 \quad 1 \quad 0 \quad 0 \\
|
||||
0 \quad 0 \quad 1 \quad 0 \\
|
||||
0 \quad 0 \quad 0 \quad 1
|
||||
\end{pmatrix}
|
||||
\\\\
|
||||
TS = T\times S =
|
||||
\begin{pmatrix}
|
||||
2 \quad 0 \quad 0 \quad 1 \\
|
||||
0 \quad 1 \quad 0 \quad 0 \\
|
||||
0 \quad 0 \quad 1 \quad 0 \\
|
||||
0 \quad 0 \quad 0 \quad 1
|
||||
\end{pmatrix}
|
||||
$$
|
||||
|
||||
Matrix multiplication is read from right to left
|
||||
|
||||
The order of the transformations makes a difference and can change the resulting vector for example
|
||||
|
||||
$$
|
||||
ST = S\times T =
|
||||
\begin{pmatrix}
|
||||
2 \quad 0 \quad 0 \quad 2 \\
|
||||
0 \quad 1 \quad 0 \quad 0 \\
|
||||
0 \quad 0 \quad 1 \quad 0 \\
|
||||
0 \quad 0 \quad 0 \quad 1
|
||||
\end{pmatrix}
|
||||
$$
|
||||
|
||||

|
||||
|
||||
The difference between translating and scaling vs scaling and translating vector $v$
|
||||
Reference in new issue
Block a user