Follow this link to skip to the main content

claraty::Quaternion< T > Class Template Reference

#include <quaternion.h>

Inheritance diagram for claraty::Quaternion< T >:

Inheritance graph
[legend]
Collaboration diagram for claraty::Quaternion< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Quaternion ()
 Quaternion (const T *array)
 Quaternion (const Vector< T > &v)
 Quaternion (const T &r, const T &p, const T &y)
 Quaternion (const T &scalar_1, const T &scalar_2, const T &scalar_3, const T &scalar_4)
 Quaternion (ROTATION_TYPE type, const T &r, const T &p=T(), const T &y=T())
 Quaternion (const Quaternion &q)
 Quaternion (const Base_Quaternion< T > &q)
 Quaternion (const RMatrix< T > &m)
 Quaternion (const Vector< T > &a, const Vector< T > &b)
 Quaternion (const Vector< T > &euler_vector, const T &euler_angle)
 ~Quaternion ()
T & operator() (int n)
const T & operator() (int n) const
Quaternion operator= (const Quaternion &rhs)
Quaternion operator= (const RMatrix< T > &rhs)
Quaternion operator * (const Quaternion &rhs) const
Point< T > operator * (const Point< T > &rhs) const
Quaternion operator/ (const Quaternion &rhs)
bool operator== (const Quaternion &rhs) const
void rotation_matrix_to_quaternion (const RMatrix< T > &m)
RMatrix< T > quaternion_to_rotation_matrix () const
RMatrix< T > get_rotation_matrix () const
Vector< T > quaternion_to_theta_triple () const
void theta_triple_to_quaternion (const Vector< T > &a)
void euler_parameters_to_quaternion (const Vector< T > &euler_vector, const T &euler_angle)
get_euler_angle ()
norm () const
void conjugate ()
void negate ()
Quaternion interpolate (const T &k, Quaternion &a) const
void scale (const T &d)
void normalize ()
void power (const T &p)
void standardize ()
void set_identity ()
bool io (FDM_Map map)
Quaternion reverse ()
Vector< T > get_x_axis () const
Vector< T > get_y_axis () const
Vector< T > get_z_axis () const
void get_rpy_angles (T &roll, T &pitch, T &yaw) const

Public Attributes

_elements [4]

Static Public Attributes

static const Base_Quaternion<
T > 
identity

Friends

template<class Y>
std::ostream & operator<< (std::ostream &os, const Quaternion< Y > &q)

Detailed Description

template<class T>
class claraty::Quaternion< T >

Definition at line 64 of file quaternion.h.


Constructor & Destructor Documentation

template<class T>
claraty::Quaternion< T >::Quaternion (  )  [inline]

Definition at line 73 of file quaternion.h.

00073 : Base_Quaternion<T>(identity) {}

template<class T>
claraty::Quaternion< T >::Quaternion ( const T *  array  ) 

This constructor copies an input array of T into its elements.

Definition at line 163 of file quaternion.h.

References EPSILON, and claraty::Quaternion< T >::norm().

00164 {
00165   assert(this->_elements != NULL);
00166 
00167   // Copy the data from array to this quaternion
00168   for (int i=0; i<4; i++)
00169     this->_elements[i] = array[i];
00170 
00171   // Check for consistancy of elements
00172   assert(norm() - 1.0 < EPSILON);
00173 }

Here is the call graph for this function:

template<class T>
claraty::Quaternion< T >::Quaternion ( const Vector< T > &  a  ) 

This constructor creates a quaternion with the rotation transformation corresponding to the rotation represented by three angles about the X-, Y- and Z- axes.

Definition at line 181 of file quaternion.h.

References claraty::Quaternion< T >::theta_triple_to_quaternion().

00182 {
00183   // cout <<
00184   // "Quaternion constructor Quaternion(Vector<T> & a)"
00185   // << endl;
00186 
00187   assert(this->_elements != NULL);
00188 
00189   theta_triple_to_quaternion(a);
00190 
00191 }

Here is the call graph for this function:

template<class T>
claraty::Quaternion< T >::Quaternion ( const T &  r,
const T &  p,
const T &  y 
)

template<class T>
claraty::Quaternion< T >::Quaternion ( const T &  scalar_1,
const T &  scalar_2,
const T &  scalar_3,
const T &  scalar_4 
)

This constructor creates a quaternion with elements set to equal to the 4 input parameters.

Definition at line 236 of file quaternion.h.

