rotmatrix.h

Go to the documentation of this file.
00001 /*
00002  *  This file is part of libcxxsupport.
00003  *
00004  *  libcxxsupport is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  libcxxsupport is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with libcxxsupport; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  */
00018 
00019 /*
00020  *  libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik
00021  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00022  *  (DLR).
00023  */
00024 
00025 /*! \file rotmatrix.h
00026  *  Class for rotation transforms in 3D space
00027  *
00028  *  Copyright (C) 2003-2011 Max-Planck-Society
00029  *  \author Martin Reinecke
00030  */
00031 
00032 #ifndef PLANCK_ROTMATRIX_H
00033 #define PLANCK_ROTMATRIX_H
00034 
00035 #include <iostream>
00036 #include "vec3.h"
00037 
00038 /*! \defgroup rotmatrixgroup Rotation matrices */
00039 /*! \{ */
00040 
00041 /*! Class for rotation transforms in 3D space */
00042 class rotmatrix
00043   {
00044   public:
00045     double entry[3][3];
00046 
00047     rotmatrix () {}
00048 
00049     /*! Constructs a rotation matrix from its nine entries */
00050     rotmatrix (double a00, double a01, double a02,
00051                double a10, double a11, double a12,
00052                double a20, double a21, double a22)
00053       {
00054       entry[0][0]=a00; entry[0][1]=a01; entry[0][2]=a02;
00055       entry[1][0]=a10; entry[1][1]=a11; entry[1][2]=a12;
00056       entry[2][0]=a20; entry[2][1]=a21; entry[2][2]=a22;
00057       }
00058 
00059     /*! Constructs a rotation matrix so that \a a is the first column,
00060         \a b is the second column and \a c is the third column.
00061         \note The vectors \a a, \a b and \a c must form an orthonormal system!
00062      */
00063     rotmatrix (const vec3 &a, const vec3 &b, const vec3 &c);
00064 
00065     /*! Sets the matrix to the identity matrix. */
00066     void SetToIdentity ();
00067     /*! Sets all matrix elements to zero. */
00068     void SetToZero ();
00069     /*! Transposes the matrix. */
00070     void Transpose ();
00071 
00072     /*! Extracts a unit-length rotation axis \a axis and a rotation angle
00073         \a angle (in radian) from the matrix. */
00074     void toAxisAngle (vec3 &axis, double &angle) const;
00075 
00076     /*! Constructs a matrix which causes a rotation by \a angle radians around
00077         \a axis. \a axis must have unit length. */
00078     void Make_Axis_Rotation_Transform (const vec3 &axis, double angle);
00079 
00080     /*! Creates a rotation matrix \a A, which performs the following operations
00081         on a vector \a v, when \a Av is calculated:
00082         -# rotate \a v around the z-axis by \a gamma,
00083         -# rotate \a v' around the y-axis by \a beta,
00084         -# rotate \a v'' around the z-axis by \a alpha.
00085 
00086         \note \a alpha, \a beta and \a gamma are given in radians,
00087               the rotations are right handed.
00088 
00089         \note This transformation rotates the \e vectors, not the coordinate
00090               axes! */
00091     void Make_CPAC_Euler_Matrix (double alpha, double beta, double gamma);
00092 
00093     /*! Extracts the Euler angles \a alpha, \a beta and \a gamma from the
00094         matrix. For their definition see Make_CPAC_Euler_Matrix().
00095 
00096         \note In case of ambiguity \a alpha will be 0. */
00097     void Extract_CPAC_Euler_Angles
00098       (double &alpha, double &beta, double &gamma) const;
00099 
00100     /*! Returns the vector \a vec, transformed by the matrix. */
00101     vec3 Transform (const vec3 &vec) const
00102       {
00103       return vec3
00104         (vec.x*entry[0][0] + vec.y*entry[0][1] + vec.z*entry[0][2],
00105          vec.x*entry[1][0] + vec.y*entry[1][1] + vec.z*entry[1][2],
00106          vec.x*entry[2][0] + vec.y*entry[2][1] + vec.z*entry[2][2]);
00107       }
00108     /*! Returns the vector \a vec, transformed by the matrix, in \a vec2. */
00109     void Transform (const vec3 &vec, vec3 &vec2) const
00110       {
00111       vec2.x = vec.x*entry[0][0] + vec.y*entry[0][1] + vec.z*entry[0][2];
00112       vec2.y = vec.x*entry[1][0] + vec.y*entry[1][1] + vec.z*entry[1][2];
00113       vec2.z = vec.x*entry[2][0] + vec.y*entry[2][1] + vec.z*entry[2][2];
00114       }
00115   };
00116 
00117 /*! Returns \a a * \a b.
00118     \relates rotmatrix */
00119 rotmatrix operator* (const rotmatrix &a, const rotmatrix &b);
00120 /*! Returns \a a * \a b in \a res.
00121     \relates rotmatrix */
00122 void matmult (const rotmatrix &a, const rotmatrix &b, rotmatrix &res);
00123 
00124 /*! Returns \a a^T * \a b in \a res.
00125     \relates rotmatrix */
00126 void TransposeTimes (const rotmatrix &a, const rotmatrix &b, rotmatrix &res);
00127 
00128 /*! Writes \a mat to \a os.
00129     \relates rotmatrix */
00130 std::ostream &operator<< (std::ostream &os, const rotmatrix &mat);
00131 
00132 /*! \} */
00133 
00134 #endif

Generated on Thu Oct 8 14:48:51 2015 for LevelS C++ support library