Project
Loading...
Searching...
No Matches
FairGeoRotation.h
Go to the documentation of this file.
1/********************************************************************************
2 * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3 * *
4 * This software is distributed under the terms of the *
5 * GNU Lesser General Public Licence (LGPL) version 3, *
6 * copied verbatim in the file "LICENSE" *
7 ********************************************************************************/
8#ifndef FAIRGEOROTATION_H
9#define FAIRGEOROTATION_H
10
11#include "FairGeoVector.h" // for FairGeoVector
12
13#include <Rtypes.h> // for Double_t, Int_t, Bool_t, etc
14#include <TObject.h> // for TObject
15#include <iostream> // for operator<<, cout, ostream, etc
16
17class TRotMatrix;
18
24{
25 protected:
26 Double_t rot[9];
27
28 public:
29 inline FairGeoRotation();
30 inline FairGeoRotation(const FairGeoRotation&);
31 inline FairGeoRotation(const Double_t*);
32 FairGeoRotation(const Double_t, const Double_t, const Double_t);
34 inline void setMatrix(const Double_t*);
35 inline void setMatrix(const Float_t*);
36 void setEulerAngles(const Double_t, const Double_t, const Double_t);
37 inline void setElement(const Double_t, const Int_t);
38 inline Double_t operator()(Int_t) const;
40 inline Bool_t operator==(const FairGeoRotation&);
41 inline Bool_t operator!=(const FairGeoRotation&);
42 inline FairGeoVector operator*(const FairGeoVector&)const;
43 inline FairGeoRotation operator*(const FairGeoRotation&)const;
46 inline Bool_t isUnitMatrix();
47 inline FairGeoRotation inverse() const;
48 inline FairGeoRotation& invert();
49 inline Double_t determinant() const;
50 Double_t diff2(const FairGeoRotation&) const;
51 inline Double_t getElement(Int_t i, Int_t j) const;
52 inline void setUnitMatrix();
53 inline void setZero();
54 inline void print() const;
55 TRotMatrix* createTRotMatrix(const Text_t* name = "", const Text_t* title = "");
56
58};
59
60// -------------------- inlines ---------------------------
61
63 : TObject()
64{
65 rot[0] = rot[4] = rot[8] = 1.;
66 rot[1] = rot[2] = rot[3] = rot[5] = rot[6] = rot[7] = 0.;
67}
68
69inline Double_t FairGeoRotation::operator()(Int_t i) const
70{
71 if (i >= 0 && i < 9) {
72 return rot[i];
73 }
74 Error("operator()", "bad index");
75 return 0;
76}
77
79 : TObject(r)
80{
81 for (Int_t i = 0; i < 9; i++) {
82 rot[i] = r(i);
83 }
84}
85
86inline FairGeoRotation::FairGeoRotation(const Double_t* a)
87 : TObject()
88{
89 for (Int_t i = 0; i < 9; i++) {
90 rot[i] = a[i];
91 }
92}
93
94inline void FairGeoRotation::setMatrix(const Double_t* a)
95{
96 for (Int_t i = 0; i < 9; i++) {
97 rot[i] = a[i];
98 }
99}
100
102{
103 for (Int_t i = 0; i < 9; i++) {
104 rot[i] = a[i];
105 }
106}
107
108inline void FairGeoRotation::setElement(const Double_t a, const Int_t i)
109{
110 if (i < 9) {
111 rot[i] = a;
112 }
113}
114
115inline Double_t FairGeoRotation::getElement(Int_t i, Int_t j) const { return rot[i * 3 + j]; }
116
118{
119 for (Int_t i = 0; i < 9; i++) {
120 rot[i] = r(i);
121 }
122 return *this;
123}
124
126{
127 Int_t i = 0;
128 while (i < 9) {
129 if (rot[i] != r(i)) {
130 return kFALSE;
131 }
132 i++;
133 }
134 return kTRUE;
135}
136
138{
139 Int_t i = 0;
140 while (i < 9) {
141 if (rot[i] != r(i)) {
142 return kTRUE;
143 }
144 i++;
145 }
146 return kFALSE;
147}
148
150{
151 return FairGeoVector(rot[0] * v(0) + rot[1] * v(1) + rot[2] * v(2),
152 rot[3] * v(0) + rot[4] * v(1) + rot[5] * v(2),
153 rot[6] * v(0) + rot[7] * v(1) + rot[8] * v(2));
154}
155
157{
158 Double_t a[9];
159 for (Int_t kk = 0; kk < 9; kk++) {
160 a[kk] = 0;
161 }
162 for (Int_t i = 0; i < 3; i++) {
163 for (Int_t j = 0; j < 3; j++) {
164 Int_t n = 3 * i + j;
165 for (Int_t k = 0; k < 3; k++) {
166 a[n] += rot[3 * i + k] * r(3 * k + j);
167 }
168 }
169 }
170 return FairGeoRotation(&a[0]);
171}
172
174
175inline FairGeoRotation& FairGeoRotation::transform(const FairGeoRotation& r) { return *this = r * (*this); }
176
178{
179 return (rot[0] == 1. && rot[1] == 0. && rot[2] == 0. && rot[3] == 0. && rot[4] == 1. && rot[5] == 0. && rot[6] == 0.
180 && rot[7] == 0. && rot[8] == 1.)
181 ? kTRUE
182 : kFALSE;
183}
184
186{
187 Double_t a[9];
188 for (Int_t i = 0; i < 3; i++) {
189 for (Int_t j = 0; j < 3; j++) {
190 a[j + 3 * i] = rot[i + 3 * j];
191 }
192 }
193 return FairGeoRotation(a);
194}
195
196inline FairGeoRotation& FairGeoRotation::invert() { return *this = inverse(); }
197
198inline Double_t FairGeoRotation::determinant() const
199{
200 return rot[0] * (rot[4] * rot[8] - rot[7] * rot[5]) - rot[3] * (rot[1] * rot[8] - rot[7] * rot[2])
201 + rot[6] * (rot[1] * rot[5] - rot[4] * rot[2]);
202}
203
205{
206 rot[0] = rot[4] = rot[8] = 1.;
207 rot[1] = rot[2] = rot[3] = rot[5] = rot[6] = rot[7] = 0.;
208}
209
211{
212 for (Int_t i = 0; i < 9; i++) {
213 rot[i] = 0.;
214 }
215}
216
217inline void FairGeoRotation::print() const
218{
219 for (Int_t i = 0; i < 9; i++) {
220 std::cout << rot[i] << " ";
221 }
222 std::cout << '\n';
223}
224
225#endif /* !FAIRGEOROTATION_H */
int32_t i
uint32_t j
Definition RawData.h:0
FairGeoRotation & invert()
void setEulerAngles(const Double_t, const Double_t, const Double_t)
void setMatrix(const Double_t *)
FairGeoVector operator*(const FairGeoVector &) const
Bool_t operator!=(const FairGeoRotation &)
FairGeoRotation & operator=(const FairGeoRotation &)
FairGeoRotation inverse() const
FairGeoRotation & transform(const FairGeoRotation &)
ClassDef(FairGeoRotation, 1)
Bool_t operator==(const FairGeoRotation &)
void setElement(const Double_t, const Int_t)
Double_t determinant() const
Double_t getElement(Int_t i, Int_t j) const
FairGeoRotation & operator*=(const FairGeoRotation &)
void print() const
Double_t operator()(Int_t) const
TRotMatrix * createTRotMatrix(const Text_t *name="", const Text_t *title="")
Double_t diff2(const FairGeoRotation &) const
GLdouble n
Definition glcorearb.h:1982
const GLdouble * v
Definition glcorearb.h:832
GLuint const GLchar * name
Definition glcorearb.h:781
GLboolean r
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233