References claraty::Base_Quaternion< T >::_elements.

00238 {
00239   // cout <<
00240   // "Quaternion constructor Quaternion(const T& scalar_1, const T& scalar_2, const T& scalar_3, const T& scalar_4)"
00241   // << endl;
00242 
00243   assert(this->_elements != NULL);
00244 
00245   // Initialize the zero transformation quaternion
00246   this->_elements[0] = scalar_1;
00247   this->_elements[1] = scalar_2;
00248   this->_elements[2] = scalar_3;
00249   this->_elements[3] = scalar_4;
00250 
00251   // Don't normalize because the entered values may intentionally not represent a
00252   // unit quaternion
00253   // normalize();
00254 
00255 }

template<class T>
claraty::Quaternion< T >::Quaternion ( ROTATION_TYPE  type,
const T &  r,
const T &  p = T(),
const T &  y = T() 
)

This constructor creates a quaternion with elements set to equal to the 4 input parameters.

Definition at line 197 of file quaternion.h.

References claraty::ANGLE_AXIS, claraty::EULER_ZYZ, claraty::RPY, claraty::RX, claraty::RY, and claraty::RZ.

00198 {
00199   // cout <<
00200   // "Quaternion constructor Quaternion(const T& scalar_1, const T& scalar_2, const T& scalar_3, const T& scalar_4)"
00201   // << endl;
00202 
00203   assert(this->_elements != NULL);
00204   
00205   //RMatrix<T> temp(type, r, p, y);
00206   //*this = Quaternion<T>(temp);
00207 
00208   RMatrix<T> temp;
00209   
00210   switch(type) {
00211     
00212   case RX:
00213   case RY:
00214   case RZ:
00215     temp = RMatrix<T>(type, r );
00216     break;
00217     
00218     
00219   case EULER_ZYZ:     // Rotation about rotated axes Z, Y, Z
00220   case RPY:           // Rotation about fixed axes X, Y, Z
00221   case ANGLE_AXIS:    // Angle-axis rotation about X, Y, Z axes
00222     temp = RMatrix<T>(type, r, p, y);
00223     break;
00224     
00225   default:
00226     std::cout << "rotation matrix error: undefined matrix type" << std::endl;
00227   }
00228   *this = Quaternion<T>(temp);
00229 }

template<class T>
claraty::Quaternion< T >::Quaternion ( const Quaternion< T > &  q  ) 

This is a copy constructor

Definition at line 260 of file quaternion.h.

References claraty::Base_Quaternion< T >::_elements.

00261 {
00262   // cout << "Quaternion constructor Quaternion(const Quaternion& q)" << endl;
00263 
00264   assert(this->_elements != NULL);
00265 
00266   // Initialize this quaternion to be equal to the input quaternion
00267   for (int i=0; i<4; i++)
00268      this->_elements[i] = q._elements[i];
00269 
00270 }

template<class T>
claraty::Quaternion< T >::Quaternion ( const Base_Quaternion< T > &  q  )  [inline]

Definition at line 82 of file quaternion.h.

00082 : Base_Quaternion<T>(q) {}

template<class T>
claraty::Quaternion< T >::Quaternion ( const RMatrix< T > &  m  ) 

This constructor creates a quaternion that represents the rotation transformation specified in the input rotation matrix.

Definition at line 276 of file quaternion.h.

References claraty::Quaternion< T >::rotation_matrix_to_quaternion().

00277 {
00278   // cout << "Quaternion constructor Quaternion(const RMatrix& m)" << endl;
00279 
00280   assert(this->_elements != NULL);
00281 
00282   rotation_matrix_to_quaternion(m);
00283 }

Here is the call graph for this function:

template<class T>
claraty::Quaternion< T >::Quaternion ( const Vector< T > &  a,
const Vector< T > &  b 
)

This constructor creates the quaternion corresponding to the rotation of a 3-D vector a to a 3-D vector b.

Definition at line 290 of file quaternion.h.

References claraty::Vector< T >::cross(), claraty::Vector< T >::dot(), claraty::Quaternion< T >::euler_parameters_to_quaternion(), M_PI, claraty::Vector< T >::magnitude(), and claraty::Quaternion< T >::set_identity().

