Reference setMag()

setMag()

Sets a vector's magnitude to a given value.

The static version of setMag(), as in p5.Vector.setMag(v, 10), returns a new p5.Vector object and doesn't change the original.

Examples

Syntax

setMag(len)
setMag()
setMag(v, len, [target])

Parameters

len
Number: new length for this vector.
v
p5.Vector: the vector to set the magnitude of
target
p5.Vector: the vector to receive the result (Optional)

Returns

p5.Vector: v with a magnitude set to len
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