math Namespace Reference

## Data Structures

class  matrix3d
3-Dimensional Matrix Class More...

class  matrix4d
4-Dimensional Matrix Class More...

class  plane
3-dimensional plane class declaration More...

class  quaternion
4-dimensional normed division algebra over the Real Numbers More...

class  vector2d
Ordered 2-tuple implementing Euclidean vector operations. More...

class  vector3d
Ordered 3-tuple implementing Euclidean vector operations. More...

class  vector4d
Ordered 4-tuple implementing Euclidean vector operations. More...

class  vector4h
Augmented 3-dimensional vector / homogeneous vector / projected point. More...

## Functions

scalar det (scalar a, scalar b, scalar c, scalar d)
Calculate the determinant of a 2x2 matrix. More...

scalar det (scalar a1, scalar b1, scalar c1, scalar a2, scalar b2, scalar c2, scalar a3, scalar b3, scalar c3)
Calculate the determinant of a 3x3 matrix. More...

const quaternion operator* (const quaternion &q, const vector3d &v)
Multiply a vector by a quaternion. More...

const quaternion operator* (const vector3d &v, const quaternion &q)
Multiply a quaternion by a vector. More...

const matrix3d quaternion2DCM (const quaternion &q)
Quaternion to direction cosine matrix (DCM) conversion. More...

const vector3d quaternion2euler (const quaternion &q)
Quaternion to Euler angle conversion. More...

const vector3d rotate (const quaternion &q, const vector3d &v)
Rotate a vector by a unit quaternion. More...

 scalar math::det ( scalar a, scalar b, scalar c, scalar d )
inline

Calculate the determinant of a 2x2 matrix.

This routine calculates the determinant of a 2x2 matrix consisting of entries a, b, c, and d arranged in the matrix as follows:

$\left| \begin{array}{cc} a & b \\ c & d \end{array} \right|$

Return values
 scalar The real-valued determinant of the input matrix.
 scalar math::det ( scalar a1, scalar b1, scalar c1, scalar a2, scalar b2, scalar c2, scalar a3, scalar b3, scalar c3 )
inline

Calculate the determinant of a 3x3 matrix.

This routine calculates the determinant of a 3x3 matrix consisting of entries arranged in the matrix as follows:

$\left| \begin{array}{ccc} a_1 & b_1 & c_1\\ a_2 & b_2 & c_2\\ a_3 & b_3 & c_3 \end{array} \right|$

Return values
 scalar The real-valued determinant of the input matrix.

References det().

 const quaternion math::operator* ( const quaternion & q, const vector3d & v )
inline

Multiply a vector by a quaternion.

This operator multiplies a math::vector3d object on the right-side of the operator by math::quaternion object on the left-side of the operator.

Parameters
 q A math::quaternion operand. v A math::vector3d operand.
Return values
 math::quaternion The product of the input operands.
 const quaternion math::operator* ( const vector3d & v, const quaternion & q )
inline

Multiply a quaternion by a vector.

This operator multiplies a math::quaternion object on the right-side of the operator by math::vector3d object on the left-side of the operator.

Parameters
 v A math::vector3d operand. q A math::quaternion operand.
Return values
 math::quaternion The product of the input operands.
 const matrix3d math::quaternion2DCM ( const quaternion & q )
inline

Quaternion to direction cosine matrix (DCM) conversion.

This routine converts a specified quaternion $$\mathbf{q}$$ to a 3x3 direction cosine matrix (DCM).

If point $$\mathbf{P}$$ is transformed to $$\mathbf{P^{\prime}}$$ as a result of a rotation described by quaternion $$\mathbf{q}$$ according to the following quaternion algebra:

$$P^{\prime} = qPq^{*}$$

where

$$q = q_0 + \hat{i}q_1 + \hat{j}q_2 + \hat{k}q_3$$

$$q^{*} = q_0 - \hat{i}q_1 - \hat{j}q_2 - \hat{k}q_3$$

$$P = 0 + \hat{i}x + \hat{j}y + \hat{k}z$$

Parameters
 q A rotation math::quaternion argument.
Return values
 math::matrix3d A 3x3 direction cosine matrix.
 const vector3d math::quaternion2euler ( const quaternion & q )
inline

Quaternion to Euler angle conversion.

This routine converts a specified quaternion $$\mathbf{q}$$ to a 3x1 vector storing bank (rotation about x-axis), attitude (rotation about y-axis), and heading (rotation about z-axis) values in the x, y, and z vector elements, respectively.

Note
• Singularities are not accounted for when the pitch approaches $$\pm 90$$ degrees (north / south pole); i.e. gimbal lock.
• This is a special-case assuming a particular right-hand system, but there are many types of Euler angles depending upon the system being described. Additional work is required to create a set of useful utility methods for converting quaternions to Euler angles.
Parameters
 q A rotation math::quaternion argument.
Return values
 math::vector3d A 3x1 vector storing roll, pitch, and yaw.
 const vector3d math::rotate ( const quaternion & q, const vector3d & v )
inline

Rotate a vector by a unit quaternion.

Given unit quaternion $$q = (s, \vec{v})$$ and its conjugate $$q^{*} = (s, -\vec{v}),$$ to rotate arbitrary vector $$\vec{r}$$ by an angle $$\alpha$$ about a vector $$\hat{N}$$:

• Convert the vector $$\vec{r}$$ to quaternion form $$p = (0, \vec{r})$$ and express the rotation quaternion as:

$q = (\cos{(\frac{\alpha}{2})}, \sin{(\frac{\alpha}{2})}\hat{N})$

• Perform the following multiplication which is equivalent to rotation about $$\hat{N}$$:

$qpq^{*} = (0, (s^{2} - \vec{v} \cdot \vec{v})\vec{r} + 2\vec{v}(\vec{v} \cdot \vec{r}) + 2s\vec{v} \times \vec{r}) = (0, \vec{r}^{\prime})$

Parameters
 q A math::quaternion operand. v A math::vector3d operand.
Return values
 math::vector3d The resulting rotated vector object.