00291 {
00292   if (a == b)
00293     {
00294       set_identity();
00295       return;
00296     }
00297   // make copies because a and b are consts
00298   Vector<T> a_copy(a);
00299   Vector<T> b_copy(b);
00300   Vector<T> b_copy_neg(Point<T>(-b(0), -b(1), -b(2)));
00301   
00302   assert(this->_elements != NULL);
00303 
00304   // Make sure that the input vectors are not of zero magnitude and have
00305   // 3 elements
00306   assert(a_copy.magnitude() != 0.0);
00307   assert(b_copy.magnitude() != 0.0);
00308   assert(a_copy.size() == 3);
00309   assert(b_copy.size() == 3);
00310 
00311   // Normalize the vectors -- cannot use fnorm for now because it
00312   // appears to be incorrect
00313   T norm_a = sqrt(a_copy.dot(a_copy));
00314   T norm_b = sqrt(b_copy.dot(b_copy));
00315   T norm_b_neg = sqrt(b_copy_neg.dot(b_copy_neg));
00316   a_copy /= norm_a;
00317   b_copy /= norm_b;
00318   b_copy_neg /= norm_b_neg;
00319 
00320   //std::cout << "a_copy " << a_copy << std::endl;
00321   //std::cout << "b_copy " << b_copy << std::endl;
00322 
00323   Vector<T> euler_vector(3);
00324 
00325   //Handle special case when vectors are aligned
00326   T euler_angle;
00327 
00328   // If vectors point in the same direction
00329   if (a_copy == b_copy)
00330     {
00331       // The euler angle is zero so it doesn't matter what the euler
00332       // vector is
00333       euler_vector = Vector<T>(Point<T>(1.0, 0.0, 0.0)); 
00334       euler_angle  = 0;
00335     }
00336   // if vectors point in oposite directions
00337   else if (a_copy == b_copy_neg)
00338     {
00339       // Arbitrarily choose (1.0, 0.0, 0.0) and see if it is
00340       // perpendicular to a_copy
00341       if (a_copy.dot(Vector<T>(Point<T>(1.0, 0.0, 0.0))) == 0.0)
00342         euler_vector = Vector<T>(Point<T>(1.0, 0.0, 0.0));
00343 
00344       // else try (0.0, 1.0, 0.0)
00345       else if (a_copy.dot(Vector<T>(Point<T>(0.0, 1.0, 0.0))) == 0.0)
00346         euler_vector = Vector<T>(Point<T>(0.0, 1.0, 0.0));
00347 
00348       // else try (0.0, 0.0, 1.0)
00349       else if (a_copy.dot(Vector<T>(Point<T>(0.0, 0.0, 1.0))) == 0.0)
00350         euler_vector = Vector<T>(Point<T>(0.0, 0.0, 1.0));
00351 
00352       else // use a random vector that's perpendicular to a_copy
00353         euler_vector = a_copy.cross(Vector<T>(Point<T>(0.4243, 0.5657, 0.7071)));
00354 
00355       euler_angle  = M_PI;
00356     }
00357   else  // the vectors are not aligned; choose the euler vector and
00358         // angle from the minimum rotation of the first vector to the second
00359     {
00360       // Get the Euler vector by performing the cross product between a
00361       // and b
00362       euler_vector = a_copy.cross(b_copy);
00363       // Get the Euler angle from the dot product and cross product 
00364       euler_angle = atan2(euler_vector.magnitude(), a_copy.dot(b_copy));
00365     }
00366 
00367   std::cout << "euler_vector = " << euler_vector << std::endl;
00368   std::cout << "eular_angle =  " << euler_angle  << std::endl;
00369   
00370   euler_parameters_to_quaternion(euler_vector, euler_angle);
00371 
00372 }

Here is the call graph for this function:

template<class T>
claraty::Quaternion< T >::Quaternion ( const Vector< T > &  euler_vector,
const T &  euler_angle 
)

This constructor creates the quaternion corresponding to the input Euler vector and Euler angle inputs. The Euler angle is assumed to be in units of radians.

Definition at line 380 of file quaternion.h.

References claraty::Quaternion< T >::euler_parameters_to_quaternion().

00381 {
00382   // cout <<
00383   //   "Quaternion constructor Quaternion(const Vector<T>& euler_vector, const T& euler_angle)"
00384   //     << endl;
00385 
00386   assert(this->_elements != NULL);
00387 
00388   euler_parameters_to_quaternion(euler_vector, euler_angle);
00389 }

Here is the call graph for this function:

template<class T>
claraty::Quaternion< T >::~Quaternion (  )  [inline]

Definition at line 86 of file quaternion.h.

00086 {};


Member Function Documentation

