vmult method

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

Multiply the quaternion by a vector

Implementation

Vector3 vmult(Vector3 v, [Vector3? target]){
target ??= Vector3.zero();
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;
  }