Vector Subtraction

Subtraction is very similar to addition. The subtract method does the following.

[xyz]=[x1y1z1][x2y2z2]    x=x1x2y=y1y2z=z1z2\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}

Graphically speaking you take the subtrahend (the vector on the right side of the - ) and invert it. Then it's just regular addition with the inverted vector.

Inverting a vector means multiplying it with -1 .

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

Subtraction is commonly used when finding the vector between two locations/entities.

Last updated