template<class T>
T& claraty::Quaternion< T >::operator() ( int  n  )  [inline]

Definition at line 90 of file quaternion.h.

00090 {return this->_elements[n];}

template<class T>
const T& claraty::Quaternion< T >::operator() ( int  n  )  const [inline]

Definition at line 91 of file quaternion.h.

00091 {return this->_elements[n];}

template<class T>
Quaternion< T > claraty::Quaternion< T >::operator= ( const Quaternion< T > &  rhs  ) 

This is the equals operator. The left hand side is set equals to the right hand side.

Definition at line 399 of file quaternion.h.

References claraty::Base_Quaternion< T >::_elements.

00400 {
00401   // If the lhs is already the rhs, return the lhs
00402   if (this == &rhs) return *this;
00403   
00404   // Copy the elements of the rhs to the lhs
00405   memcpy(this->_elements, rhs._elements, sizeof(T)*4);
00406 
00407   return *this;
00408 }

template<class T>
Quaternion< T > claraty::Quaternion< T >::operator= ( const RMatrix< T > &  rhs  ) 

This is the equals operator. The left hand side is set equals to the right hand side.

Definition at line 415 of file quaternion.h.

References claraty::Quaternion< T >::rotation_matrix_to_quaternion().

00416 {
00417   // Copy the elements of the rhs to the lhs
00418   rotation_matrix_to_quaternion(rhs);
00419 
00420   return *this;
00421 }

Here is the call graph for this function:

template<class T>
Quaternion< T > claraty::Quaternion< T >::operator * ( const Quaternion< T > &  rhs  )  const

This is the product operator.

Definition at line 427 of file quaternion.h.

References claraty::Base_Quaternion< T >::_elements.

00428 {
00429   Quaternion<T> temp;
00430   
00431   temp._elements[0] =   this->_elements[3] * rhs._elements[0] + 
00432                       - this->_elements[2] * rhs._elements[1] +
00433                         this->_elements[1] * rhs._elements[2] +
00434                         this->_elements[0] * rhs._elements[3];
00435   
00436   temp._elements[1] =   this->_elements[2] * rhs._elements[0] +
00437                         this->_elements[3] * rhs._elements[1] +
00438                       - this->_elements[0] * rhs._elements[2] +
00439                         this->_elements[1] * rhs._elements[3];
00440 
00441   temp._elements[2] = - this->_elements[1] * rhs._elements[0] +
00442                         this->_elements[0] * rhs._elements[1] +
00443                         this->_elements[3] * rhs._elements[2] +
00444                         this->_elements[2] * rhs._elements[3];
00445 
00446   temp._elements[3] = - this->_elements[0] * rhs._elements[0] +
00447                       - this->_elements[1] * rhs._elements[1] +
00448                       - this->_elements[2] * rhs._elements[2] +
00449                         this->_elements[3] * rhs._elements[3];
00450 
00451   return temp;
00452 }

template<class T>
Point< T > claraty::Quaternion< T >::operator * ( const Point< T > &  rhs  )  const

Definition at line 458 of file quaternion.h.

References claraty::Quaternion< T >::conjugate(), and claraty::Point< T >::xyz().

00459 {
00460   Quaternion<T> q_temp1(rhs(0), rhs(1), rhs(2), 0.0);
00461   Quaternion<T> q_temp2(*this);
00462   Quaternion<T> q_temp3;
00463   Point<T> ret_val(0.0, 0.0, 0.0);
00464 
00465   q_temp2.conjugate();
00466   q_temp3 = (*this) * q_temp1 * q_temp2;
00467   ret_val.xyz(q_temp3(0), q_temp3(1),q_temp3(2));
00468   
00469   //  p(0) = lhs._data[0][0]*rhs(0) + lhs._data[0][1]*rhs(1) + lhs._data[0][2]*rhs(2);
00470   //  p(1) = lhs._data[1][0]*rhs(0) + lhs._data[1][1]*rhs(1) + lhs._data[1][2]*rhs(2);
00471   //  p(2) = lhs._data[2][0]*rhs(0) + lhs._data[2][1]*rhs(1) + lhs._data[2][2]*rhs(2);
00472   return ret_val;
00473 }

Here is the call graph for this function:

template<class T>
Quaternion< T > claraty::Quaternion< T >::operator/ ( const Quaternion< T > &  rhs  ) 

This is the divide operator.

Definition at line 478 of file quaternion.h.

