QuaternionFromEuler function

Quaternion QuaternionFromEuler(
  1. double pitch,
  2. double yaw,
  3. double roll
)

From Euler angles pitch (X), yaw (Y), roll (Z) in radians — ZYX order.

Implementation

Quaternion QuaternionFromEuler(double pitch, double yaw, double roll) {
  final x0 = math.cos(pitch * 0.5), x1 = math.sin(pitch * 0.5);
  final y0 = math.cos(yaw * 0.5), y1 = math.sin(yaw * 0.5);
  final z0 = math.cos(roll * 0.5), z1 = math.sin(roll * 0.5);
  return Quaternion(
    x1 * y0 * z0 - x0 * y1 * z1,
    x0 * y1 * z0 + x1 * y0 * z1,
    x0 * y0 * z1 - x1 * y1 * z0,
    x0 * y0 * z0 + x1 * y1 * z1,
  );
}