LevelS C++ support library  3.83
rotmatrix.h
Go to the documentation of this file.
1 /*
2  * This file is part of libcxxsupport.
3  *
4  * libcxxsupport is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * libcxxsupport is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with libcxxsupport; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /*
20  * libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik
21  * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
22  * (DLR).
23  */
24 
25 /*! \file rotmatrix.h
26  * Class for rotation transforms in 3D space
27  *
28  * Copyright (C) 2003-2011 Max-Planck-Society
29  * \author Martin Reinecke
30  */
31 
32 #ifndef PLANCK_ROTMATRIX_H
33 #define PLANCK_ROTMATRIX_H
34 
35 #include <iostream>
36 #include "vec3.h"
37 
38 /*! \defgroup rotmatrixgroup Rotation matrices */
39 /*! \{ */
40 
41 /*! Class for rotation transforms in 3D space */
42 class rotmatrix
43  {
44  public:
45  double entry[3][3];
46 
47  rotmatrix () {}
48 
49  /*! Constructs a rotation matrix from its nine entries */
50  rotmatrix (double a00, double a01, double a02,
51  double a10, double a11, double a12,
52  double a20, double a21, double a22)
53  {
54  entry[0][0]=a00; entry[0][1]=a01; entry[0][2]=a02;
55  entry[1][0]=a10; entry[1][1]=a11; entry[1][2]=a12;
56  entry[2][0]=a20; entry[2][1]=a21; entry[2][2]=a22;
57  }
58 
59  /*! Constructs a rotation matrix so that \a a is the first column,
60  \a b is the second column and \a c is the third column.
61  \note The vectors \a a, \a b and \a c must form an orthonormal system!
62  */
63  rotmatrix (const vec3 &a, const vec3 &b, const vec3 &c);
64 
65  /*! Sets the matrix to the identity matrix. */
66  void SetToIdentity ();
67  /*! Sets all matrix elements to zero. */
68  void SetToZero ();
69  /*! Transposes the matrix. */
70  void Transpose ();
71 
72  /*! Extracts a unit-length rotation axis \a axis and a rotation angle
73  \a angle (in radian) from the matrix. */
74  void toAxisAngle (vec3 &axis, double &angle) const;
75 
76  /*! Constructs a matrix which causes a rotation by \a angle radians around
77  \a axis. \a axis must have unit length. */
78  void Make_Axis_Rotation_Transform (const vec3 &axis, double angle);
79 
80  /*! Creates a rotation matrix \a A, which performs the following operations
81  on a vector \a v, when \a Av is calculated:
82  -# rotate \a v around the z-axis by \a gamma,
83  -# rotate \a v' around the y-axis by \a beta,
84  -# rotate \a v'' around the z-axis by \a alpha.
85 
86  \note \a alpha, \a beta and \a gamma are given in radians,
87  the rotations are right handed.
88 
89  \note This transformation rotates the \e vectors, not the coordinate
90  axes! */
91  void Make_CPAC_Euler_Matrix (double alpha, double beta, double gamma);
92 
93  /*! Extracts the Euler angles \a alpha, \a beta and \a gamma from the
94  matrix. For their definition see Make_CPAC_Euler_Matrix().
95 
96  \note In case of ambiguity \a alpha will be 0. */
98  (double &alpha, double &beta, double &gamma) const;
99 
100  /*! Returns the vector \a vec, transformed by the matrix. */
101  vec3 Transform (const vec3 &vec) const
102  {
103  return vec3
104  (vec.x*entry[0][0] + vec.y*entry[0][1] + vec.z*entry[0][2],
105  vec.x*entry[1][0] + vec.y*entry[1][1] + vec.z*entry[1][2],
106  vec.x*entry[2][0] + vec.y*entry[2][1] + vec.z*entry[2][2]);
107  }
108  /*! Returns the vector \a vec, transformed by the matrix, in \a vec2. */
109  void Transform (const vec3 &vec, vec3 &vec2) const
110  {
111  vec2.x = vec.x*entry[0][0] + vec.y*entry[0][1] + vec.z*entry[0][2];
112  vec2.y = vec.x*entry[1][0] + vec.y*entry[1][1] + vec.z*entry[1][2];
113  vec2.z = vec.x*entry[2][0] + vec.y*entry[2][1] + vec.z*entry[2][2];
114  }
115  };
116 
117 /*! Returns \a a * \a b.
118  \relates rotmatrix */
119 rotmatrix operator* (const rotmatrix &a, const rotmatrix &b);
120 /*! Returns \a a * \a b in \a res.
121  \relates rotmatrix */
122 void matmult (const rotmatrix &a, const rotmatrix &b, rotmatrix &res);
123 
124 /*! Returns \a a^T * \a b in \a res.
125  \relates rotmatrix */
126 void TransposeTimes (const rotmatrix &a, const rotmatrix &b, rotmatrix &res);
127 
128 /*! Writes \a mat to \a os.
129  \relates rotmatrix */
130 std::ostream &operator<< (std::ostream &os, const rotmatrix &mat);
131 
132 /*! \} */
133 
134 #endif
void Transform(const vec3 &vec, vec3 &vec2) const
Definition: rotmatrix.h:109
T y
Definition: vec3.h:46
T z
Definition: vec3.h:46
std::ostream & operator<<(std::ostream &os, const pointing &p)
void SetToIdentity()
Definition: rotmatrix.cc:45
T x
Definition: vec3.h:46
vec3_t< float64 > vec3
Definition: vec3.h:143
void TransposeTimes(const rotmatrix &a, const rotmatrix &b, rotmatrix &res)
Definition: rotmatrix.cc:187
void Extract_CPAC_Euler_Angles(double &alpha, double &beta, double &gamma) const
Definition: rotmatrix.cc:147
Definition: vec3.h:43
rotmatrix operator*(const rotmatrix &a, const rotmatrix &b)
Definition: rotmatrix.cc:167
void matmult(const rotmatrix &a, const rotmatrix &b, rotmatrix &res)
Definition: rotmatrix.cc:178
void Make_CPAC_Euler_Matrix(double alpha, double beta, double gamma)
Definition: rotmatrix.cc:136
rotmatrix(double a00, double a01, double a02, double a10, double a11, double a12, double a20, double a21, double a22)
Definition: rotmatrix.h:50
void toAxisAngle(vec3 &axis, double &angle) const
Definition: rotmatrix.cc:65
void Transpose()
Definition: rotmatrix.cc:58
void Make_Axis_Rotation_Transform(const vec3 &axis, double angle)
Definition: rotmatrix.cc:117
void SetToZero()
Definition: rotmatrix.cc:52
vec3 Transform(const vec3 &vec) const
Definition: rotmatrix.h:101

Generated on Wed Nov 13 2024 12:18:16 for LevelS C++ support library