MercuryDPM  Trunk
Quaternion.cc File Reference
#include "Math/Quaternion.h"

Go to the source code of this file.

## Functions

std::ostream & operator<< (std::ostream &os, const Quaternion &a)

std::istream & operator>> (std::istream &is, Quaternion &a)

Quaternion operator+ (const Mdouble a, const Quaternion &b)

Quaternion operator- (const Mdouble a, const Quaternion &b)

Quaternion operator- (const Quaternion &a)

Quaternion operator* (const Mdouble a, const Quaternion &b)

## Function Documentation

 Quaternion operator* ( const Mdouble a, const Quaternion & b )

Multiplies each element of a given quaternion (b) by a given scalar (a). NB: this is a global function and a friend of the Quaternion class. Gets called when a scalar multiplication of the form (Mdouble) * (Quaternion) is performed.

Parameters
 [in] a the scalar [in] b the quaternion
Returns
the resulting quaternion

Definition at line 405 of file Quaternion.cc.

References Quaternion::q0, Quaternion::q1, Quaternion::q2, and Quaternion::q3.

406 {
407  return Quaternion(b.q0 * a, b.q1 * a, b.q2 * a, b.q3 * a);
408 }
Implementation of a 3D quaternion (by Vitaliy).
Definition: Quaternion.h:62
Mdouble q2
the second component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:77
Mdouble q3
the third component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:81
Mdouble q0
the zeroth component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:69
Mdouble q1
the first component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:73
 Quaternion operator+ ( const Mdouble a, const Quaternion & b )

Adds a scalar to the elements of given quaternion NB this is a global function and a friend of the Quaternion class. Gets called when addition operation of the form (Mdouble) + (Quaternion) is performed.

Parameters
 [in] a the scalar to be added [in] b the quaternion the scalar gets added to.
Returns
the resulting quaternion.

Definition at line 367 of file Quaternion.cc.

References Quaternion::q0, Quaternion::q1, Quaternion::q2, and Quaternion::q3.

368 {
369  return Quaternion(b.q0 + a, b.q1 + a, b.q2 + a, b.q3 + a);
370 }
Implementation of a 3D quaternion (by Vitaliy).
Definition: Quaternion.h:62
Mdouble q2
the second component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:77
Mdouble q3
the third component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:81
Mdouble q0
the zeroth component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:69
Mdouble q1
the first component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:73
 Quaternion operator- ( const Mdouble a, const Quaternion & b )

Subtracts each element of a given quaternion from a scalar NB this is a global function and a friend of the Quaternion class. Gets called when subtraction operation of the form (Mdouble) - (Quaternion) is performed.

Parameters
 [in] a the scalar [in] b the quaternion to be subtracted the scalar gets subtracted from.
Returns
the resulting quaternion.

Definition at line 380 of file Quaternion.cc.

References Quaternion::q0, Quaternion::q1, Quaternion::q2, and Quaternion::q3.

381 {
382  return Quaternion(a - b.q0, a - b.q1, a - b.q2, a - b.q3);
383 }
Implementation of a 3D quaternion (by Vitaliy).
Definition: Quaternion.h:62
Mdouble q2
the second component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:77
Mdouble q3
the third component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:81
Mdouble q0
the zeroth component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:69
Mdouble q1
the first component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:73
 Quaternion operator- ( const Quaternion & a )

Returns the negative of a given quaternion. NB: this is a global function and a friend of the Quaternion class. Gets called when a negation operation of the form - (Quaternion) is performed.

Parameters
 [in] a the quaternion to be negated
Returns
the negated quaternion

Definition at line 392 of file Quaternion.cc.

References Quaternion::q0, Quaternion::q1, Quaternion::q2, and Quaternion::q3.

393 {
394  return Quaternion(-a.q0, -a.q1, -a.q2, -a.q3);
395 }
Implementation of a 3D quaternion (by Vitaliy).
Definition: Quaternion.h:62
Mdouble q2
the second component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:77
Mdouble q3
the third component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:81
Mdouble q0
the zeroth component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:69
Mdouble q1
the first component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:73
 std::ostream& operator<< ( std::ostream & os, const Quaternion & a )

Adds all elements of the quaternion to an output stream. NB: this is a global function and a friend of the Quaternion class!

Parameters
 [in] os the output stream, [in] a The quaternion of interest
Returns
the output stream with quaternion elements added

Definition at line 340 of file Quaternion.cc.

References Quaternion::q0, Quaternion::q1, Quaternion::q2, and Quaternion::q3.

341 {
342  os << a.q0 << ' ' << a.q1 << ' ' << a.q2 << ' ' << a.q3;
343  return os;
344 }
Mdouble q2
the second component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:77
Mdouble q3
the third component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:81
Mdouble q0
the zeroth component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:69
Mdouble q1
the first component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:73
 std::istream& operator>> ( std::istream & is, Quaternion & a )

Reads all elements of a given quaternion from an input stream. NB: this is a global function and a friend of the Quaternion class!

Parameters
 [in,out] is the input stream [in,out] a the quaternion to be read in
Returns
the input stream from which the quaternion elements were read

Definition at line 353 of file Quaternion.cc.

References Quaternion::q0, Quaternion::q1, Quaternion::q2, and Quaternion::q3.

354 {
355  is >> a.q0 >> a.q1 >> a.q2 >> a.q3;
356  return is;
357 }
Mdouble q2
the second component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:77
Mdouble q3
the third component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:81
Mdouble q0
the zeroth component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:69
Mdouble q1
the first component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:73