slerp function

List<double> slerp(
  1. List<double> out,
  2. List<double> a,
  3. List<double> b,
  4. double t,
)

Performs a spherical linear interpolation between two vec3's

@param {vec3} out the receiving vector @param {ReadonlyVec3} a the first operand @param {ReadonlyVec3} b the second operand @param {Number} t interpolation amount, in the range 0-1, between the two inputs @returns {vec3} out

Implementation

List<double> slerp(List<double> out, List<double> a, List<double> b, double t) {
  final angle = math.acos(math.min(math.max(dot(a, b), -1), 1));
  final sinTotal = math.sin(angle);

  final ratioA = math.sin((1 - t) * angle) / sinTotal;
  final ratioB = math.sin(t * angle) / sinTotal;
  out[0] = ratioA * a[0] + ratioB * b[0];
  out[1] = ratioA * a[1] + ratioB * b[1];
  out[2] = ratioA * a[2] + ratioB * b[2];

  return out;
}