Vector Addition

Adding vectors together is one of simplest operation you can do. Take each x,y,z values and add them together. Mathematically speaking this means the following.

[xyz]=[x1y1z1]+[x2y2z2]    x=x1+x2y=y1+y2z=z1+z2\begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} x1 \\ y1 \\ z1 \end{bmatrix} + \begin{bmatrix} x2 \\ y2 \\ z2 \end{bmatrix} \iff \begin{matrix} x = x1 + x2\\ y = y1 + y2\\ z = z1 + z2 \end{matrix}

This is exactly what the add method does. So writing

Vector greenVector = new Vector(3, 0, 1);
Vector orangeVector = new Vector(2, 0, 3);
Vector purpleVector = greenVector.clone().add(orangeVector);

The y component is 0 because the tutorial explains 2D examples in the xz-plane.

Addition of two vectors.

You can also add arbitrary many vectors together.

Vector greenVector = new Vector(3, 0, 1);
Vector orangeVector = new Vector(-2, 0, -1);
Vector yellowVector = new Vector(-3, 0, 4);
Vector purpleVector = greenVector.clone().add(orangeVector).add(yellowVector);
Chaining additions.

Vector Addition is commonly used for ,what I call, offset vectors. So when doing operations around the origin, adding back in the actual location in the world where whatever we just calculated should take place/be shown is a key step.

Last updated