参考 div()

div()

Divides a vector's x, y, and z 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. If a value isn't provided for a component, it won't change. For example, v.div(4, 5) divides v.x by, v.y by 5, and v.z by 1. Calling div() with no arguments, as in v.div(), has no effect.

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

示例

语法

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

参数

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.

target
p5.Vector:

The vector to receive the result

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

相关参考