2.9 KiB
Mathematics for Graphics
Vectors
- The n-dimensional Euclidean Space is
\mathbb{R}^n\mathbb{R}^n = \{(v_0, v_1, ... v_{n-1}) | v_0, v_1, ...v_{n-1} \in \mathbb{R}\}
- A vector is an n-turple
v\in \mathbb{R}^n \Longleftrightarrow v=(v_0, v_1, ...v_{n-1}) | v_0, v_1, ...v_{n-1} \in \mathbb{R}- In computer graphics we normally deal with 3-Dimensional Euclidean space
\mathbb{R}^3- vec3 notation:
v=(v_0, v_1, v_2)v = \begin{pmatrix} {v_0}\\{v_1}\\{v_2} \end{pmatrix}
- Where
v_0represents x,v_1represents y, andv_2represents z axis
- vec3 notation:
Vector Scaling
Each element of v is scaled independently by s. Only the length is changed
v\cdot s = \begin{pmatrix} {v_0\cdot s}\\{v_1\cdot s}\\{v_2\cdot s} \end{pmatrix}
Vector Addition
v + u = \begin{pmatrix} {v_0+u_0}\\{v_1+u_1}\\{v_2+u_2} \end{pmatrix}
Vector Length
||v|| = \sqrt{v_0^2 + v_1^2 + v_2^2}
Vector Normalisation
To change the length of the vector to 1.
\frac{1}{||v||} \cdot v
\hat{v} is the notation for a normalised vector
Dot Product
u\cdot v = \sum_{i=0}^{n-1} u_i \times v_i
or u\cdot v = (u_0 * v_0) + (u_1 * v_1) + (u_2 * v_2)
The dot product is also defined in \mathbb{R}^2 and \mathbb{R}^3 as:
u\cdot v = ||u||\times||v||cos\theta
where \theta is the smallest angle between u and v
If the dot product is 0: the two vectors are perpendicular
If the dot product is positive: 0 \leq \theta \leq \frac{\pi}{2}
If the dot product is negative: \frac{\pi}{2} \leq \theta \leq \pi
Cross Product
In \mathbb{R}^3 cross product is defined as follows:
u \times v = \begin{pmatrix}
(u_1 * v_2)-(u_2*v_1)\\
(u_2 * v_0)-(u_0*v_2)\\
(u_0 * v_1)-(u_1*v_0) \end{pmatrix}
Matrices
Identity Matrix
\begin{pmatrix}
1 \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}
Transpose of a Matrix
Turns each row into a column
Matrix addition
Matrix Multiplication
Two matrices can only be multiplied if they both have the same number of columns and rows.
To get the resulting matrix, for each (x,y) pair, is the cross product of the x^{th} column and the y^{th} row.
- Matrix multiplication is not communative
MN \neq NM
Matrix-Vector Multiplication
A matrix multiplied by vector gives new vector
Each row of the resulting vector is that row of the vector, dot producted with that row on the matrix.
Trigonometry
If p=(p_x, p_y) is a unit vector, we can write them as:
p_x = cos \space \alpha \\
p_y = sin \space \alpha
sin \space \alpha = \frac{opp}{hyp} \\
cos \space \alpha = \frac{adj}{hyp} \\
tan \space \alpha = \frac{opp}{adj} \\
hyp^2 = opp^2 + adj^2

