# Kapitel 2_e:
# Eulerwinkel (, , ) 
#  2015 Friedrich U. Mathiak, 
# mathiak@mechanik-info.de
# 
> interface(displayprecision=5): restart: with(LinearAlgebra):
# Beispiel: 2-12:
# Es wird eine Maple-Prozedur zur Verfgung gestellt, die bei Vorgabe der Eulerwinkel (, , ,) die Drehmatrix TE berechnet. 
> Proc_Calc_11:=proc(EW::list,flag::integer)
> #-------------------------------------------------------
> # Eingabe: 
> #        EW:     Eulerschen Winkel [psi, theta, phi] 
> #      flag:     flag = 0 : Winkel im Gradma
> #                flag = 1 : Winkel in Radiant
> # Ausgabe: 
> #           RE   : Drehmatrix TE(psi,theta,phi)
> #--------------------------------------------------------
> local w,fak,Lambda,Phi,i,k,nn;
> global R3psi,R1tet,R3phi,RE,N;
> description "Berechnung der Drehmatrix TE mittels der Eulerschen Winkel";
> if   flag = 0 then fak:=Pi/180;
> elif flag = 1 then fak:=1;
> else
>   print(`Whlen Sie\nflag = 0 (Winkel im Gradma)\nflag = 1 (Winkel im Bogenma)`); return;
> end if;
> w    := [seq(fak*EW[i],i=1..3)];
> R3psi:= Matrix([[cos(w[1]),-sin(w[1]),0],[sin(w[1]),cos(w[1]),0         ],[0,0        ,1        ]]);
> R1tet:= Matrix([[1        ,0         ,0],[0        ,cos(w[2]),-sin(w[2])],[0,sin(w[2]),cos(w[2])]]);
> R3phi:= Matrix([[cos(w[3]),-sin(w[3]),0],[sin(w[3]),cos(w[3]),0         ],[0,0        ,1        ]]);
> RE   := R3psi.R1tet.R3phi;
> print(`RE    = `,eval(RE)   );
> end proc:
# Um die Prozedur fr nachfolgende Arbeitsbltter anwendbar zu machen, speichern wir diese ab.
> save Proc_Calc_11, "Proc_Calc_11.m":
# Entsprechend der Aufgabenstellung ist
> Proc_Calc_11([psi,theta,phi],1):
> WE:=[30,135,210]:         Proc_Calc_11(WE,0):    # Winkel im Gradma
;
> WE:=[Pi/6,3/4*Pi,7/6*Pi]: Proc_Calc_11(WE,1):    # Dieselben Winkel im Bogenma
;
# Beispiel: 2-13:
# Es wird eine Maple-Prozedur zur Verfgung gestellt, die bei Vorgabe der Drehmatrix  TE(,,)  die Eulerwinkel (, , ) berechnet. 
> Proc_Calc_12:=proc(R::Matrix)
> #-----------------------------------------------------------------------------------
# #  Eingabe:
# #      R   : Drehmatrix 
> 
> #  Ausgabe:
> #      Eulerwinkel (psi, theta, phi)
> #-----------------------------------------------------------------------------------
> local cd,Z,zn,eps,R1,R2,R3,psi,theta,phi,cps,cth,cph,sps,sth,sph,Rps,Rth,Rph,i,j,a,b,g;
> global RE,gl,loe;
> description "Berechnung der Eulerwinkel aus der Drehmatrix";
> #Es wird zunchst geprft, ob R orthogonal ist.
> cd := LinearAlgebra[ColumnDimension](R):
> Z  := R.LinearAlgebra[Transpose](R) - Matrix(cd,shape=identity);
> zn := LinearAlgebra[MatrixNorm](Z,Frobenius);
> eps:= 10.^(-Digits+2);
> if zn > eps then
>   print(`Drehmatrix ist nicht orthogonal`); return;
> end if;
> #Es wird geprft, ob R ein uneigentlicher Versor ist. In diesem Fall 
> #liegt eine Klappung mit phi=(+,-)Pi/2 vor und die Berechnung wird abgebrochen. 
> R1:=evalf(LinearAlgebra[Trace](R));
> if abs(R1 + 1) < eps then
>   print(`Es liegt mit der Drehmatrix eine Umklappung vor`); return;
> end if;
> #Berechnung der Hauptinvarianten R2 und R3
> R2:=0.5*(R1^2-LinearAlgebra[Trace](R.R)):
> R3:=LinearAlgebra[Determinant](R):
> #Aufbau der Drehmatrix
> cps:=cos(psi): cth:=cos(theta): cph:=cos(phi): 
> sps:=sin(psi): sth:=sin(theta): sph:=sin(phi):
> Rps:= Matrix(3,3,[[cps,-sps,  0], [sps,cps,   0],[0,  0,  1]]):
> Rth:= Matrix(3,3,[[1  ,   0,  0], [0  ,cth,-sth],[0,sth,cth]]):
> Rph:= Matrix(3,3,[[cph,-sph,  0], [sph,cph,   0],[0,  0,  1]]):
> RE := Rps.Rth.Rph:
> #Berechnung der Eulerwinkel
> gl:={}:
> for i to 3 do 
>   for j to 3 do
>     gl:=gl union {R[i,j]-RE[i,j]}:
>   end do:
> end do:
> loe:=solve(gl,[psi,theta,phi]);
> print(`Eulerwinkel in rad = `,allvalues(loe));
> end proc:
# Um die Prozedur fr nachfolgende Arbeitsbltter anwendbar zu machen, speichern wir diese ab.
> save Proc_Calc_12, "Proc_Calc_12.m":
# Entsprechend der Aufgabenstellung ist
> w:=sqrt(3):
> TE:=1/8*Matrix([[6+w,3-2*w,2],[3-2*w,2+3*w,2*w],[-2,-2*w,4*w]]);
> Proc_Calc_12(TE);
> loe[1];loe[2];
# Beide Lsungen fhren selbstverstndlich auf  dieselbe Drehmatrix. 
> 
;
