source: trunk/MagicSoft/slalib/m2av.c@ 8820

Last change on this file since 8820 was 731, checked in by tbretz, 24 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 1.5 KB
Line 
1#include "slalib.h"
2#include "slamac.h"
3void slaM2av ( float rmat[3][3], float axvec[3] )
4/*
5** - - - - - - - -
6** s l a M 2 a v
7** - - - - - - - -
8**
9** From a rotation matrix, determine the corresponding axial vector.
10**
11** (single 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** slaVn.)
20**
21** Given:
22** rmat float[3][3] rotation matrix
23**
24** Returned:
25** axvec float[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: 9 April 1998
33**
34** Copyright P.T.Wallace. All rights reserved.
35*/
36{
37 float 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 = (float) sqrt ( (double) ( x * x + y * y + z * z ) );
43 if ( s2 != 0.0f ) {
44 c2 = rmat[0][0] + rmat[1][1] + rmat[2][2] - 1.0f;
45 phi = (float) atan2 ( (double) s2 / 2.0, (double) c2 / 2.0 );
46 f = phi / s2;
47 axvec[0] = x * f;
48 axvec[1] = y * f;
49 axvec[2] = z * f;
50 } else {
51 axvec[0] = 0.0f;
52 axvec[1] = 0.0f;
53 axvec[2] = 0.0f;
54 }
55}
Note: See TracBrowser for help on using the repository browser.