Control software for the ??SRT telescope
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
1 /* * @file quaternion.h */
7 #include <ostream>
8 #endif
10 #include "position.h"
29 class Quaternion {
30  private:
31  // I'd like to make this const, so that there's no
32  // possibility of changing the quaternion once it's created,
33  // but I then need to assign the values inside the constructor,
34  // and that's not possible in C++ (ie, C++ isn't like Java, where
35  // the const/final status kicks in at the end of the constructor).
36  //
37  // It's possible to have quite a long argument with the compiler
38  // about this, and get drawn into a maze of twisty passages, all
39  // alike, which have scrawled on the walls remarks about
40  // non-default copy assignment operators, and copy-and-swap
41  // constructors, but it doesn't really seem worth the effort right now.
42  double q[4];
44  public:
45  Quaternion(); // default constructor
46  Quaternion(const double q0, const double q1, const double q2, const double q3);
52  I,
53  J,
54  K
55  };
57  Quaternion(const Position&);
59  Quaternion operator-() const; // unary minus
60  Quaternion operator+(const Quaternion&) const; // addition
61  Quaternion operator-(const Quaternion&) const; // subtraction
62  Quaternion operator*(const Quaternion&) const; // multiplication
63  Quaternion scale(double factor) const; // scale by real factor
64  Quaternion rotate(const Quaternion&) const; // A -> r*A*r.conj
65  Quaternion reflect(const Quaternion&) const; // A -> r*A*r.conj, but argument assumed to be vector
67  Quaternion conj(void) const;
68  const double* cpts(void) const;
69  Position coords(Position::System system=Position::TopoPolar,
70  Position::System from_system=Position::TopoPolar) const;
72  Quaternion cross(const Quaternion&, bool norm=false) const; // vector product of quaternions in Vec(H)
73  double dot(const Quaternion&) const; // scalar product of quaternions in Vec(H)
75  Quaternion rotation(const double angle) const;
77  bool is_unit_p(void);
79  static Quaternion vector(const double longitude, double latitude);
80  // static Quaternion rotation(const double longitude,
81  // const double colatitude,
82  // const double angle);
83  static const char* coords_str(const Quaternion&,
84  Position::System system=Position::TopoPolar,
85  bool sexagesimal_p=true);
86 };
89 std::ostream& operator<<(std::ostream &strm, const Quaternion& a);
90 #endif
92 #endif /* QUATERNION_H_LOADED */
double dot(const Quaternion &) const
Return scalar product of two quaternions in Vec(H).
Definition: quaternion.cpp:230
Quaternion operator-() const
Produce a new quaternion which is the negative of this one.
Definition: quaternion.cpp:81
Quaternion operator*(const Quaternion &) const
Performs the quaternion product of two quaternions.
Definition: quaternion.cpp:111
the basis quaternion in the j direction
Definition: quaternion.h:53
Position coords(Position::System system=Position::TopoPolar, Position::System from_system=Position::TopoPolar) const
Obtains the direction of a quaternion, by decomposing it into polar angles.
Definition: quaternion.cpp:276
Quaternion reflect(const Quaternion &) const
Reflect the quaternion through the line generated by the argument.
Definition: quaternion.cpp:172
The Quaternion class encapsulates quaternions (quelle surprise!), and provides a small set of operati...
Definition: quaternion.h:29
static Quaternion vector(const double longitude, double latitude)
Creates a new vector quaternion which is pointing in the direction of the given (east-)longitude and ...
Definition: quaternion.cpp:395
Quaternion rotation(const double angle) const
Produce a quaternion which specifies a rotation about the current quaternion, by the given angle...
Definition: quaternion.cpp:408
Quaternion scale(double factor) const
Return quaternion scaled by real factor.
Definition: quaternion.cpp:192
Quaternion operator+(const Quaternion &) const
Produces the sum of two quaternions.
Definition: quaternion.cpp:89
Quaternion rotate(const Quaternion &) const
'Rotate' the quaternion.
Definition: quaternion.cpp:137
The Position class allows us to represent positions on the celestial sphere (or on Earth...
Definition: position.h:15
The known coordinate systems.
Definition: position.h:33
Quaternion cross(const Quaternion &, bool norm=false) const
Return the vector product of this quaternion with the argument.
Definition: quaternion.cpp:208
the basis quaternion in the i direction
Definition: quaternion.h:52
bool is_unit_p(void)
Test whether a quaternion is a unit quaternion.
Definition: quaternion.cpp:259
The unit quaternion (sometimes used as a sentinel value; see is_unit_p())
Definition: quaternion.h:51
const double * cpts(void) const
The components of the quaternion, as an array of doubles, in radians.
Definition: quaternion.cpp:248
static const char * coords_str(const Quaternion &, Position::System system=Position::TopoPolar, bool sexagesimal_p=true)
Returns a pointer to a static buffer containing a formatted representation of the quaternion...
Definition: quaternion.cpp:312
Quaternion conj(void) const
Returns a new quaternion which is the conjugate of this one.
Definition: quaternion.cpp:240
the basis quaternion in the k direction
Definition: quaternion.h:54
The set of basis quaternions.
Definition: quaternion.h:51
The default constructor creates a K quaternion.
Definition: quaternion.cpp:20