add()

Adds to a vector's x, y, and z components.

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

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

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

Ejemplos

Sintaxis

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

Parámetros

x
Number:

x component of the vector to be added.

y
Number:

y component of the vector to be added.

z
Number:

z component of the vector to be added.

value
p5.Vector|Number[]:

The vector to add

v1
p5.Vector:

A p5.Vector to add

v2
p5.Vector:

A p5.Vector to add

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!

Referencias Relacionadas