Reference slerp()

slerp()

Calculates a new heading and magnitude that are between two vectors.

The amt parameter is the amount to interpolate between the old vector and the new vector. 0.0 keeps the heading and magnitude equal to the old vector's, 0.5 sets them halfway between, and 1.0 sets the heading and magnitude equal to the new vector's.

slerp() differs from lerp() because it interpolates magnitude. Calling v0.slerp(v1, 0.5) sets v0's magnitude to a value halfway between its original magnitude and v1's. Calling v0.lerp(v1, 0.5) makes no such guarantee.

The static version of slerp(), as in p5.Vector.slerp(v0, v1, 0.5), returns a new p5.Vector object and doesn't change the original.

Examples

Syntax

slerp(v, amt)
slerp(v1, v2, amt, [target])

Parameters

v
p5.Vector:

p5.Vector to slerp toward.

amt
Number:

amount of interpolation between 0.0 (old vector) and 1.0 (new vector). 0.5 is halfway between.

v1
p5.Vector:

old vector.

v2
p5.Vector:

new vector.

target
p5.Vector:

vector to receive the result.

Returns

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!

Related References