contrib/mul/m23d/m23d_rotation_matrix.cxx
Go to the documentation of this file.
00001 #include "m23d_rotation_matrix.h"
00002 //:
00003 // \file
00004 // \author Tim Cootes
00005 // \brief Generate pure 3x3 rotation matrices
00006 
00007 #include <vcl_cmath.h>
00008 
00009 //: Generate 3x3 matrix which applies a rotation about the x axis
00010 vnl_matrix<double> m23d_rotation_matrix_x(double A)
00011 {
00012   vnl_matrix<double> R(3,3,0.0);
00013   double c = vcl_cos(A);
00014   double s = vcl_sin(A);
00015   R(0,0)=1.0;
00016   R(1,1)=c;  R(1,2)=-s;
00017   R(2,1)=s;  R(2,2)= c;
00018   return R;
00019 }
00020 
00021 //: Generate 3x3 matrix which applies a rotation about the y axis
00022 vnl_matrix<double> m23d_rotation_matrix_y(double A)
00023 {
00024   vnl_matrix<double> R(3,3,0.0);
00025   double c = vcl_cos(A);
00026   double s = vcl_sin(A);
00027   R(1,1)=1.0;
00028   R(0,0)=c;  R(0,2)=-s;
00029   R(2,0)=s;  R(2,2)= c;
00030   return R;
00031 }
00032 
00033 
00034 //: Generate 3x3 matrix which applies a rotation about the z axis
00035 vnl_matrix<double> m23d_rotation_matrix_z(double A)
00036 {
00037   vnl_matrix<double> R(3,3,0.0);
00038   double c = vcl_cos(A);
00039   double s = vcl_sin(A);
00040   R(2,2)=1.0;
00041   R(0,0)=c;  R(0,1)=-s;
00042   R(1,0)=s;  R(1,1)= c;
00043   return R;
00044 }
00045 
00046 
00047 //: Generate 3x3 matrix which applies rotations about the x,y and z axes
00048 //  Order of application: x,y, z.
00049 vnl_matrix<double> m23d_rotation_matrix(double Ax, double Ay, double Az)
00050 {
00051   return m23d_rotation_matrix_z(Az)
00052          * m23d_rotation_matrix_y(Ay)
00053          * m23d_rotation_matrix_x(Ax);
00054 }