References claraty::Base_Quaternion< T >::_elements, claraty::Quaternion< T >::conjugate(), and claraty::Quaternion< T >::negate().

00479 {
00480   Quaternion<T> temp1(*this), temp2, temp3;
00481   
00482   temp2 = rhs;
00483   temp2.conjugate();
00484   temp3 = temp1 * temp2;
00485   if (temp3._elements[3] < 0.0)
00486     temp3.negate();
00487   return temp3;
00488 }

Here is the call graph for this function:

template<class T>
bool claraty::Quaternion< T >::operator== ( const Quaternion< T > &  rhs  )  const

This is the test equals operator. If the elements of the left hand side are equal to the elements of the right hand side, return TRUE, otherwise return FALSE

Definition at line 495 of file quaternion.h.

References claraty::Base_Quaternion< T >::_elements.

00496 {
00497   // If the lhs is the rhs, return 0
00498   if (this == &rhs) return true;
00499   
00500   for (int i=0; i<4; i++)
00501     if (this->_elements[i] != rhs._elements[i])
00502       return false;
00503 
00504   return true;
00505 }

template<class T>
void claraty::Quaternion< T >::rotation_matrix_to_quaternion ( const RMatrix< T > &  m  ) 

This operation determines the quaternion that performs a transformation that is equivalent to the transformation performed by its input rotation matrix. The equivalent quaternion is put in this quaternion.

Definition at line 524 of file quaternion.h.

References claraty::Base_Quaternion< T >::_elements, and claraty::Quaternion< T >::negate().

Referenced by claraty::Quaternion< T >::operator=(), and claraty::Quaternion< T >::Quaternion().

00525 {
00526   int i, f, g;
00527   T ta, k, prd[4][4];
00528 
00529   // Compute porduct of terms of addition
00530   prd[0][1] = prd[1][0] = (T)(m(1,0) + m(0,1));
00531   prd[1][2] = prd[2][1] = (T)(m(2,1) + m(1,2));
00532   prd[2][0] = prd[0][2] = (T)(m(0,2) + m(2,0));
00533   prd[0][3] = prd[3][0] = (T)(m(2,1) - m(1,2));
00534   prd[1][3] = prd[3][1] = (T)(m(0,2) - m(2,0));
00535   prd[2][3] = prd[3][2] = (T)(m(1,0) - m(0,1));
00536 
00537   // Determine which form to use */
00538   if ((ta=(T)( m(0,0)+m(1,1)+m(2,2))) >= 0.0 )
00539     f=3;
00540   else if ((ta=(T)( m(0,0)-m(1,1)-m(2,2))) >= 0.0 )
00541     f=0;
00542   else if ((ta=(T)(-m(0,0)+m(1,1)-m(2,2))) >= 0.0 )
00543     f=1;
00544   else
00545   {
00546     ta=(T)(-m(0,0)-m(1,1)+m(2,2));
00547     f=2;
00548   }
00549 
00550   // Determine other parts
00551   ta = (T)(0.5 * sqrt(1.0 + ta ));
00552   this->_elements[f] = ta;
00553   k = 0.25 / this->_elements[f];
00554   for ( i=0, g=(f+1)&3; i<3; ++i, g=(g+1)&3 )
00555     this->_elements[g] = k * prd[f][g];
00556   
00557   if ( this->_elements[3] < 0.0 )
00558     negate();
00559 }

Here is the call graph for this function:

template<class T>
RMatrix< T > claraty::Quaternion< T >::quaternion_to_rotation_matrix (  )  const

This operation returns the rotation matrix equivalent of the quaternion.

Definition at line 565 of file quaternion.h.

References claraty::Quaternion< T >::norm().

Referenced by claraty::Quaternion< T >::get_rpy_angles(), claraty::Quaternion< double >::get_x_axis(), claraty::Quaternion< double >::get_y_axis(), claraty::Quaternion< double >::get_z_axis(), and claraty::RMatrix< T >::RMatrix().

