Jpp 21.0.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JRotation2D.hh
Go to the documentation of this file.
1#ifndef __JROTATION2D__
2#define __JROTATION2D__
3
4#include <cmath>
5
9
10
11/**
12 * \author mdejong
13 */
14
15namespace JGEOMETRY2D {}
16namespace JPP { using namespace JGEOMETRY2D; }
17
18namespace JGEOMETRY2D {
19
20
21 /**
22 * Rotation matrix
23 */
25 public JMatrix2D
26 {
27 public:
28 /**
29 * Default constructor (= identity matrix).
30 */
32 JMatrix2D()
33 {
35 }
36
37
38 /**
39 * Constructor.
40 * The rotation is around the origin and anti-clockwise.
41 *
42 * \param angle angle [rad]
43 */
44 JRotation2D(const JAngle2D& angle) :
45 JMatrix2D()
46 {
47 const double cp = cos(angle.getPhi());
48 const double sp = sin(angle.getPhi());
49
50 a00 = cp; a01 = -sp;
51 a10 = sp; a11 = cp;
52 }
53
54
55 /**
56 * Constructor.
57 * The rotation is defined such that back ration of the same direction aligns with the x-axis.
58 *
59 * \param dir direction
60 */
61 JRotation2D(const JVector2D& dir) :
62 JMatrix2D()
63 {
64 const double R = hypot(dir.getX(), dir.getY());
65 const double cp = dir.getX() / R;
66 const double sp = dir.getY() / R;
67
68 a00 = cp; a01 = -sp;
69 a10 = sp; a11 = cp;
70 }
71
72
73 /**
74 * Get rotation.
75 *
76 * \return rotation
77 */
78 const JRotation2D& getRotation() const
79 {
80 return static_cast<const JRotation2D&>(*this);
81 }
82
83
84 /**
85 * Transpose.
86 */
88 {
90
91 return *this;
92 }
93
94
95 /**
96 * Matrix multiplication.
97 *
98 * \param A matrix
99 * \return this * A
100 */
102 {
104
105 return *this;
106 }
107
108
109 /**
110 * Rotate.
111 *
112 * \param __x x value
113 * \param __y y value
114 */
115 void rotate(double& __x, double& __y) const
116 {
117 const double x = a00 * __x + a01 * __y;
118 const double y = a10 * __x + a11 * __y;
119
120 __x = x;
121 __y = y;
122 }
123
124
125 /**
126 * Rotate back.
127 *
128 * \param __x x value
129 * \param __y y value
130 */
131 void rotate_back(double& __x, double& __y) const
132 {
133 const double x = a00 * __x + a10 * __y;
134 const double y = a01 * __x + a11 * __y;
135
136 __x = x;
137 __y = y;
138 }
139 };
140}
141
142#endif
Data structure for angle in two dimensions.
Definition JAngle2D.hh:35
double getPhi() const
Get phi angle.
Definition JAngle2D.hh:72
JRotation2D(const JAngle2D &angle)
Constructor.
JRotation2D()
Default constructor (= identity matrix).
void rotate(double &__x, double &__y) const
Rotate.
JRotation2D & mul(const JRotation2D &A)
Matrix multiplication.
JRotation2D & transpose()
Transpose.
JRotation2D(const JVector2D &dir)
Constructor.
const JRotation2D & getRotation() const
Get rotation.
void rotate_back(double &__x, double &__y) const
Rotate back.
Data structure for vector in two dimensions.
Definition JVector2D.hh:34
double getY() const
Get y position.
Definition JVector2D.hh:74
double getX() const
Get x position.
Definition JVector2D.hh:63
JMatrix2D & setIdentity()
Set to identity matrix.
JMatrix2D & mul(const double factor)
Scale matrix.
JMatrix2D & transpose()
Transpose.
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).