## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# csQuaternion Class Reference
[Geometry utilities]

Class for a quaternion. More...

`#include <csgeom/quaternion.h>`

List of all members.

## Public Member Functions

void | Conjugate ()
| csQuaternion (const csMatrix3 &smat)
| Construct quaternion from a matrix.
| csQuaternion (const csVector3 &q)
| Construct quaternion from a vector.
| csQuaternion (const csQuaternion &q)
| Copy constructor.
| csQuaternion (float theR, float theX=0.0, float theY=0.0, float theZ=0.0)
| Construct a quaternion with the given parameters.
| csQuaternion ()
| Construct a 0,0,0,0 quaternion.
void | GetAxisAngle (csVector3 &axis, float &phi) const
| Get an axis-angle representation of this orientation.
void | GetEulerAngles (csVector3 &angles, bool radians=false)
| Convert a Quaternion to a set of Euler angles.
void | Init (float theR, float theX, float theY, float theZ)
| Initialize a quaternion with specific values.
void | Invert ()
| Invert the orientation of this quaternion.
void | Negate ()
| Negate all parameters of the quaternion.
void | Normalize ()
| Normalize this quaternion.
csQuaternion & | operator *= (const csQuaternion &q2)
| Multiply two quaternions.
void | PrepRotation (float angle, csVector3 vec)
| Prepare a rotation quaternion, we do a rotation around vec by an angle of "angle".
csVector3 | Rotate (csVector3 vec)
| rotated = q * vec * qConj.
void | SetWithAxisAngle (csVector3 axis, float phi)
| Set the quaternion using an axis-angle representation.
void | SetWithEuler (const csVector3 &rot)
| Convert a set of Euler angles to a Quaternion.
csQuaternion | Slerp (const csQuaternion &quat2, float slerp) const
| Spherical Linear Interpolation between two quaternions Calculated between this class & the second quaternion by the slerp factor and returned as a new quaternion.
csQuaternion | ToAxisAngle () const
| Return an Axis Angle representation of this Quaternion.

## Public Attributes

float | r
float | x
float | y
float | z

## Friends

csQuaternion | operator * (const csQuaternion &q1, const csQuaternion &q2)
| Multiply two quaternions.
csQuaternion | operator+ (const csQuaternion &q1, const csQuaternion &q2)
| Add two quaternions.
csQuaternion | operator- (const csQuaternion &q1, const csQuaternion &q2)
| Subtract two quaternions.

## Detailed Description

Class for a quaternion.

Definition at line 39 of file quaternion.h.

## Constructor & Destructor Documentation

csQuaternion::csQuaternion | ( |  | ) | `[inline]`

| Construct a 0,0,0,0 quaternion. Definition at line 47 of file quaternion.h.

csQuaternion::csQuaternion | ( | float | theR,
|  | float | theX = `0.0`,
|  | float | theY = `0.0`,
|  | float | theZ = `0.0`
| ) | `[inline]`

| Construct a quaternion with the given parameters. Definition at line 49 of file quaternion.h.

csQuaternion::csQuaternion | ( | const csQuaternion & | q | ) | `[inline]`

| Copy constructor. Definition at line 52 of file quaternion.h. References r, x, y, and z.

csQuaternion::csQuaternion | ( | const csVector3 & | q | ) | `[inline]`

| Construct quaternion from a vector. Definition at line 54 of file quaternion.h. References csVector3::x, csVector3::y, and csVector3::z.

csQuaternion::csQuaternion | ( | const csMatrix3 & | smat | ) |

| Construct quaternion from a matrix.

## Member Function Documentation

void csQuaternion::GetAxisAngle | ( | csVector3 & | axis,
|  | float & | phi
| ) | const

Get an axis-angle representation of this orientation.

Parameters:

  | axis | this vector specifies the axis on which to make a rotation
  | phi | the angle (in radians) about this axis

void csQuaternion::GetEulerAngles | ( | csVector3 & | angles,
|  | bool | radians = `false`
| ) |

| Convert a Quaternion to a set of Euler angles. Returns a (X,Y,Z) rather than Yaw-Pitch-Roll (Y,X,Z).

void csQuaternion::Init | ( | float | theR,
|  | float | theX,
|  | float | theY,
|  | float | theZ
| ) | `[inline]`

| Initialize a quaternion with specific values. Definition at line 43 of file quaternion.h.

void csQuaternion::Invert | ( |  | ) |

| Invert the orientation of this quaternion.

void csQuaternion::Negate | ( |  | ) | `[inline]`

| Negate all parameters of the quaternion. Definition at line 97 of file quaternion.h.

void csQuaternion::Normalize | ( |  | ) | `[inline]`

| Normalize this quaternion. Definition at line 140 of file quaternion.h. References csQisqrt().

csQuaternion& csQuaternion::operator *= | ( | const csQuaternion & | q2 | ) | `[inline]`

| Multiply two quaternions. Definition at line 84 of file quaternion.h. References r, x, y, and z.

void csQuaternion::PrepRotation | ( | float | angle,
|  | csVector3 | vec
| ) | `[inline]`

| Prepare a rotation quaternion, we do a rotation around vec by an angle of "angle". Note that vec needs to be a normalized vector (we don't check this). Definition at line 121 of file quaternion.h. References csVector3::x, csVector3::y, and csVector3::z.

csVector3 csQuaternion::Rotate | ( | csVector3 | vec | ) | `[inline]`

| rotated = q * vec * qConj. Definition at line 129 of file quaternion.h. References x, y, and z.

void csQuaternion::SetWithAxisAngle | ( | csVector3 | axis,
|  | float | phi
| ) |

Set the quaternion using an axis-angle representation.

Parameters:

  | axis | this vector specifies the axis on which to make a rotation
  | phi | the angle (in radians) about this axis

void csQuaternion::SetWithEuler | ( | const csVector3 & | rot | ) |

| Convert a set of Euler angles to a Quaternion. Takes a (X,Y,Z) rather than Yaw-Pitch-Roll (Y,X,Z) The output is NOT Normalized, if you wish to do so, normalize it yourself.

csQuaternion csQuaternion::Slerp | ( | const csQuaternion & | quat2,
|  | float | slerp
| ) | const

| Spherical Linear Interpolation between two quaternions Calculated between this class & the second quaternion by the slerp factor and returned as a new quaternion.

csQuaternion csQuaternion::ToAxisAngle | ( |  | ) | const

| Return an Axis Angle representation of this Quaternion.

## Friends And Related Function Documentation

csQuaternion operator * | ( | const csQuaternion & | q1,
|  | const csQuaternion & | q2
| ) | `[friend]`

| Multiply two quaternions. Definition at line 74 of file quaternion.h.

csQuaternion operator+ | ( | const csQuaternion & | q1,
|  | const csQuaternion & | q2
| ) | `[friend]`

| Add two quaternions. Definition at line 60 of file quaternion.h.

csQuaternion operator- | ( | const csQuaternion & | q1,
|  | const csQuaternion & | q2
| ) | `[friend]`

| Subtract two quaternions. Definition at line 67 of file quaternion.h.

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

- csgeom/quaternion.h