Skip to content

4600 Notes 2-1 (9/4)

Published: at 07:58 PM

Points and Vectors

A point represents a position, while a vector represents a direction, or a change in position. Typically, both are written vertically. $$ x = (10, 5) $$ $$ \vec{v} = (2, 1) $$ Both, of course, have component-based addition and subtraction. Vectors also have some special properties.

Matrix Notation

A matrix is an $n \times m$ grid of values. $$ \begin{bmatrix} 1 & 3 \ 4 & 12 \ 1 & 5 \end{bmatrix} $$ It has the following functions:

Dot Product

A dot product can be thought of as the length of the projection of one vector onto the other vector. This means that dot product is a really nice way of telling the similarity of two vectors. $$ \vec{v_1} \cdot \vec{v_2} = |\vec{v_1}||\vec{v_2}|cos(\theta) = v_1(x)v_2(x) + v_1(y)v_2(y) $$ You’ll find that the dot product of two vectors facing directly away from each other is $-1$, two that are perpendicular to each other is $0$, and two that are parallel is $1$.

Cross Product

The cross product is an operation defined on only 3 dimensional vectors. You’ll see it used on 2D vectors, but in this case, the third dimension is assumed to be $0$. $$ \vec{v_1} \cdot \vec{v_2} = |\vec{v_1}||\vec{v_2}|sin(\theta) = \begin{bmatrix} y_1z_2 - y_2z_1 \ z_1x_2 - z_2x_1 \ x_1y_2 - x_2y_1 \end{bmatrix} $$ The cross product creates a vector that is orthogonal to both input vectors. The length of this vector is the area of the parallelogram created by the two input vectors. When vectors are parallel or antiparallel(facing away from each other), the cross product is 0.

Transformation Matrices

In graphics, the three general transformations, translation, rotation, and scale(dilation), are represented through transformation matrices.

Scaling

Given a vector $( x, y, z )$, if you wanted to scale it by $( s_x, s_y, s_z )$, then you would multiply it by the following matrix: $$ \begin{bmatrix} s_x & 0 \ 0 & s_y \end{bmatrix} \begin{bmatrix} x \ y \end{bmatrix} = \begin{bmatrix} s_x \times x \ s_y \times y \end{bmatrix} $$ Note that the initial positions of vertices matter, as these transformations scale from $(0, 0)$. So, a point at $(5, 0)$ would never change position if scaled along the y component, even by a million. A million times zero is still zero.

Rotation in 2D

Rotation of a 2D vector by $\theta$ counter clockwise looks like such: $$ \begin{bmatrix} cos(\theta) & -sin(\theta) \ sin(\theta) & cos(\theta) \end{bmatrix} $$ This is relatively straightforward, but if you’d like you can test it on $0\degree$, $90\degree$, and other common rotation values to see how it affects vectors.

Translation

If you think about it, you could just add a vector to a type to translate it from its current point. However, we actually don’t do this in graphics for two very good reasons:

Therefore, we must use a matrix for translation. However, it turns out that this doesn’t work. It is impossible to represent a translation as a 2D transformation matrix. We have to use another tool.

Homogeneous Coordinates

To do this, we add an extra coordinate to every point: $$ \begin{bmatrix} x \ y \ w \end{bmatrix} \to \begin{bmatrix} x/w \ y/w \end{bmatrix} $$ A regular coordinate of $x, y$ would look like this: $$ \begin{bmatrix} x \ y \end{bmatrix} \to \begin{bmatrix} x \ y \ 1 \end{bmatrix} $$ Now, we can represent a translation of $t_x, t_y$ like this: $$ \begin{bmatrix} 1 & 0 & t_x \ 0 & 1 & t_y \ 0 & 0 & 1 \ \end{bmatrix} \begin{bmatrix} x \ y \ 1 \end{bmatrix} = \begin{bmatrix} t_x + x \ t_y + y \ 1 \end{bmatrix} $$ If you try making the homogeneous coordinate of the vector 0, you’ll find that the transformation actually doesn’t apply. This sort of acts as an indicator for whether a type is a point or vector, because vectors should not be translated(as that would be a translation of a plane). Therefore, a vector should have a homogeneous value of 0, while a point should have a homogeneous value of 1.

3D Vectors and Matrices

3D vectors and matrices generally follow from 2D vectors and matrices. Homogeneous vectors now have 4 coordinates. Scaling is trivial. Rotation has two new axes, however, represented as a rotation by $\alpha, \beta, \gamma$. There is a very complex formula for it which can be found here.