ROOT logo
#ifndef HGEOMROTATION_H
#define HGEOMROTATION_H
using namespace std;
#include "TObject.h"
#include "hgeomvector.h"
#include "TRotMatrix.h"
#include <iostream> 
#include <iomanip>

class HGeomRotation : public TObject {
protected:
  Double_t rot[9];
public:
  inline HGeomRotation();
  inline HGeomRotation(const Double_t*);
  HGeomRotation(const Double_t,const Double_t,const Double_t);
  ~HGeomRotation() {}
  inline void setMatrix(const Double_t*);
  inline void setMatrix(const Float_t*);
  void setEulerAngles(const Double_t,const Double_t,const Double_t);
  inline void setElement(const Double_t,const Int_t);
  inline Double_t operator () (Int_t) const;
  inline HGeomRotation& operator = (const HGeomRotation&);
  inline Bool_t operator == (const HGeomRotation&);
  inline Bool_t operator != (const HGeomRotation&);
  inline HGeomVector operator * (const HGeomVector&) const;
  inline HGeomRotation operator * (const HGeomRotation&) const;
  inline HGeomRotation& operator *= (const HGeomRotation&);
  inline HGeomRotation& transform(const HGeomRotation&);
  inline Bool_t isUnitMatrix();
  inline HGeomRotation inverse() const;
  inline HGeomRotation& invert();
  inline Double_t determinant() const;
  Double_t diff2(const HGeomRotation&) const;
  inline Double_t getElement(Int_t i,Int_t j) const;
  inline void setUnitMatrix();
  inline void setZero();
  inline void print() const;
  TRotMatrix* createTRotMatrix(const Text_t* name="",const Text_t* title="");

  ClassDef(HGeomRotation,1) // rotation matrix
};

// -------------------- inlines ---------------------------

inline HGeomRotation::HGeomRotation() {
  rot[0]=rot[4]=rot[8]=1.;
  rot[1]=rot[2]=rot[3]=rot[5]=rot[6]=rot[7]=0.;
}

inline Double_t HGeomRotation::operator () (Int_t i) const {
  if (i>=0 && i<9) return rot[i];
  Error("operator()","bad index");
  return 0;
}

inline HGeomRotation::HGeomRotation(const Double_t* a) {
  for(Int_t i=0;i<9;i++) rot[i]=a[i];
}
  
inline void HGeomRotation::setMatrix(const Double_t* a) {
  for(Int_t i=0;i<9;i++) rot[i]=a[i];
}
  
inline void HGeomRotation::setMatrix(const Float_t* a) {
  for(Int_t i=0;i<9;i++) rot[i]=a[i];
}
  
inline void HGeomRotation::setElement(const Double_t a, const Int_t i) {
  if (i<9) rot[i]=a;
}

inline Double_t HGeomRotation::getElement(Int_t i,Int_t j) const {
  return rot[i*3+j];
}

inline HGeomRotation& HGeomRotation::operator = (const HGeomRotation& r) {
  for(Int_t i=0;i<9;i++) rot[i]=r(i);
  return *this;
}

inline Bool_t HGeomRotation::operator == (const HGeomRotation& r) {
  Int_t i=0;
  while (i<9) {
    if (rot[i]!=r(i)) return kFALSE;
    i++;
  }
  return kTRUE;
}

inline Bool_t HGeomRotation::operator != (const HGeomRotation& r) {
  Int_t i=0;
  while (i<9) {
    if (rot[i]!=r(i)) return kTRUE;
    i++;
  }
  return kFALSE;
}
 
inline HGeomVector HGeomRotation::operator * (const HGeomVector& v) const {
  return HGeomVector(rot[0]*v(0)+rot[1]*v(1)+rot[2]*v(2),
                     rot[3]*v(0)+rot[4]*v(1)+rot[5]*v(2),
                     rot[6]*v(0)+rot[7]*v(1)+rot[8]*v(2));
}

inline HGeomRotation HGeomRotation::operator * (const HGeomRotation& r) const {
  Double_t a[9];
  for(Int_t i=0;i<9;i++) a[i]=0;
  for(Int_t i=0;i<3;i++) {
    for(Int_t j=0;j<3;j++) {
      Int_t n=3*i+j;
      for(Int_t k=0;k<3;k++) a[n]+=rot[3*i+k]*r(3*k+j);
    }
  }
  return HGeomRotation(&a[0]);
}

inline HGeomRotation& HGeomRotation::operator *= (const HGeomRotation& r) {
  return *this=operator * (r);  
}

inline   HGeomRotation& HGeomRotation::transform(const HGeomRotation& r) {
  return *this=r*(*this);
}

inline Bool_t HGeomRotation::isUnitMatrix() {
  return (rot[0]==1. && rot[1]==0. && rot[2]==0. &&
          rot[3]==0. && rot[4]==1. && rot[5]==0. &&
          rot[6]==0. && rot[7]==0. && rot[8]==1.)  ? kTRUE : kFALSE;
}

inline HGeomRotation HGeomRotation::inverse() const {
  Double_t a[9];
  for(Int_t i=0;i<3;i++) {
    for(Int_t j=0;j<3;j++) a[j+3*i]=rot[i+3*j];
  }
  return HGeomRotation(a); 
}

inline HGeomRotation& HGeomRotation::invert() {
  return *this=inverse();
}

inline Double_t HGeomRotation::determinant() const {
  return rot[0]*(rot[4]*rot[8]-rot[7]*rot[5])
        -rot[3]*(rot[1]*rot[8]-rot[7]*rot[2])
        +rot[6]*(rot[1]*rot[5]-rot[4]*rot[2]);
}

inline void HGeomRotation::setUnitMatrix(){
  rot[0]=rot[4]=rot[8]=1.;
  rot[1]=rot[2]=rot[3]=rot[5]=rot[6]=rot[7]=0.;
}

