Reference div()

div()

Divides a vector's components.

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

If only one value is provided, as in v.div(2), then all the components will be divided by 2. Calling div() with no arguments, as in v.div(), has no effect.

You should divide vectors only when they are the same size. When two vectors of different sizes are divided, the smaller dimension will be used, any additional values of the longer vector will be ignored. For example, dividing [8, 12, 21] by [2, 3] will result in [4, 4].

The static version of div(), as in p5.Vector.div(v, 2), returns a new p5.Vector object and doesn't change the originals.

Examples

Syntax

div(n)
div(x, y, [z])
div(arr)
div(v)

Parameters

n
Number: The number to divide the vector by
x
Number: number to divide with the x component of the vector.
y
Number: number to divide with the y component of the vector.
z
Number: number to divide with the z component of the vector.
arr
Number[]: array to divide the components of the vector by.
v
p5.Vector: vector to divide the components of the original vector by.
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