qToEuler method

Vector3D qToEuler()

Implementation

Vector3D qToEuler() {
  // Roll (x-axis rotation)
  final x0 = 2.0*(w*x + y*z);
  final x1 = 1.0 - 2.0*(x*x + y*y);

  // Pitch (y-axis rotation)
  double y0 = 2.0*(w*y - z*x);
  y0 = y0 > 1.0 ? 1.0 : y0;
  y0 = y0 < -1.0 ? -1.0 : y0;

  // Yaw (z-axis rotation)
  final z0 = 2.0*(w*z + x*y);
  final z1 = 1.0 - 2.0*(y*y + z*z);

  return .vec3(
    math.atan2(x0, x1),
    math.asin(y0),
    math.atan2(z0, z1),
  );
}