euler.h

Go to the documentation of this file.
00001 /**** EulerAngles.h - Support for 24 angle schemes ****/
00002 /* Ken Shoemake, 1993 */
00003 #ifndef _H_EulerAngles
00004 #define _H_EulerAngles
00005 
00006 /*** Definitions ***/
00007 typedef struct {float x, y, z, w;} QuatX; /* Quaternion */
00008 enum QuatPart {X, Y, Z, W};
00009 typedef float HMatrix[4][4]; /* Right-handed, for column vectors */
00010 typedef QuatX EulerAngles;    /* (x,y,z)=ang 1,2,3, w=order code  */
00011 
00012 /*** Order type constants, constructors, extractors ***/
00013     /* There are 24 possible conventions, designated by:    */
00014     /*    o EulAxI = axis used initially                    */
00015     /*    o EulPar = parity of axis permutation             */
00016     /*    o EulRep = repetition of initial axis as last     */
00017     /*    o EulFrm = frame from which axes are taken        */
00018     /* Axes I,J,K will be a permutation of X,Y,Z.           */
00019     /* Axis H will be either I or K, depending on EulRep.   */
00020     /* Frame S takes axes from initial static frame.        */
00021     /* If ord = (AxI=X, Par=Even, Rep=No, Frm=S), then      */
00022     /* {a,b,c,ord} means Rz(c)Ry(b)Rx(a), where Rz(c)v      */
00023     /* rotates v around Z by c radians.                     */
00024 #define EulFrmS      0
00025 #define EulFrmR      1
00026 #define EulFrm(ord)  ((unsigned)(ord)&1)
00027 #define EulRepNo     0
00028 #define EulRepYes    1
00029 #define EulRep(ord)  (((unsigned)(ord)>>1)&1)
00030 #define EulParEven   0
00031 #define EulParOdd    1
00032 #define EulPar(ord)  (((unsigned)(ord)>>2)&1)
00033 #define EulSafe      "\000\001\002\000"
00034 #define EulNext      "\001\002\000\001"
00035 #define EulAxI(ord)  ((int)(EulSafe[(((unsigned)(ord)>>3)&3)]))
00036 #define EulAxJ(ord)  ((int)(EulNext[EulAxI(ord)+(EulPar(ord)==EulParOdd)]))
00037 #define EulAxK(ord)  ((int)(EulNext[EulAxI(ord)+(EulPar(ord)!=EulParOdd)]))
00038 #define EulAxH(ord)  ((EulRep(ord)==EulRepNo)?EulAxK(ord):EulAxI(ord))
00039     /* EulGetOrd unpacks all useful information about order simultaneously. */
00040 #define EulGetOrd(ord,i,j,k,h,n,s,f) {unsigned o=ord;f=o&1;o>>=1;s=o&1;o>>=1;\
00041     n=o&1;o>>=1;i=EulSafe[o&3];j=EulNext[i+n];k=EulNext[i+1-n];h=s?k:i;}
00042     /* EulOrd creates an order value between 0 and 23 from 4-tuple choices. */
00043 #define EulOrd(i,p,r,f)    (((((((i)<<1)+(p))<<1)+(r))<<1)+(f))
00044     /* Static axes */
00045 #define EulOrdXYZs    EulOrd(X,EulParEven,EulRepNo,EulFrmS)
00046 #define EulOrdXYXs    EulOrd(X,EulParEven,EulRepYes,EulFrmS)
00047 #define EulOrdXZYs    EulOrd(X,EulParOdd,EulRepNo,EulFrmS)
00048 #define EulOrdXZXs    EulOrd(X,EulParOdd,EulRepYes,EulFrmS)
00049 #define EulOrdYZXs    EulOrd(Y,EulParEven,EulRepNo,EulFrmS)
00050 #define EulOrdYZYs    EulOrd(Y,EulParEven,EulRepYes,EulFrmS)
00051 #define EulOrdYXZs    EulOrd(Y,EulParOdd,EulRepNo,EulFrmS)
00052 #define EulOrdYXYs    EulOrd(Y,EulParOdd,EulRepYes,EulFrmS)
00053 #define EulOrdZXYs    EulOrd(Z,EulParEven,EulRepNo,EulFrmS)
00054 #define EulOrdZXZs    EulOrd(Z,EulParEven,EulRepYes,EulFrmS)
00055 #define EulOrdZYXs    EulOrd(Z,EulParOdd,EulRepNo,EulFrmS)
00056 #define EulOrdZYZs    EulOrd(Z,EulParOdd,EulRepYes,EulFrmS)
00057     /* Rotating axes */
00058 #define EulOrdZYXr    EulOrd(X,EulParEven,EulRepNo,EulFrmR)
00059 #define EulOrdXYXr    EulOrd(X,EulParEven,EulRepYes,EulFrmR)
00060 #define EulOrdYZXr    EulOrd(X,EulParOdd,EulRepNo,EulFrmR)
00061 #define EulOrdXZXr    EulOrd(X,EulParOdd,EulRepYes,EulFrmR)
00062 #define EulOrdXZYr    EulOrd(Y,EulParEven,EulRepNo,EulFrmR)
00063 #define EulOrdYZYr    EulOrd(Y,EulParEven,EulRepYes,EulFrmR)
00064 #define EulOrdZXYr    EulOrd(Y,EulParOdd,EulRepNo,EulFrmR)
00065 #define EulOrdYXYr    EulOrd(Y,EulParOdd,EulRepYes,EulFrmR)
00066 #define EulOrdYXZr    EulOrd(Z,EulParEven,EulRepNo,EulFrmR)
00067 #define EulOrdZXZr    EulOrd(Z,EulParEven,EulRepYes,EulFrmR)
00068 #define EulOrdXYZr    EulOrd(Z,EulParOdd,EulRepNo,EulFrmR)
00069 #define EulOrdZYZr    EulOrd(Z,EulParOdd,EulRepYes,EulFrmR)
00070 
00071 EulerAngles Eul_(float ai, float aj, float ah, int order);
00072 QuatX Eul_ToQuat(EulerAngles ea);
00073 void Eul_ToHMatrix(EulerAngles ea, HMatrix M);
00074 EulerAngles Eul_FromHMatrix(HMatrix M, int order);
00075 EulerAngles Eul_FromQuat(QuatX q, int order);
00076 #endif