Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
JRotation2D.hh
Go to the documentation of this file.
1 #ifndef __JROTATION2D__
2 #define __JROTATION2D__
3 
4 #include <cmath>
5 
8 
9 
10 /**
11  * \author mdejong
12  */
13 
14 namespace JGEOMETRY2D {}
15 namespace JPP { using namespace JGEOMETRY2D; }
16 
17 namespace JGEOMETRY2D {
18 
19 
20  /**
21  * Rotation matrix
22  */
23  class JRotation2D :
24  public JMatrix2D
25  {
26  public:
27  /**
28  * Default constructor (= identity matrix).
29  */
31  JMatrix2D()
32  {
33  setIdentity();
34  }
35 
36 
37  /**
38  * Constructor.
39  * The rotation is around the origin and anti-clockwise.
40  *
41  * \param dir direction
42  */
43  JRotation2D(const JAngle2D& dir) :
44  JMatrix2D()
45  {
46  const double cp = cos(dir.getPhi());
47  const double sp = sin(dir.getPhi());
48 
49  a00 = cp; a01 = -sp;
50  a10 = sp; a11 = cp;
51  }
52 
53 
54  /**
55  * Get rotation.
56  *
57  * \return rotation
58  */
59  const JRotation2D& getRotation() const
60  {
61  return static_cast<const JRotation2D&>(*this);
62  }
63 
64 
65  /**
66  * Transpose.
67  */
69  {
71 
72  return *this;
73  }
74 
75 
76  /**
77  * Matrix multiplication.
78  *
79  * \param A matrix
80  * \return this * A
81  */
83  {
84  JMatrix2D::mul(A);
85 
86  return *this;
87  }
88 
89 
90  /**
91  * Rotate.
92  *
93  * \param __x x value
94  * \param __y y value
95  */
96  void rotate(double& __x, double& __y) const
97  {
98  const double x = a00 * __x + a01 * __y;
99  const double y = a10 * __x + a11 * __y;
100 
101  __x = x;
102  __y = y;
103  }
104 
105 
106  /**
107  * Rotate back.
108  *
109  * \param __x x value
110  * \param __y y value
111  */
112  void rotate_back(double& __x, double& __y) const
113  {
114  const double x = a00 * __x + a10 * __y;
115  const double y = a01 * __x + a11 * __y;
116 
117  __x = x;
118  __y = y;
119  }
120  };
121 }
122 
123 #endif
Data structure for angle in two dimensions.
Definition: JAngle2D.hh:35
double getPhi() const
Get phi angle.
Definition: JAngle2D.hh:72
Rotation matrix.
Definition: JRotation2D.hh:25
JRotation2D()
Default constructor (= identity matrix).
Definition: JRotation2D.hh:30
void rotate(double &__x, double &__y) const
Rotate.
Definition: JRotation2D.hh:96
JRotation2D & transpose()
Transpose.
Definition: JRotation2D.hh:68
JRotation2D(const JAngle2D &dir)
Constructor.
Definition: JRotation2D.hh:43
const JRotation2D & getRotation() const
Get rotation.
Definition: JRotation2D.hh:59
void rotate_back(double &__x, double &__y) const
Rotate back.
Definition: JRotation2D.hh:112
JRotation2D & mul(const JRotation2D &A)
Matrix multiplication.
Definition: JRotation2D.hh:82
JMatrix2D & transpose()
Transpose.
JMatrix2D & mul(const double factor)
Scale matrix.
JMatrix2D & setIdentity()
Set to identity matrix.
Auxiliary classes and methods for 2D geometrical objects and operations.
Definition: JAngle2D.hh:19
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).