00566 {
00567   int i, j;
00568   T k, k2, qq[4][4], t;
00569   RMatrix<T> a;
00570 
00571   // Form partial products
00572   for ( i=0; i<4; i++ )
00573     for ( j=0; j<4; j++ )
00574       qq[i][j] = this->_elements[i] * this->_elements[j];
00575 
00576   // Fill rotation matrix
00577   t = norm();
00578   k = 1.0 / (t*t);
00579   k2 = 2.0 * k;
00580   a(0,0) = k * (  qq[0][0] - qq[1][1] - qq[2][2] + qq[3][3]);
00581   a(1,1) = k * ( -qq[0][0] + qq[1][1] - qq[2][2] + qq[3][3]);
00582   a(2,2) = k * ( -qq[0][0] - qq[1][1] + qq[2][2] + qq[3][3]);
00583   a(1,0) = k2 * ( qq[0][1] + qq[2][3] );
00584   a(0,1) = k2 * ( qq[0][1] - qq[2][3] );
00585   a(2,0) = k2 * ( qq[0][2] - qq[1][3] );
00586   a(0,2) = k2 * ( qq[0][2] + qq[1][3] );
00587   a(2,1) = k2 * ( qq[1][2] + qq[0][3] );
00588   a(1,2) = k2 * ( qq[1][2] - qq[0][3] );
00589 
00590   return a;
00591 }

Here is the call graph for this function:

template<class T>
RMatrix<T> claraty::Quaternion< T >::get_rotation_matrix (  )  const

template<class T>
Vector< T > claraty::Quaternion< T >::quaternion_to_theta_triple (  )  const

Form the quaternion corresponding to the rotation represented by a vector of 3 rotation angles about the X-, Y- and Z-axes.

Definition at line 782 of file quaternion.h.

References claraty::Base_Quaternion< T >::_elements.

00783 {
00784   double s,k,l,t;
00785   Vector<T> a(3);
00786   
00787   s = sqrt( this->_elements[0]*this->_elements[0] +
00788             this->_elements[1]*this->_elements[1] +
00789             this->_elements[2]*this->_elements[2] );
00790   l = (s != 0.0 ? atan2(s, (double)this->_elements[3] ) : 0.0);
00791   
00792   if (s!=0.0)
00793     k = l * 2.0 / s;
00794   else
00795     k = 0.0;
00796  
00797   t = this->_elements[0] * k;
00798   a(0) = t;
00799   t = this->_elements[1] * k;
00800   a(1) = t;
00801   t = this->_elements[2] * k;
00802   a(2) = t;
00803   
00804   return a;
00805 }

template<class T>
void claraty::Quaternion< T >::theta_triple_to_quaternion ( const Vector< T > &  a  ) 

Form the quaternion corresponding to the rotation represented by a vector of 3 rotation angles about the X-, Y- and Z-axes.

Definition at line 761 of file quaternion.h.

References claraty::Base_Quaternion< T >::_elements.

Referenced by claraty::Quaternion< T >::Quaternion().

00762 {
00763   double s,k,l;
00764   
00765   k = sqrt(a(0)*a(0) + a(1)*a(1) + a(2)*a(2));
00766   l = 0.5 * k;
00767   s = (k!=0.0 ? sin(l)/k : 0.0);
00768   
00769   // a.scale(s);
00770   // The scale function is currently not implemented in the vector
00771   // class so we do it here.
00772   this->_elements[0] = s * a(0);
00773   this->_elements[1] = s * a(1);
00774   this->_elements[2] = s * a(2);
00775   this->_elements[3] = cos(l);
00776 }

template<class T>
void claraty::Quaternion< T >::euler_parameters_to_quaternion ( const Vector< T > &  euler_vector,
const T &  euler_angle 
)

This operation makes this quaternion correspond to the entered Euler vector and angle

Definition at line 597 of file quaternion.h.

References claraty::Base_Quaternion< T >::_elements.

Referenced by claraty::Quaternion< T >::Quaternion().

00598 {
00599   T theta_2 = euler_angle / 2.0;
00600   int i;
00601 
00602   this->_elements[3] = (T) cos((double)theta_2);
00603 
00604   // The vector that was entered may not be normalized so
00605   // normalize it
00606 
00607   T normVec = (T)sqrt((double)(euler_vector[0]*euler_vector[0]
00608                                + euler_vector[1]*euler_vector[1]
00609                                + euler_vector[2]*euler_vector[2]));
00610   
00611   T normEulerVec[3];
00612 
00613   for (i=0; i<3; i++)
00614     normEulerVec[i] = (T)(euler_vector[i] / normVec);
00615   
00616 
00617   // Enter the remaining quaternion values
00618 
00619   T sin_theta_2 = (T)sin((double)theta_2);
00620 
00621   for (i=0; i<3; i++) {
00622     this->_elements[i] = normEulerVec[i] * sin_theta_2;
00623   }
00624 }

template<class T>
T claraty::Quaternion< T >::get_euler_angle (  ) 

