QP
0.7SNAPSHOT
Control software for the ??SRT telescope

The Quaternion class encapsulates quaternions (quelle surprise!), and provides a small set of operations for manipulating them. More...
#include <quaternion.h>
Public Types  
enum  basis_quaternion { Unit, I, J, K } 
The set of basis quaternions. More...  
Public Member Functions  
Quaternion ()  
The default constructor creates a K quaternion. More...  
Quaternion (const double q0, const double q1, const double q2, const double q3)  
The constructor creates a quaternion from four coefficients of the basis quaternions. More...  
Quaternion (const basis_quaternion)  
Produce one of the basis quaternions.  
Quaternion (const Position &)  
Create a quaternion vector which points in the direction of the given position.  
Quaternion  operator () const 
Produce a new quaternion which is the negative of this one.  
Quaternion  operator+ (const Quaternion &) const 
Produces the sum of two quaternions.  
Quaternion  operator (const Quaternion &) const 
Produces the difference of two quaternions.  
Quaternion  operator* (const Quaternion &) const 
Performs the quaternion product of two quaternions.  
Quaternion  scale (double factor) const 
Return quaternion scaled by real factor.  
Quaternion  rotate (const Quaternion &) const 
'Rotate' the quaternion. More...  
Quaternion  reflect (const Quaternion &) const 
Reflect the quaternion through the line generated by the argument. More...  
Quaternion  conj (void) const 
Returns a new quaternion which is the conjugate of this one.  
const double *  cpts (void) const 
The components of the quaternion, as an array of doubles, in radians.  
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. More...  
Quaternion  cross (const Quaternion &, bool norm=false) const 
Return the vector product of this quaternion with the argument. More...  
double  dot (const Quaternion &) const 
Return scalar product of two quaternions in Vec(H). More...  
Quaternion  rotation (const double angle) const 
Produce a quaternion which specifies a rotation about the current quaternion, by the given angle.  
bool  is_unit_p (void) 
Test whether a quaternion is a unit quaternion. More...  
Static Public Member Functions  
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 latitude. More...  
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. More...  
The Quaternion class encapsulates quaternions (quelle surprise!), and provides a small set of operations for manipulating them.
The directions in this module are described either in terms of the basis quaternions 1, i, j, k, or in terms of longitude [0..2pi] and latitude [pi/2..+pi/2], where the direction i is (long,lat) = (0,0), j is (pi/2, 0) and k is (0, pi/2). The longitude coordinate therefore increases from i to j (ie, moving eastwards).
Although it doesn't much matter to this class, when viewed as a topocentric coordinate system, i should be taken as pointing south, and j east.
The arithmetic operations in this class return new constant objects, rather than mutating existing ones.
The set of basis quaternions.
Enumerator  

Unit 
The unit quaternion (sometimes used as a sentinel value; see is_unit_p()) 
I 
the basis quaternion in the i direction 
J 
the basis quaternion in the j direction 
K 
the basis quaternion in the k direction 
Quaternion::Quaternion  (  ) 
The default constructor creates a K quaternion.
Creating a Unit quaternion might be more intuitive, but since this isn't a vector, it has the potential to cause lots of trouble if used accidentally.
Quaternion::Quaternion  (  const double  q0, 
const double  q1,  
const double  q2,  
const double  q3  
) 
The constructor creates a quaternion from four coefficients of the basis quaternions.
This is the only constructor that can create a nonunit quaternion.
Position Quaternion::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.
The coordinates are returned as part of a Position object, so the specific result coordinate system may be chosen using the arguments.
system  the system in which the result angles are to be expressed 
from_system  the system in which the quaternion's rectangular components should be taken to be expressed 

static 
Returns a pointer to a static buffer containing a formatted representation of the quaternion.
q  the quaternion to be formatted 
system  the system to be used for the formatted output 
sexagesimal_p  if true, output as sexagesimal, if false, in radians 
Quaternion Quaternion::cross  (  const Quaternion &  arg, 
bool  norm = false 

)  const 
Return the vector product of this quaternion with the argument.
We assume, but don't check, that the both the current and the argument quaternion are in Vec(H).
arg  the quaternion to be crossed with this one (on the right) 
norm  if true, the result is normalised to unit length 
double Quaternion::dot  (  const Quaternion &  arg  )  const 
Return scalar product of two quaternions in Vec(H).
We assume, but don't check, that the both the current and the argument quaternion are in Vec(H).
bool Quaternion::is_unit_p  (  void  ) 
Test whether a quaternion is a unit quaternion.
That is, test whether it is (1, 0, 0, 0). We sometimes use this quaternion, generated by Quaternion(const basis_quaternion), as a sentinel value.
Quaternion Quaternion::reflect  (  const Quaternion &  rq  )  const 
Reflect the quaternion through the line generated by the argument.
This is equivalent to a rotation of pi radians around the argument, which is assumed to be a unit vector. The result of this method should be equivalent to the application of Quaternion::rotate, but should be faster because of the assumption that the argument is a vector.
rq  the quaternion which generates the rotation, which is assumed to be a unit vector 
Quaternion Quaternion::rotate  (  const Quaternion &  rq  )  const 
'Rotate' the quaternion.
Given a quaternion, r, and taking the current quaternion to be A, return r*A*r.conj
. This requires 23 multiplications and 24 additions, as opposed to 32 multiplications and 24 additions when done the 'long' way. This should also be more accurate.
Note that this is different from the rotation method, which constructs a quaternion which generates a rotation.
See quaternionpointing notes, at note rotation
.
rq  the quaternion which generates the rotation, which is assumed to be a unit quaternion 

static 
Creates a new vector quaternion which is pointing in the direction of the given (east)longitude and latitude.
Both of the angles are given in 'polar' radians, thus east of south.