Reference sub()

sub()

Subtracts from a vector's x, y, and z components.

sub() can use separate numbers, as in v.sub(1, 2, 3), another p5.Vector object, as in v.sub(v2), or an array of numbers, as in v.sub([1, 2, 3]).

If a value isn't provided for a component, it won't change. For example, v.sub(4, 5) subtracts 4 from v.x, 5 from v.y, and 0 from v.z. Calling sub() with no arguments, as in v.sub(), has no effect.

The static version of sub(), as in p5.Vector.sub(v2, v1), returns a new p5.Vector object and doesn't change the originals.

Examples

Syntax

sub(x, [y], [z])
sub(value)
sub(v1, v2, [target])

Parameters

x
Number:

x component of the vector to subtract.

y
Number:

y component of the vector to subtract.

z
Number:

z component of the vector to subtract.

value
p5.Vector|Number[]:

the vector to subtract

v1
p5.Vector:

A p5.Vector to subtract from

v2
p5.Vector:

A p5.Vector to subtract

target
p5.Vector:

vector to receive the result.

Notice any errors or typos? Please let us know. Please feel free to edit src/math/p5.Vector.js and open a pull request!

Related References