Return the Euler angle associated with the quaternion

Definition at line 629 of file quaternion.h.

References claraty::Quaternion< T >::negate().

00630 {
00631   double l;
00632   T angle;
00633 
00634   if (this->_elements[3] < 0.0)
00635     negate();
00636   l = sqrt((double)(this->_elements[0]*this->_elements[0] +
00637                  this->_elements[1]*this->_elements[1] + this->_elements[2]*this->_elements[2]));
00638 
00639   angle = (T)atan2( l, (double)this->_elements[3] );
00640 
00641   return((T)((T)2.0 * (l != (T)0.0 ? angle : (T)0.0 )));
00642 
00643 }

Here is the call graph for this function:

template<class T>
T claraty::Quaternion< T >::norm (  )  const

Return the norm of the quaternion

Definition at line 648 of file quaternion.h.

Referenced by claraty::Quaternion< T >::normalize(), claraty::Quaternion< T >::Quaternion(), and claraty::Quaternion< T >::quaternion_to_rotation_matrix().

00649 {
00650   double local_norm = sqrt(this->_elements[0] * this->_elements[0] +
00651                            this->_elements[1] * this->_elements[1] +
00652                            this->_elements[2] * this->_elements[2] +
00653                            this->_elements[3] * this->_elements[3]);
00654 
00655   return((T)local_norm);
00656 }

template<class T>
void claraty::Quaternion< T >::conjugate (  ) 

Take the conjugate of the quaternion

Definition at line 705 of file quaternion.h.

Referenced by claraty::Quaternion< T >::operator *(), claraty::Quaternion< T >::operator/(), claraty::Quaternion< double >::reverse(), claraty::ME_Body::rotate_center_of_mass(), and claraty::ME_Joint::rotate_joint_axes().

00706 {
00707   for (int i=0; i<3; i++)
00708      this->_elements[i] = - this->_elements[i];
00709 
00710 }

template<class T>
void claraty::Quaternion< T >::negate (  ) 

Negate the quaternion

Definition at line 715 of file quaternion.h.

Referenced by claraty::Quaternion< T >::get_euler_angle(), claraty::Quaternion< T >::interpolate(), claraty::Quaternion< T >::operator/(), claraty::Quaternion< T >::rotation_matrix_to_quaternion(), and claraty::Quaternion< T >::standardize().

00716 {
00717   for (int i=0; i<4; i++)
00718      this->_elements[i] = - this->_elements[i];
00719 }

template<class T>
Quaternion< T > claraty::Quaternion< T >::interpolate ( const T &  k,
Quaternion< T > &  a 
) const

Return an interpolated quaternion that is k (0<k<1) between this quaternion and the input quaternion

Definition at line 742 of file quaternion.h.

References claraty::Base_Quaternion< T >::_elements, claraty::Quaternion< T >::negate(), and claraty::Quaternion< T >::power().

00743 {
00744   Quaternion temp1(*this), temp2;
00745   
00746   temp1.conjugate();
00747   temp2 = a * temp1;
00748   
00749   if (temp2._elements[3] < 0.0)
00750     temp2.negate();
00751   temp2.power(k);
00752   temp1 = temp2 * *this;
00753   return temp1;
00754 }

Here is the call graph for this function:

template<class T>
void claraty::Quaternion< T >::scale ( const T &  d  ) 

Scale the quaternion

Definition at line 696 of file quaternion.h.

Referenced by claraty::Quaternion< T >::normalize().

00697 {
00698         for (int i = 0; i<4; i++)
00699                 this->_elements[i] = d * this->_elements[i];
00700 }

template<class T>
void claraty::Quaternion< T >::normalize (  ) 

Normalize the quaternion

Definition at line 662 of file quaternion.h.

References claraty::Base_Quaternion< T >::_elements, claraty::Quaternion< T >::norm(), and claraty::Quaternion< T >::scale().

Referenced by claraty::Quaternion< T >::power().

00663 {
00664   T d;
00665   
00666   d = norm();
00667   if (d > 0.0)
00668     {
00669       scale(1/d);
00670     }
00671   else
00672     {
00673       this->_elements[0] = 0.0;
00674       this->_elements[1] = 0.0;
00675       this->_elements[2] = 0.0;
00676       this->_elements[3] = 1.0;
00677     }
00678 }

Here is the call graph for this function:

template<class T>
void claraty::Quaternion< T >::power ( const T &  p  ) 

