### sub()

#### Description

Subtracts x, y, and z components from a vector, subtracts one vector from another, or subtracts two independent vectors. The version of the method that substracts two vectors is a static method and returns a PVector, the others act directly on the vector. See the examples for more context. In all cases, the second vector (v2) is subtracted from the first (v1), resulting in v1‑v2.

#### Examples

• ``````PVector v1, v2;

void setup() {
noLoop();
v1 = new PVector(40, 20, 0);
v2 = new PVector(65, 70, 0);
}

void draw() {
ellipse(v1.x, v1.y, 12, 12);
ellipse(v2.x, v2.y, 12, 12);
v2.sub(v1);
ellipse(v2.x, v2.y, 24, 24);
}
``````
• ``````PVector v;

void setup() {
noLoop();
v = new PVector(65, 70, 0);
}

void draw() {
ellipse(v.x, v.y, 12, 12);
ellipse(40, 20, 12, 12);
v.sub(40, 20, 0);
ellipse(v.x, v.y, 24, 24);
}
``````
• ``````PVector v1, v2;

void setup() {
noLoop();
v1 = new PVector(65, 70, 0);
v2 = new PVector(40, 20, 0);
}

void draw() {
ellipse(v1.x, v1.y, 12, 12);
ellipse(v2.x, v2.y, 12, 12);
PVector v3 = PVector.sub(v1, v2);
ellipse(v3.x, v3.y, 24, 24);
}
``````

#### Syntax

• `.sub(v)`
• `.sub(x, y)`
• `.sub(x, y, z)`
• `.sub(v1, v2)`
• `.sub(v1, v2, target)`

#### Parameters

• `v``(PVector)`any variable of type PVector
• `x``(float)`the x component of the vector
• `y``(float)`the y component of the vector
• `z``(float)`the z component of the vector
• `v1``(PVector)`the x, y, and z components of a PVector object
• `v2``(PVector)`the x, y, and z components of a PVector object
• `target``(PVector)`PVector in which to store the result

#### Return

• `PVector`