mult method

Quaternion mult(
  1. Quaternion quat, [
  2. Quaternion? target
])

Multiply the quaternion with an other quaternion.

Implementation

Quaternion mult(Quaternion quat, [Quaternion? target]){
  target ??= Quaternion();
  final ax = x;
  final ay = y;
  final az = z;
  final aw = w;
  final bx = quat.x;
  final by = quat.y;
  final bz = quat.z;
  final bw = quat.w;

  target.x = ax * bw + aw * bx + ay * bz - az * by;
  target.y = ay * bw + aw * by + az * bx - ax * bz;
  target.z = az * bw + aw * bz + ax * by - ay * bx;
  target.w = aw * bw - ax * bx - ay * by - az * bz;

  return target;
}