QNANO
Quaternion.h
1 #ifndef QNANO_NEW_QUATERNION_DEFINED_H
2 #define QNANO_NEW_QUATERNION_DEFINED_H
3 
4 #include <cmath>
5 #include <vector>
6 #include <iostream>
7 #include <cstdlib>
8 #include <tools/Vec3d.h>
9 
10 class Quaternion{
11 private:
12  double u[4];
13 public:
14  double& operator[] (size_t i) {return u[i];}
15  const double& operator[] (size_t i) const {return u[i];}
16 
17  Vec3d rotate(const Vec3d &v)const;
18 
19  void set(double ur=1,double ux=0,double uy=0,double uz=0){
20  u[0]=ur; u[1]=ux; u[2]=uy; u[3]=uz;
21  }
22  inline double norm2()const{
23  return (u[0]*u[0]+u[1]*u[1]+u[2]*u[2]+u[3]*u[3]);
24  }
25  double norm()const{
26  return sqrt(norm2());
27  }
28  std::vector<std::vector<double> > RotMat() const;
29 
30 
31  Quaternion(double ur=1,double ux=0,double uy=0,double uz=0){
32  u[0]=ur; u[1]=ux; u[2]=uy; u[3]=uz;
33  }
34  Quaternion(const std::vector<double> &dvec){
35  if(dvec.size()<4){
36  std::cerr<<"Contructing Quaternion from double vector: vector needs to have 4 elements!"<<std::endl;
37  exit(1);
38  }
39  u[0]=dvec[0];
40  u[1]=dvec[1];
41  u[2]=dvec[2];
42  u[3]=dvec[3];
43  }
44  friend Quaternion operator*(const Quaternion &q1, const Quaternion &q2);
45  friend Quaternion conj(const Quaternion &q);
46 };
47 
48 Quaternion operator*(const Quaternion &q1, const Quaternion &q2);
49 Quaternion conj(const Quaternion &q);
50 
51 
52 #endif
Definition: Quaternion.h:10
Class to store positions and to handle operations on 3d vectors.
Definition: Vec3d.h:9