/usr/include/root/TQuaternion.h is in libroot-math-physics-dev 5.34.14-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | // @(#)root/physics:$Id$
// Author: Eric Anciant 28/06/2005
#ifndef ROOT_TQuaternion
#define ROOT_TQuaternion
#ifndef ROOT_TVector3
#include "TVector3.h"
#endif
#ifndef ROOT_TMath
#include "TMath.h"
#endif
class TQuaternion : public TObject {
public:
TQuaternion(Double_t real = 0, Double_t X = 0, Double_t Y = 0, Double_t Z = 0);
TQuaternion(const TVector3 & vector, Double_t real = 0);
TQuaternion(const Double_t *);
TQuaternion(const Float_t *);
// Constructors from an array : 0 to 2 = vector part, 3 = real part
TQuaternion(const TQuaternion &);
// The copy constructor.
virtual ~TQuaternion();
// Destructor
Double_t operator () (int) const;
inline Double_t operator [] (int) const;
// Get components by index. 0 to 2 = vector part, 3 = real part
Double_t & operator () (int);
inline Double_t & operator [] (int);
// Set components by index. 0 to 2 = vector part, 3 = real part
inline TQuaternion& SetRXYZ(Double_t r,Double_t x,Double_t y,Double_t z);
inline TQuaternion& SetRV(Double_t r, TVector3& vect);
// Sets components
TQuaternion& SetAxisQAngle(TVector3& v,Double_t QAngle);
// Set from vector direction and quaternion angle
Double_t GetQAngle() const;
TQuaternion& SetQAngle(Double_t angle);
// set and get quaternion angle
inline void GetRXYZ(Double_t *carray) const;
inline void GetRXYZ(Float_t *carray) const;
// Get the components into an array : 0 to 2 vector part, 3 real part
// not checked!
// --------------- real to quaternion algebra
inline TQuaternion& operator=(Double_t r);
inline Bool_t operator == (Double_t r) const;
inline Bool_t operator != (Double_t r) const;
inline TQuaternion& operator+=(Double_t real);
inline TQuaternion& operator-=(Double_t real);
inline TQuaternion& operator*=(Double_t real);
inline TQuaternion& operator/=(Double_t real);
TQuaternion operator*(Double_t real) const;
TQuaternion operator+(Double_t real) const;
TQuaternion operator-(Double_t real) const;
TQuaternion operator/(Double_t real) const;
// ---------------- vector to quaternion algebra
inline TQuaternion& operator=(const TVector3& );
inline Bool_t operator == (const TVector3&) const;
inline Bool_t operator != (const TVector3&) const;
inline TQuaternion& operator+=(const TVector3 &vector);
inline TQuaternion& operator-=(const TVector3 &vector);
TQuaternion& MultiplyLeft(const TVector3 &vector);
TQuaternion& operator*=(const TVector3 &vector);
TQuaternion& DivideLeft(const TVector3 &vector);
TQuaternion& operator/=(const TVector3 &vector);
TQuaternion operator+(const TVector3 &vector) const;
TQuaternion operator-(const TVector3 &vector) const;
TQuaternion LeftProduct(const TVector3 &vector) const;
TQuaternion operator*(const TVector3 &vector) const;
TQuaternion LeftQuotient(const TVector3 &vector) const;
TQuaternion operator/(const TVector3 &vector) const;
// ----------------- quaternion algebra
inline TQuaternion& operator=(const TQuaternion& );
inline Bool_t operator == (const TQuaternion&) const;
inline Bool_t operator != (const TQuaternion&) const;
inline TQuaternion& operator+=(const TQuaternion &quaternion);
inline TQuaternion& operator-=(const TQuaternion &quaternion);
TQuaternion& MultiplyLeft(const TQuaternion &quaternion);
TQuaternion& operator*=(const TQuaternion &quaternion);
TQuaternion& DivideLeft(const TQuaternion &quaternion);
TQuaternion& operator/=(const TQuaternion &quaternion);
TQuaternion operator+(const TQuaternion &quaternion) const;
TQuaternion operator-(const TQuaternion &quaternion) const;
TQuaternion LeftProduct(const TQuaternion &quaternion) const;
TQuaternion operator*(const TQuaternion &quaternion) const;
TQuaternion LeftQuotient(const TQuaternion &quaternion) const;
TQuaternion operator/(const TQuaternion &quaternion) const;
// ------------------ general algebra
inline Double_t Norm() const; // quaternion magnitude
inline Double_t Norm2() const; // quaternion squared magnitude
Double_t QMag() const { return Norm(); } // quaternion magnitude
Double_t QMag2() const { return Norm2(); } // quaternion squared magnitude
inline TQuaternion& Normalize(); // normalize quaternion
inline TQuaternion operator - () const; // Unary minus.
inline TQuaternion Conjugate() const;
TQuaternion Invert() const;
void Rotate(TVector3& vect) const;
TVector3 Rotation(const TVector3& vect) const;
void Print(Option_t* option="") const;
Double_t fRealPart; // Real part
TVector3 fVectorPart; // vector part
ClassDef(TQuaternion,1) // a quaternion class
};
// getters / setters
inline TQuaternion& TQuaternion::SetRXYZ(Double_t r,Double_t x,Double_t y,Double_t z) {
fRealPart = r;
fVectorPart.SetXYZ(x,y,z);
return (*this);
}
inline TQuaternion& TQuaternion::SetRV(Double_t r, TVector3& vect) {
fRealPart = r;
fVectorPart= vect;
return (*this);
}
inline void TQuaternion::GetRXYZ(Double_t *carray) const {
fVectorPart.GetXYZ(carray+1);
carray[0] = fRealPart;
}
inline void TQuaternion::GetRXYZ(Float_t *carray) const {
fVectorPart.GetXYZ(carray+1);
carray[0] = (Float_t) fRealPart;
}
inline Double_t & TQuaternion::operator[] (int i) { return operator()(i); }
inline Double_t TQuaternion::operator[] (int i) const { return operator()(i); }
// ------------------ real to quaternion algebra
inline Bool_t TQuaternion::operator == (Double_t r) const {
return (fVectorPart.Mag2()==0 && fRealPart == r) ? kTRUE : kFALSE;
}
inline Bool_t TQuaternion::operator != (Double_t r) const {
return (fVectorPart.Mag2()!=0 || fRealPart != r) ? kTRUE : kFALSE;
}
inline TQuaternion& TQuaternion::operator=(Double_t r) {
fRealPart = r;
fVectorPart.SetXYZ(0,0,0);
return (*this);
}
inline TQuaternion& TQuaternion::operator+=(Double_t real) {
fRealPart += real;
return (*this);
}
inline TQuaternion& TQuaternion::operator-=(Double_t real) {
fRealPart -= real;
return (*this);
}
inline TQuaternion& TQuaternion::operator*=(Double_t real) {
fRealPart *= real;
fVectorPart *= real;
return (*this);
}
inline TQuaternion& TQuaternion::operator/=(Double_t real) {
if (real!=0) {
fRealPart /= real;
fVectorPart.SetX(fVectorPart.x()/real); // keep numericaly compliant with operator/(Double_t)
fVectorPart.SetY(fVectorPart.y()/real);
fVectorPart.SetZ(fVectorPart.z()/real);
} else {
Error("operator/=()(Double_t)", "bad value (%f) ignored",real);
}
return (*this);
}
TQuaternion operator + (Double_t r, const TQuaternion & q);
TQuaternion operator - (Double_t r, const TQuaternion & q);
TQuaternion operator * (Double_t r, const TQuaternion & q);
TQuaternion operator / (Double_t r, const TQuaternion & q);
// ------------------- vector to quaternion algebra
inline Bool_t TQuaternion::operator == (const TVector3& V) const {
return (fVectorPart == V && fRealPart == 0) ? kTRUE : kFALSE;
}
inline Bool_t TQuaternion::operator != (const TVector3& V) const {
return (fVectorPart != V || fRealPart != 0) ? kTRUE : kFALSE;
}
inline TQuaternion& TQuaternion::operator=(const TVector3& vect) {
fRealPart = 0;
fVectorPart.SetXYZ(vect.X(),vect.Y(),vect.Z());
return *this;
}
inline TQuaternion& TQuaternion::operator+=(const TVector3 &vect) {
fVectorPart += vect;
return (*this);
}
inline TQuaternion& TQuaternion::operator-=(const TVector3 &vect) {
fVectorPart -= vect;
return (*this);
}
TQuaternion operator + (const TVector3 &V, const TQuaternion &Q);
TQuaternion operator - (const TVector3 &V, const TQuaternion &Q);
TQuaternion operator * (const TVector3 &V, const TQuaternion &Q);
TQuaternion operator / (const TVector3 &V, const TQuaternion &Q);
// --------------- quaternion algebra
inline Bool_t TQuaternion::operator == (const TQuaternion& Q) const {
return (fVectorPart == Q.fVectorPart && fRealPart == Q.fRealPart) ? kTRUE : kFALSE;
}
inline Bool_t TQuaternion::operator != (const TQuaternion& Q) const {
return (fVectorPart != Q.fVectorPart || fRealPart != Q.fRealPart) ? kTRUE : kFALSE;
}
inline TQuaternion& TQuaternion::operator=(const TQuaternion& quat) {
if (&quat != this) {
fRealPart = quat.fRealPart;
fVectorPart.SetXYZ(quat.fVectorPart.X(),quat.fVectorPart.Y(),quat.fVectorPart.Z());
}
return (*this);
}
inline TQuaternion& TQuaternion::operator+=(const TQuaternion &quaternion) {
fVectorPart += quaternion.fVectorPart;
fRealPart += quaternion.fRealPart;
return (*this);
}
inline TQuaternion& TQuaternion::operator-=(const TQuaternion &quaternion) {
fVectorPart -= quaternion.fVectorPart;
fRealPart -= quaternion.fRealPart;
return (*this);
}
inline TQuaternion TQuaternion::operator+(const TQuaternion &quaternion) const {
return TQuaternion(fVectorPart+quaternion.fVectorPart, fRealPart+quaternion.fRealPart);
}
inline TQuaternion TQuaternion::operator-(const TQuaternion &quaternion) const {
return TQuaternion(fVectorPart-quaternion.fVectorPart, fRealPart-quaternion.fRealPart);
}
// ---------------- general
inline Double_t TQuaternion::Norm() const {
return TMath::Sqrt(Norm2());
}
inline Double_t TQuaternion::Norm2() const {
return fRealPart*fRealPart + fVectorPart.Mag2();
}
inline TQuaternion& TQuaternion::Normalize() {
(*this) /= Norm();
return (*this);
}
inline TQuaternion TQuaternion::operator - () const {
return TQuaternion(-fVectorPart,-fRealPart);
}
inline TQuaternion TQuaternion::Conjugate() const {
return TQuaternion(-fVectorPart,fRealPart);
}
#endif
|