inline void HGeomRotation::setZero(){
  for(Int_t i=0;i<9;i++) rot[i]=0.;
}

inline void HGeomRotation::print() const {
  for(Int_t i=0;i<9;i++) cout<<rot[i]<<"  ";
  cout<<'\n';
}

#endif /* !HGEOMROTATION_H */
 hgeomrotation.h:1
 hgeomrotation.h:2
 hgeomrotation.h:3
 hgeomrotation.h:4
 hgeomrotation.h:5
 hgeomrotation.h:6
 hgeomrotation.h:7
 hgeomrotation.h:8
 hgeomrotation.h:9
 hgeomrotation.h:10
 hgeomrotation.h:11
 hgeomrotation.h:12
 hgeomrotation.h:13
 hgeomrotation.h:14
 hgeomrotation.h:15
 hgeomrotation.h:16
 hgeomrotation.h:17
 hgeomrotation.h:18
 hgeomrotation.h:19
 hgeomrotation.h:20
 hgeomrotation.h:21
 hgeomrotation.h:22
 hgeomrotation.h:23
 hgeomrotation.h:24
 hgeomrotation.h:25
 hgeomrotation.h:26
 hgeomrotation.h:27
 hgeomrotation.h:28
 hgeomrotation.h:29
 hgeomrotation.h:30
 hgeomrotation.h:31
 hgeomrotation.h:32
 hgeomrotation.h:33
 hgeomrotation.h:34
 hgeomrotation.h:35
 hgeomrotation.h:36
 hgeomrotation.h:37
 hgeomrotation.h:38
 hgeomrotation.h:39
 hgeomrotation.h:40
 hgeomrotation.h:41
 hgeomrotation.h:42
 hgeomrotation.h:43
 hgeomrotation.h:44
 hgeomrotation.h:45
 hgeomrotation.h:46
 hgeomrotation.h:47
 hgeomrotation.h:48
 hgeomrotation.h:49
 hgeomrotation.h:50
 hgeomrotation.h:51
 hgeomrotation.h:52
 hgeomrotation.h:53
 hgeomrotation.h:54
 hgeomrotation.h:55
 hgeomrotation.h:56
 hgeomrotation.h:57
 hgeomrotation.h:58
 hgeomrotation.h:59
 hgeomrotation.h:60
 hgeomrotation.h:61
 hgeomrotation.h:62
 hgeomrotation.h:63
 hgeomrotation.h:64
 hgeomrotation.h:65
 hgeomrotation.h:66
 hgeomrotation.h:67
 hgeomrotation.h:68
 hgeomrotation.h:69
 hgeomrotation.h:70
 hgeomrotation.h:71
 hgeomrotation.h:72
 hgeomrotation.h:73
 hgeomrotation.h:74
 hgeomrotation.h:75
 hgeomrotation.h:76
 hgeomrotation.h:77
 hgeomrotation.h:78
 hgeomrotation.h:79
 hgeomrotation.h:80
 hgeomrotation.h:81
 hgeomrotation.h:82
 hgeomrotation.h:83
 hgeomrotation.h:84
 hgeomrotation.h:85
 hgeomrotation.h:86
 hgeomrotation.h:87
 hgeomrotation.h:88
 hgeomrotation.h:89
 hgeomrotation.h:90
 hgeomrotation.h:91
 hgeomrotation.h:92
 hgeomrotation.h:93
 hgeomrotation.h:94
 hgeomrotation.h:95
 hgeomrotation.h:96
 hgeomrotation.h:97
 hgeomrotation.h:98
 hgeomrotation.h:99
 hgeomrotation.h:100
 hgeomrotation.h:101
 hgeomrotation.h:102
 hgeomrotation.h:103
 hgeomrotation.h:104
 hgeomrotation.h:105
 hgeomrotation.h:106
 hgeomrotation.h:107
 hgeomrotation.h:108
 hgeomrotation.h:109
 hgeomrotation.h:110
 hgeomrotation.h:111
 hgeomrotation.h:112
 hgeomrotation.h:113
 hgeomrotation.h:114
 hgeomrotation.h:115
 hgeomrotation.h:116
 hgeomrotation.h:117
 hgeomrotation.h:118
 hgeomrotation.h:119
 hgeomrotation.h:120
 hgeomrotation.h:121
 hgeomrotation.h:122
 hgeomrotation.h:123
 hgeomrotation.h:124
 hgeomrotation.h:125
 hgeomrotation.h:126
 hgeomrotation.h:127
 hgeomrotation.h:128
 hgeomrotation.h:129
 hgeomrotation.h:130
 hgeomrotation.h:131
 hgeomrotation.h:132
 hgeomrotation.h:133
 hgeomrotation.h:134
 hgeomrotation.h:135
 hgeomrotation.h:136
 hgeomrotation.h:137
 hgeomrotation.h:138
 hgeomrotation.h:139
 hgeomrotation.h:140
 hgeomrotation.h:141
 hgeomrotation.h:142
 hgeomrotation.h:143
 hgeomrotation.h:144
 hgeomrotation.h:145
 hgeomrotation.h:146
 hgeomrotation.h:147
 hgeomrotation.h:148
 hgeomrotation.h:149
 hgeomrotation.h:150
 hgeomrotation.h:151
 hgeomrotation.h:152
 hgeomrotation.h:153
 hgeomrotation.h:154
 hgeomrotation.h:155
 hgeomrotation.h:156
 hgeomrotation.h:157
 hgeomrotation.h:158
 hgeomrotation.h:159
 hgeomrotation.h:160
 hgeomrotation.h:161
 hgeomrotation.h:162
 hgeomrotation.h:163
 hgeomrotation.h:164