Take the quaternion to the pth power

Definition at line 724 of file quaternion.h.

References claraty::Base_Quaternion< T >::_elements, and claraty::Quaternion< T >::normalize().

Referenced by claraty::Quaternion< T >::interpolate().

00725 {
00726   normalize();
00727   double s = sqrt((double)(this->_elements[0]*this->_elements[0] +
00728           this->_elements[1]*this->_elements[1] + this->_elements[2]*this->_elements[2]));
00729   if (s!=0.0)
00730   {
00731     double t = atan2(s, (double)(this->_elements[3])) * p;
00732     for (int i=0; i<3; i++)
00733       this->_elements[i] *= (T)(sin(t) / s);
00734       this->_elements[3] = (T)cos(t);
00735   }
00736 }

Here is the call graph for this function:

template<class T>
void claraty::Quaternion< T >::standardize (  ) 

Standardize the quaternion

Definition at line 684 of file quaternion.h.

References claraty::Quaternion< T >::negate().

00685 {
00686   if (this->_elements[3] < 0.0)
00687     {
00688       negate();
00689     }
00690 }

Here is the call graph for this function:

template<class T>
void claraty::Quaternion< T >::set_identity (  )  [inline]

Definition at line 118 of file quaternion.h.

Referenced by claraty::Quaternion< T >::Quaternion().

00118 { *this = identity;}

template<class T>
bool claraty::Quaternion< T >::io ( FDM_Map  map  ) 

Definition at line 846 of file quaternion.h.

References claraty::FDM_Map::field(), claraty::FDM_Map::is_read(), and claraty::FDM_Map::is_write().

00847 {
00848   T qi, qj, qk, qs;
00849   
00850   if (map.is_write()) {
00851     qi = this->_elements[0];
00852     qj = this->_elements[1];
00853     qk = this->_elements[2];
00854     qs = this->_elements[3];
00855   }
00856   
00857   bool ok = map.field("qi", qi);
00858   ok &= map.field("qj", qj);
00859   ok &= map.field("qk", qk);
00860   ok &= map.field("qs", qs);
00861     
00862   if (map.is_read())
00863   {
00864     this->_elements[0] = qi;
00865     this->_elements[1] = qj;
00866     this->_elements[2] = qk;
00867     this->_elements[3] = qs;
00868   }
00869 
00870   return ok;
00871 }

Here is the call graph for this function:

template<class T>
Quaternion claraty::Quaternion< T >::reverse (  )  [inline]

Definition at line 121 of file quaternion.h.

Referenced by claraty::Frame_IO::convert_to_internal_format().

00122     {
00123       Quaternion<T> temp(*this);
00124       temp.conjugate();
00125       return temp;
00126     };

template<class T>
Vector<T> claraty::Quaternion< T >::get_x_axis (  )  const [inline]

Definition at line 130 of file quaternion.h.

00130                                {
00131     return quaternion_to_rotation_matrix().get_x_axis();
00132   }

template<class T>
Vector<T> claraty::Quaternion< T >::get_y_axis (  )  const [inline]

Definition at line 133 of file quaternion.h.

00133                                {
00134     return quaternion_to_rotation_matrix().get_y_axis();
00135   }

template<class T>
Vector<T> claraty::Quaternion< T >::get_z_axis (  )  const [inline]

Definition at line 136 of file quaternion.h.

00136                                {
00137     return quaternion_to_rotation_matrix().get_z_axis();
00138   }

template<class T>
void claraty::Quaternion< T >::get_rpy_angles ( T &  roll,
T &  pitch,
T &  yaw 
) const

Converts this quaternion into equivalent roll, pitch, yaw angles

Definition at line 511 of file quaternion.h.

References claraty::RMatrix< T >::get_rpy_angles(), and claraty::Quaternion< T >::quaternion_to_rotation_matrix().

00512 {
00513   RMatrix<T> a = quaternion_to_rotation_matrix();
00514   a.get_rpy_angles(roll, pitch, yaw);
00515 }

Here is the call graph for this function:


Friends And Related Function Documentation

template<class T>
template<class Y>
std::ostream& operator<< ( std::ostream &  os,
const Quaternion< Y > &  q 
) [friend]


Member Data Documentation

template<class T>
const Base_Quaternion< T > claraty::Quaternion< T >::identity [static]

Definition at line 142 of file quaternion.h.

Referenced by claraty::Quaternion< double >::set_identity().


The documentation for this class was generated from the following file: