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.
示例
语法
slerp(v, amt)
slerp(v1, v2, amt, [target])
参数
p5.Vector to slerp toward.
amount of interpolation between 0.0 (old vector) and 1.0 (new vector). 0.5 is halfway between.
old vector.
new vector.
vector to receive the result.