OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Matrix3D.cpp
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2// $RCSfile: Matrix3D.cpp,v $
3// ------------------------------------------------------------------------
4// $Revision: 1.1.1.1 $
5// ------------------------------------------------------------------------
6// Copyright: see Copyright.readme
7// ------------------------------------------------------------------------
8//
9// Class: Matrix3D
10// Matrix3D represents an 3-dimension matrix.
11//
12// ------------------------------------------------------------------------
13// Class category: BeamlineGeometry
14// ------------------------------------------------------------------------
15//
16// $Date: 2000/03/27 09:32:34 $
17// $Author: fci $
18//
19// ------------------------------------------------------------------------
20
23
24
25// Class Matrix3D.
26// ------------------------------------------------------------------------
27
28Matrix3D::Matrix3D(const Vector3D &a, const Vector3D &b, const Vector3D &c) {
29 m[0][0] = a(0);
30 m[0][1] = b(0);
31 m[0][2] = c(0);
32 m[1][0] = a(1);
33 m[1][1] = b(1);
34 m[1][2] = c(1);
35 m[2][0] = a(2);
36 m[2][1] = b(2);
37 m[2][2] = c(2);
38}
39
40
41Matrix3D::Matrix3D(double x11, double x12, double x13,
42 double x21, double x22, double x23,
43 double x31, double x32, double x33) {
44 m[0][0] = x11;
45 m[0][1] = x12;
46 m[0][2] = x13;
47 m[1][0] = x21;
48 m[1][1] = x22;
49 m[1][2] = x23;
50 m[2][0] = x31;
51 m[2][1] = x32;
52 m[2][2] = x33;
53}
54
55
56bool Matrix3D::operator==(const Matrix3D &rhs) const {
57 return (m[0][0] == rhs(0, 0)) && (m[0][1] == rhs(0, 1)) && (m[0][2] == rhs(0, 2))
58 && (m[1][0] == rhs(1, 0)) && (m[1][1] == rhs(1, 1)) && (m[1][2] == rhs(1, 2))
59 && (m[2][0] == rhs(2, 0)) && (m[2][1] == rhs(2, 1)) && (m[2][2] == rhs(2, 2));
60}
61
62
63bool Matrix3D::operator!=(const Matrix3D &rhs) const {
64 return (m[0][0] != rhs(0, 0)) || (m[0][1] != rhs(0, 1)) || (m[0][2] != rhs(0, 2))
65 || (m[1][0] != rhs(1, 0)) || (m[1][1] != rhs(1, 1)) || (m[1][2] != rhs(1, 2))
66 || (m[2][0] != rhs(2, 0)) || (m[2][1] != rhs(2, 1)) || (m[2][2] != rhs(2, 2));
67}
68
69
71 m[0][0] += rhs.m[0][0];
72 m[0][1] += rhs.m[0][1];
73 m[0][2] += rhs.m[0][2];
74 m[1][0] += rhs.m[1][0];
75 m[1][1] += rhs.m[1][1];
76 m[1][2] += rhs.m[1][2];
77 m[2][0] += rhs.m[2][0];
78 m[2][1] += rhs.m[2][1];
79 m[2][2] += rhs.m[2][2];
80 return *this;
81}
82
83
85 m[0][0] -= rhs.m[0][0];
86 m[0][1] -= rhs.m[0][1];
87 m[0][2] -= rhs.m[0][2];
88 m[1][0] -= rhs.m[1][0];
89 m[1][1] -= rhs.m[1][1];
90 m[1][2] -= rhs.m[1][2];
91 m[2][0] -= rhs.m[2][0];
92 m[2][1] -= rhs.m[2][1];
93 m[2][2] -= rhs.m[2][2];
94 return *this;
95}
96
97
99 return (*this = *this * rhs);
100}
101
102
104 m[0][0] *= rhs;
105 m[0][1] *= rhs;
106 m[0][2] *= rhs;
107 m[1][0] *= rhs;
108 m[1][1] *= rhs;
109 m[1][2] *= rhs;
110 m[2][0] *= rhs;
111 m[2][1] *= rhs;
112 m[2][2] *= rhs;
113 return *this;
114}
115
116
118 return Matrix3D();
119}
120
121
123 return (m[0][0] == 1.0) && (m[0][1] == 0.0) && (m[0][2] == 0.0)
124 && (m[1][0] == 0.0) && (m[1][1] == 1.0) && (m[1][2] == 0.0)
125 && (m[2][0] == 0.0) && (m[2][1] == 0.0) && (m[2][2] == 1.0);
126}
127
128
130 double det =
131 m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) +
132 m[0][1] * (m[1][2] * m[2][0] - m[1][0] * m[2][2]) +
133 m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]);
134
135 return Matrix3D((m[1][1] * m[2][2] - m[1][2] * m[2][1]) / det,
136 (m[2][1] * m[0][2] - m[2][2] * m[0][1]) / det,
137 (m[0][1] * m[1][2] - m[0][2] * m[1][1]) / det,
138
139 (m[1][2] * m[2][0] - m[1][0] * m[2][2]) / det,
140 (m[2][2] * m[0][0] - m[2][0] * m[0][2]) / det,
141 (m[0][2] * m[1][0] - m[0][0] * m[1][2]) / det,
142
143 (m[1][0] * m[2][1] - m[1][1] * m[2][0]) / det,
144 (m[2][0] * m[0][1] - m[2][1] * m[0][0]) / det,
145 (m[0][0] * m[1][1] - m[0][1] * m[1][0]) / det);
146}
147
148
150 Matrix3D t;
151
152 for(int i = 0; i < 3; i++) {
153 t(i, 0) = m[0][i];
154 t(i, 1) = m[1][i];
155 t(i, 2) = m[2][i];
156 }
157
158 return t;
159}
160
161
162Matrix3D operator+(const Matrix3D &lhs, const Matrix3D &rhs) {
163 Matrix3D result(lhs);
164 return result += rhs;
165}
166
167
168Matrix3D operator-(const Matrix3D &lhs, const Matrix3D &rhs) {
169 Matrix3D result(lhs);
170 return result += rhs;
171}
172
173
174Matrix3D operator*(const Matrix3D &lhs, const Matrix3D &rhs) {
175 return Matrix3D(lhs(0, 0) * rhs(0, 0) + lhs(0, 1) * rhs(1, 0) + lhs(0, 2) * rhs(2, 0),
176 lhs(0, 0) * rhs(0, 1) + lhs(0, 1) * rhs(1, 1) + lhs(0, 2) * rhs(2, 1),
177 lhs(0, 0) * rhs(0, 2) + lhs(0, 1) * rhs(1, 2) + lhs(0, 2) * rhs(2, 2),
178
179 lhs(1, 0) * rhs(0, 0) + lhs(1, 1) * rhs(1, 0) + lhs(1, 2) * rhs(2, 0),
180 lhs(1, 0) * rhs(0, 1) + lhs(1, 1) * rhs(1, 1) + lhs(1, 2) * rhs(2, 1),
181 lhs(1, 0) * rhs(0, 2) + lhs(1, 1) * rhs(1, 2) + lhs(1, 2) * rhs(2, 2),
182
183 lhs(2, 0) * rhs(0, 0) + lhs(2, 1) * rhs(1, 0) + lhs(2, 2) * rhs(2, 0),
184 lhs(2, 0) * rhs(0, 1) + lhs(2, 1) * rhs(1, 1) + lhs(2, 2) * rhs(2, 1),
185 lhs(2, 0) * rhs(0, 2) + lhs(2, 1) * rhs(1, 2) + lhs(2, 2) * rhs(2, 2));
186}
187
188
189Vector3D operator*(const Matrix3D &lhs, const Vector3D &rhs) {
190 return Vector3D(lhs(0, 0) * rhs(0) + lhs(0, 1) * rhs(1) + lhs(0, 2) * rhs(2),
191 lhs(1, 0) * rhs(0) + lhs(1, 1) * rhs(1) + lhs(1, 2) * rhs(2),
192 lhs(2, 0) * rhs(0) + lhs(2, 1) * rhs(1) + lhs(2, 2) * rhs(2));
193}
Matrix3D operator*(const Matrix3D &lhs, const Matrix3D &rhs)
Multiply.
Definition: Matrix3D.cpp:174
Matrix3D operator+(const Matrix3D &lhs, const Matrix3D &rhs)
Add.
Definition: Matrix3D.cpp:162
Matrix3D operator-(const Matrix3D &lhs, const Matrix3D &rhs)
Subtract.
Definition: Matrix3D.cpp:168
std::complex< double > a
T det(const AntiSymTenzor< T, 3 > &)
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:45
3-dimensional matrix.
Definition: Matrix3D.h:33
Matrix3D transpose() const
Transpose.
Definition: Matrix3D.cpp:149
Matrix3D & operator-=(const Matrix3D &rhs)
Subtract and assign.
Definition: Matrix3D.cpp:84
Matrix3D & operator+=(const Matrix3D &rhs)
Add and assign.
Definition: Matrix3D.cpp:70
bool isIdentity() const
Test for identity.
Definition: Matrix3D.cpp:122
Matrix3D & operator*=(const Matrix3D &rhs)
Multiply and assign.
Definition: Matrix3D.cpp:98
bool operator!=(const Matrix3D &) const
Definition: Matrix3D.cpp:63
Matrix3D inverse() const
Inverse.
Definition: Matrix3D.cpp:129
bool operator==(const Matrix3D &) const
Definition: Matrix3D.cpp:56
double m[3][3]
Definition: Matrix3D.h:90
static Matrix3D Identity()
Make identity.
Definition: Matrix3D.cpp:117
Matrix3D()
Default constructor.
Definition: Matrix3D.h:113
A 3-dimension vector.
Definition: Vector3D.h:31