vmult method

Vec3 vmult(
  1. Vec3 v, [
  2. Vec3? target
])

Multiply the quaternion by a vector

Implementation

Vec3 vmult(Vec3 v, [Vec3? target]){
  target ??= Vec3();
  final x = v.x;
  final y = v.y;
  final z = v.z;

  final qx = this.x;
  final qy = this.y;
  final qz = this.z;
  final qw = w;

  // q*v
  final ix = qw * x + qy * z - qz * y;

  final iy = qw * y + qz * x - qx * z;
  final iz = qw * z + qx * y - qy * x;
  final iw = -qx * x - qy * y - qz * z;

  target.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  target.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  target.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;

  return target;
}