Fractrace.Geometry.VecRotation.toEuler C# (CSharp) Method

toEuler() public method

Converts the Rotation in Euler Axis
public toEuler ( double &heading, double &attitude, double &bank ) : void
heading double The heading.
attitude double The attitude.
bank double The bank.
return void
        public void toEuler(ref double heading, ref double attitude, ref double bank)
        {
            toQuaternion();
            double w = Angle;
            // Test nach:
            // http://www.euclideanspace.com/maths/geometry/rotations/euler/AndyGoldstein.htm
            double test = 2 * w * Y - 2 * X * Z;
            if (test > 1)
            {
                attitude = Math.Asin(1);
            }
            else
                attitude = Math.Asin(2 * w * Y - 2 * X * Z);

            heading = Math.Atan2(2 * w * Z + 2 * X * Y, w * w + X * X - Y * Y - Z * Z);

            bank = Math.Atan2(2 * w * X + 2 * Y * Z, w * w - X * X - Y * Y + Z * Z);
            toAxisAngle();
        }

Usage Example

Esempio n. 1
0
        void RotateZ(double angle)
        {
            Fractrace.Geometry.VecRotation rotation = new VecRotation();
            rotation.FromEuler(Math.PI * ParameterDict.Current.GetDouble("Transformation.Camera.AngleX") / 180.0,
                Math.PI * ParameterDict.Current.GetDouble("Transformation.Camera.AngleY") / 180.0,
                Math.PI * ParameterDict.Current.GetDouble("Transformation.Camera.AngleZ") / 180.0);

            rotation.Normalize();
            rotation.combine(0, 0, angle);

            double ax = 0, ay = 0, az = 0;
            rotation.toEuler(ref ax, ref ay, ref az);

            ax = 180 * ax / Math.PI;
            ay = 180 * ay / Math.PI;
            az = 180 * az / Math.PI;

            ParameterDict.Current.SetDouble("Transformation.Camera.AngleX", ax);
            ParameterDict.Current.SetDouble("Transformation.Camera.AngleY", ay);
            ParameterDict.Current.SetDouble("Transformation.Camera.AngleZ", az);
        }