Convert from Euler ZXZ rotation to fixed XYZ rotation axis

The problem is that I need to convert from the rotation of the fixed axis XYZ, to the Euler rotation relative to Z, then X ', then Z' '.

Here are the relevant matrices:

X: X

Y: Y

Z: Z

Combines as Rz (psi) Ry (phi) Rx (theta) = Rxyz (theta, phi, psi); they give:

Rxyz: Rxyz

And the rotation matrix for the Concrete Euler Angles Agreement I want; this:

Euler: Euler

So, my initial plan was to compare the matrix elements and extract the angles that I really wanted; I came up with this (actual current code at the end):

Code

. , Cos (theta) Cos (phi) == 1; Cos (beta) = 1, Sin [beta] = 0. Sin () s2 . , Cos () cos (phi) = +/- 1.

;

theta phi = 0, 180, 360, 540,..., Cos (theta) Cos (phi) +/- 1;

:

:

public static double[] ZXZtoEuler(double θ, double φ, double ψ){

    θ *= Math.PI/180.0;
    φ *= Math.PI/180.0;
    ψ *= Math.PI/180.0;

    double α = -1;
    double β = -1;
    double γ = -1;

    double c2 = Math.cos(θ) * Math.cos(φ);

    β = Math.acos(r(c2));

    if(eq(c2,1) || eq(c2,-1)){
        if(eq(Math.cos(θ),1)){
            if(eq(Math.cos(φ),1)){
                α = 0.0;
                γ = ψ;
            }else if(eq(Math.cos(φ),-1)){
                α = 0.0;
                γ = Math.PI - ψ;
            }
        }else if(eq(Math.cos(θ),-1)){
            if(eq(Math.cos(φ),1)){
                α = 0.0;
                γ = -ψ;
            }else if(eq(Math.cos(φ),-1)){
                α = 0.0;
                γ = ψ + Math.PI;
            }
        }
    }else{

        //original way

        double s2 = Math.sin(β);

        double c3 = ( Math.sin(θ) * Math.cos(φ) )/ s2;
        double s1 = ( Math.sin(θ) * Math.sin(ψ) + Math.cos(θ) * Math.sin(φ) * Math.cos(ψ) )/s2;

        γ = Math.acos(r(c3));
        α = Math.asin(r(s1));

    }

    α *= 180/Math.PI;
    β *= 180/Math.PI;
    γ *= 180/Math.PI;

    return new double[] {r(α), r(β), r(γ)};
}

r eq - :

public static double r(double a){
    double prec = 1000000000.0;
    return Math.round(a*prec)/prec;
}

static double thresh = 1E-4;
public static boolean eq(double a, double b){
    return (Math.abs(a-b) < thresh);
}

eq - , r - , Math.acos/Math.asin NaN;

( Math.acos(1.000000000000000004) - .)

4 x y, c2 == 1.

:

, , , ;

, - -phi psi-, - ---. , ,

[0.0, 0.0, 0.0] - correct!
[0.0, 0.0, 0.0]

[0.0, 0.0, 45.0] - correct!
[0.0, 0.0, 45.0]

[0.0, 0.0, 90.0] - correct!
[0.0, 0.0, 90.0]

[0.0, 0.0, 135.0] - correct!
[0.0, 0.0, 135.0]

[0.0, 0.0, 180.0] - correct
[0.0, 0.0, 180.0]

[0.0, 0.0, 225.0] - correct
[0.0, 0.0, 225.0]

[0.0, 0.0, 270.0] - correct
[0.0, 0.0, 270.0]

[0.0, 0.0, 315.0] - correct
[0.0, 0.0, 315.0]

[0.0, 45.0, 0.0] - incorrect: should be [90, 45, -90]
[90.0, 44.999982, 90.0]

[0.0, 45.0, 45.0]
[45.000018, 44.999982, 90.0]

[0.0, 45.0, 90.0]
[0.0, 44.999982, 90.0]

[0.0, 45.0, 135.0]
[-45.000018, 44.999982, 90.0]

[0.0, 45.0, 180.0]
[-90.0, 44.999982, 90.0]

[0.0, 45.0, 225.0]
[-45.000018, 44.999982, 90.0]

[0.0, 45.0, 270.0]
[0.0, 44.999982, 90.0]

[0.0, 45.0, 315.0]
[45.000018, 44.999982, 90.0]

[0.0, 90.0, 0.0]
[90.0, 90.0, 90.0]

[0.0, 90.0, 45.0]
[45.000018, 90.0, 90.0]

[0.0, 90.0, 90.0]
[0.0, 90.0, 90.0]

[0.0, 90.0, 135.0]
[-45.000018, 90.0, 90.0]

[0.0, 90.0, 180.0]
[-90.0, 90.0, 90.0]

[0.0, 90.0, 225.0]
[-45.000018, 90.0, 90.0]

, , Math.acos Math.asin, - ?

EDIT: math.asin math.acos -pi/2 pi/2 0 pi . , , . , - , ...

EDIT2: , , , :

Euler Angles Gif

Z, X (X '), Z'.

+5
1

, : arccos/arcsin, cos/sin , . , arccos, . , cos y = x, (, ) :

  • y = arccos x + 2kPI, k element Z
  • y = 2PI - arccos x + 2kPI, k,

k=-1

  • y = -arccos x

, y = +- arccos x. , , , cos x=0. arcsin, y = PI - asin x ( k=0 sin y = x)

. γ = Math.acos(r(c3)); - . , "" .

+1