toEuler method
Returns an euler angel (YXZ order) representation of this quaternion.
Implementation
Map<String,dynamic> toEuler(Map<String,dynamic> euler ) {
// from 3D Math Primer for Graphics and Game Development
// 8.7.6 Converting a Quaternion to Euler Angles
// extract pitch
final sp = - 2 * ( y * z - x * w );
// check for gimbal lock
if ( sp.abs() > 0.9999 ) {
// looking straight up or down
euler['x'] = math.pi * 0.5 * sp;
euler['y'] = math.atan2( x * z + w * y, 0.5 - x * x - y * y );
euler['z'] = 0;
}
else { //todo test
euler['x'] = math.asin( sp );
euler['y'] = math.atan2( x * z + w * y, 0.5 - x * x - y * y );
euler['z'] = math.atan2( x * y + w * z, 0.5 - x * x - z * z );
}
return euler;
}