| 1 | #include "slalib.h" | 
|---|
| 2 | #include "slamac.h" | 
|---|
| 3 | void slaDm2av ( double rmat[3][3], double axvec[3] ) | 
|---|
| 4 | /* | 
|---|
| 5 | **  - - - - - - - - - | 
|---|
| 6 | **   s l a D m 2 a v | 
|---|
| 7 | **  - - - - - - - - - | 
|---|
| 8 | ** | 
|---|
| 9 | **  From a rotation matrix, determine the corresponding axial vector. | 
|---|
| 10 | ** | 
|---|
| 11 | **  (double precision) | 
|---|
| 12 | ** | 
|---|
| 13 | **  A rotation matrix describes a rotation about some arbitrary axis. | 
|---|
| 14 | **  The axis is called the Euler axis, and the angle through which the | 
|---|
| 15 | **  reference frame rotates is called the Euler angle.  The axial | 
|---|
| 16 | **  vector returned by this routine has the same direction as the | 
|---|
| 17 | **  Euler axis, and its magnitude is the Euler angle in radians.  (The | 
|---|
| 18 | **  magnitude and direction can be separated by means of the routine | 
|---|
| 19 | **  slaDvn.) | 
|---|
| 20 | ** | 
|---|
| 21 | **  Given: | 
|---|
| 22 | **    rmat   double[3][3]   rotation matrix | 
|---|
| 23 | ** | 
|---|
| 24 | **  Returned: | 
|---|
| 25 | **    axvec  double[3]      axial vector (radians) | 
|---|
| 26 | ** | 
|---|
| 27 | **  The reference frame rotates clockwise as seen looking along | 
|---|
| 28 | **  the axial vector from the origin. | 
|---|
| 29 | ** | 
|---|
| 30 | **  If rmat is null, so is the result. | 
|---|
| 31 | ** | 
|---|
| 32 | **  Last revision:   31 October 1993 | 
|---|
| 33 | ** | 
|---|
| 34 | **  Copyright P.T.Wallace.  All rights reserved. | 
|---|
| 35 | */ | 
|---|
| 36 | { | 
|---|
| 37 | double x, y, z, s2, c2, phi, f; | 
|---|
| 38 |  | 
|---|
| 39 | x = rmat[1][2] - rmat[2][1]; | 
|---|
| 40 | y = rmat[2][0] - rmat[0][2]; | 
|---|
| 41 | z = rmat[0][1] - rmat[1][0]; | 
|---|
| 42 | s2 = sqrt ( x * x + y * y + z * z ); | 
|---|
| 43 | if ( s2 != 0.0 ) | 
|---|
| 44 | { | 
|---|
| 45 | c2 = ( rmat[0][0] + rmat[1][1] + rmat[2][2] - 1.0 ); | 
|---|
| 46 | phi = atan2 ( s2 / 2.0, c2 / 2.0 ); | 
|---|
| 47 | f = phi / s2; | 
|---|
| 48 | axvec[0] = x * f; | 
|---|
| 49 | axvec[1] = y * f; | 
|---|
| 50 | axvec[2] = z * f; | 
|---|
| 51 | } else { | 
|---|
| 52 | axvec[0] = 0.0; | 
|---|
| 53 | axvec[1] = 0.0; | 
|---|
| 54 | axvec[2] = 0.0; | 
|---|
| 55 | } | 
|---|
| 56 | } | 
|---|