invert method

Q invert()

Returns the inverse (conjugate divided by squared length) of this quaternion.

Returns this unchanged if the squared length is zero.

Implementation

Q invert() {
  final lengthSq = x*x + y*y + z*z + w*w;

  if (lengthSq != 0.0) {
    final invLength = 1.0/lengthSq;

    return _q(
      x * -invLength,
      y * -invLength,
      z * -invLength,
      w * invLength,
    );
  }

  return _this;
}