Jpp 19.3.0-rc.2
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
8
9
10/**
11 * \author mdejong
12 */
13
14namespace JGEOMETRY2D {}
15namespace JPP { using namespace JGEOMETRY2D; }
16
17namespace JGEOMETRY2D {
18
19
20 /**
21 * Rotation matrix
22 */
24 public JMatrix2D
25 {
26 public:
27 /**
28 * Default constructor (= identity matrix).
29 */
31 JMatrix2D()
32 {
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 {
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
JRotation2D()
Default constructor (= identity matrix).
void rotate(double &__x, double &__y) const
Rotate.
JRotation2D & mul(const JRotation2D &A)
Matrix multiplication.
JRotation2D & transpose()
Transpose.
const JRotation2D & getRotation() const
Get rotation.
JRotation2D(const JAngle2D &dir)
Constructor.
void rotate_back(double &__x, double &__y) const
Rotate back.
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).