3x3 Matrices

Overview

The 3x3 matrices that appear most often in kinematics are rotation matrices, which describe the orientation of one reference frame relative to another. The rotation matrix \(R^{ab}\) takes the components of a vector in frame \(b\) to its components in frame \(a\):

\[\underline{v}^a = R^{ab}\, \underline{v}^b\]

The columns of \(R^{ab}\) are the unit vectors along the x, y and z axes of frame \(b\), expressed in frame \(a\). Each entry is the cosine of the angle between an axis of \(a\) and an axis of \(b\), which is why rotation matrices are also called direction cosine matrices. Because the columns are orthonormal, a rotation matrix has determinant +1 and its inverse is its transpose:

\[(R^{ab})^{-1} = (R^{ab})^T = R^{ba}\]

so ksl_mat3x3_transpose() inverts a rotation with no arithmetic at all, while ksl_mat3x3_invert() is only needed for general matrices. Rotations compose by multiplication, \(R^{ac} = R^{ab} R^{bc}\). The rotations about a single coordinate axis are

\[\begin{split}R_x = \begin{bmatrix} 1 & 0 & 0 \\ 0 & c & -s \\ 0 & s & c \end{bmatrix}, \quad R_y = \begin{bmatrix} c & 0 & s \\ 0 & 1 & 0 \\ -s & 0 & c \end{bmatrix}, \quad R_z = \begin{bmatrix} c & -s & 0 \\ s & c & 0 \\ 0 & 0 & 1 \end{bmatrix}\end{split}\]

with \(c = \cos\theta\) and \(s = \sin\theta\). A rotation by angle \(\theta\) about a general unit axis \(\underline{e}\) is given by Rodrigues’ formula, \(R = I + \sin\theta\, \tilde{e} + (1 - \cos\theta)\, \tilde{e}^2\) (ksl_mat3x3_setFromAxisAngle()). Orientations can also be described by three Euler angles (see Axes and Euler Angles) or by a unit quaternion (see Quaternions). [12] and [21] give a fuller introduction.

Keeping a rotation orthonormal. After many products, round-off error slowly makes the columns of a rotation matrix lose their unit length and orthogonality. ksl_mat3x3_normalize() restores them.

Storage. ksl_mat3x3_t holds nine double values, 72 bytes (ksl_mat3x3f_t: 36 bytes), in column major order: the three values of the first column come first. Column major order is used because the columns of a rotation matrix are the rotated frame’s axes, so they can be read directly as vectors. Entries can be accessed several ways:

ksl_mat3x3_t R;
ksl_mat3x3_setIdentity(&R);
double r01 = R.m01;      /* row 0, column 1 */
double r10 = R.at[0][1]; /* at[column][row]: row 1, column 0 */
ksl_vec3_t z = R.v[2];   /* third column: the frame's z axis */

as_array gives the nine values as a flat array.

Double precision

ksl_mat3x3_t

A general 3x3 double precision matrix.

ksl_mat3x3()

ksl_mat3x3_t constructor.

ksl_mat3x3_cmo()

alternative ksl_mat3x3_t constructor.

ksl_mat3x3_alloc()

allocates n ksl_mat3x3_t datastructures on the heap. Must be freed by the user.

ksl_mat3x3_setIdentity()

Set a double precision 3x3 matrix to identity.

ksl_mat3x3_set()

Set a value in a double precision 3x3 matrix at specified row and column index.

ksl_mat3x3_setFromVectors()

Set a double precision 3x3 matrix from 3 column vectors.

ksl_mat3x3_get()

Return the entry of a 3x3 matrix at (row, column).

ksl_mat3x3_copy()

Copy a 3x3 matrix: ro = ri.

ksl_mat3x3_invert()

Invert a general 3x3 matrix in place.

ksl_mat3x3_inverted()

Compute the inverse of a general 3x3 matrix: ro = ri^-1.

ksl_mat3x3_transpose()

Transpose a 3x3 matrix in place. For a rotation matrix this is its inverse.

ksl_mat3x3_transposed()

Compute the transpose of a 3x3 matrix: ro = ri^T. For a rotation matrix this is its inverse.

ksl_mat3x3_getEulerAngles

This macro is used to obtain a double precision sequence of Euler angles from an orthonormal rotation matrix using a specified axis sequence convention.

ksl_mat3x3_getEulerAnglesWithReference()

Obtain double precision sequence of Euler angles using specified axis sequence convention.

ksl_mat3x3_setFromEulerAngles()

Set a double precision mat3x3 matrix from a sequence of Euler angles.

ksl_mat3x3_getAxisAngle()

Get axis and angle from a double precision rotation matrix.

ksl_mat3x3_setFromAxisAngle()

Set double precision rotation matrix from axis and angle representation.

ksl_mat3x3_determinant()

Compute the determinant of a 3x3 double precision matrix.

ksl_mat3x3_normalize()

Re-orthonormalize a rotation matrix in place.

ksl_mat3x3_normalized()

Compute a re-orthonormalized copy of a rotation matrix.

ksl_mat3x3_setFromAxisDC()

Set 3x3 rotation matrix from axis and direction cosines.

union ksl_mat3x3_t
#include <types.h>

A general 3x3 double precision matrix.

This union allows accessing double precision mat3x3 quantities by field name, as a singly dimensioned array, as a doubly dimensioned array, or by accessing a specific column. If using the at or as_array operators, quantities are accessed in column major order.

The following examples illustrate how to access row 2, column 1 (using 0 based indexing) of matrix R. The following access methods are equivalent.

R.as_array[2 + 1 * 3];
R.at[1][2];
R.m21;
R.v1.z;
R.v1.at[2];
R.v[1].z;
R.v[1].at[2];

See also the ksl_mat3x3_get and ksl_mat3x3_set functions.

Public Members

double as_array[9]
struct ksl_mat3x3_t

anonymous union allows accessing quantities at specified index in linear array, where entities are specified in column major order

double at[3][3]
struct ksl_mat3x3_t

anonymous union allows accessing quantities at specified index in a doubly dimensioned array, where entities are specified in column major order

double m00
double m10
double m20
double m01
double m11
double m21
double m02
double m12
double m22
struct ksl_mat3x3_t

anonymous union allows accessing rotation matrix quantities by field name

ksl_vec3_t v0
ksl_vec3_t v1
ksl_vec3_t v2
struct ksl_mat3x3_t

anonymous union allows accessing columns of rotation matrix quantities by field name

ksl_vec3_t v[3]
struct ksl_mat3x3_t

anonymous union allows accessing columns of rotation matrix quantities at specified index

static inline ksl_mat3x3_t ksl_mat3x3(const double m00, const double m01, const double m02, const double m10, const double m11, const double m12, const double m20, const double m21, const double m22)

ksl_mat3x3_t constructor.

Note that in the constructor, fields are specified in row major order. Internally, ksl_mat3x3_t datastructures are stored in column major order.

static inline ksl_mat3x3_t ksl_mat3x3_cmo(const double m00, const double m10, const double m20, const double m01, const double m11, const double m21, const double m02, const double m12, const double m22)

alternative ksl_mat3x3_t constructor.

In this alternate constructor, fields are specified in column major order to match the internal layout of ksl_mat3x3_t datastructures.

ksl_mat3x3_t *ksl_mat3x3_alloc(const int n)

allocates n ksl_mat3x3_t datastructures on the heap. Must be freed by the user.

static inline void ksl_mat3x3_setIdentity(ksl_mat3x3_t *r)

Set a double precision 3x3 matrix to identity.

\( I \rightarrow R \)

Parameters:
  • r – [in/out] input 3x3 matrix

static inline void ksl_mat3x3_set(ksl_mat3x3_t *R, const int row, const int column, const double value)

Set a value in a double precision 3x3 matrix at specified row and column index.

Bounds checking are performed in debug mode. Bounds checking can be disabled by compiling in release mode using the compiler flag -DNDEBUG.

Parameters:
  • R – [in/out]

  • row – [in] row index, \(0 \le row \lt 3\)

  • column – [in] column index, \(0 \le column \lt 3\)

  • value – [in] value to set

static inline void ksl_mat3x3_setFromVectors(ksl_mat3x3_t *R, const ksl_vec3_t *x, const ksl_vec3_t *y, const ksl_vec3_t *z)

Set a double precision 3x3 matrix from 3 column vectors.

\( \begin{bmatrix} \underline{v}_x & \underline{v}_y & \underline{v}_z \end{bmatrix} \rightarrow R \)

Parameters:
  • R – [in/out] 3x3 rotation matrix

  • x – [in] first column to set

  • y – [in] second column to set

  • z – [in] third column to set

static inline double ksl_mat3x3_get(const ksl_mat3x3_t *R, const int row, const int column)

Return the entry of a 3x3 matrix at (row, column).

Parameters:
  • R – [in] 3x3 matrix

  • row – [in] row index, 0 to 2

  • column – [in] column index, 0 to 2

Returns:

the requested entry

static inline void ksl_mat3x3_copy(const ksl_mat3x3_t *ri, ksl_mat3x3_t *ro)

Copy a 3x3 matrix: ro = ri.

Parameters:
  • ri – [in] matrix to copy

  • ro – [out] copy of ri

inline int ksl_mat3x3_invert(ksl_mat3x3_t *R)

Invert a general 3x3 matrix in place.

Uses Gauss-Jordan elimination with partial pivoting (in each column the entry largest in magnitude is the pivot), so a matrix with zeros on its diagonal inverts. For a rotation matrix, ksl_mat3x3_transpose() gives the same result with far fewer operations.

Invert a general 3x3 matrix in place.

Parameters:
  • R – [in,out] matrix, replaced by its inverse

Returns:

0 on success, or -(k + 1) if no pivot in column k is as large as 1e-12 (the matrix is singular); R is then unchanged

inline int ksl_mat3x3_inverted(const ksl_mat3x3_t *ri, ksl_mat3x3_t *ro)

Compute the inverse of a general 3x3 matrix: ro = ri^-1.

Uses Gauss-Jordan elimination with partial pivoting (in each column the entry largest in magnitude is the pivot), so a matrix with zeros on its diagonal inverts. For a rotation matrix, ksl_mat3x3_transposed() gives the same result with far fewer operations.

Compute the inverse of a general 3x3 matrix: ro = ri^-1.

Parameters:
  • ri – [in] matrix to invert

  • ro – [out] inverse of ri

Returns:

0 on success, or -(k + 1) if no pivot in column k is as large as 1e-12 (the matrix is singular); ro is then not written

static inline void ksl_mat3x3_transpose(ksl_mat3x3_t *R)

Transpose a 3x3 matrix in place. For a rotation matrix this is its inverse.

Parameters:
  • R – [in,out] matrix, replaced by its transpose

static inline void ksl_mat3x3_transposed(const ksl_mat3x3_t *ri, ksl_mat3x3_t *ro)

Compute the transpose of a 3x3 matrix: ro = ri^T. For a rotation matrix this is its inverse.

Parameters:
  • ri – [in] matrix

  • ro – [out] transpose of ri

ksl_mat3x3_getEulerAngles(r, axisType, angles, ...)

This macro is used to obtain a double precision sequence of Euler angles from an orthonormal rotation matrix using a specified axis sequence convention.

Note that this function requires the input direction cosine matrix to be orthonormal, i.e., a member of the SO3 group. For efficiency, no checks are performed on the input direction cosine matrix to check whether it is orthonormal.

This function decomposes a general direction cosine matrix into three primitive direction cosine matrices, whose axes are determined by a ksl_axis_enum_t data structure which is passed in through the axisType parameter. The direction cosine matrix is passed in through r, and the three computed angles are updated and returned in angles.

Optionally, reference angles from a previous nearby position can be passed in the last argument.

Parameters:
  • r – [in] direction cosine matrix

  • axisType – [in] an enum specifying angle sequence

  • angles – [out] sequence of euler angles

  • ... – [in] optional reference angles (a pointer to a vector of the same type as angles) from a nearby pose, used to obtain continuity in angles between poses

inline void ksl_mat3x3_getEulerAnglesWithReference(const ksl_mat3x3_t *r, const ksl_axis_enum_t axisType, ksl_vec3_t *angles, ...)

Obtain double precision sequence of Euler angles using specified axis sequence convention.

This function requires the input direction cosine matrix to be orthonormal, i.e., a member of the SO3 group. For efficiency, no checks are performed on the input direction cosine matrix to verify that it is orthonormal.

This function decomposes a general direction cosine matrix into three primitive direction cosine matrices, whose axes are determined by a ksl_axis_enum_t enum data structure passed in through the axisType parameter. The direction cosine matrix is passed in through the r, and the three computed angles are updated and returned in angles.

Optionally, reference angles from a previous nearby position can be passed in the last argument.

Parameters:
  • r – [in] direction cosine matrix

  • axisType – [in] an enum specifying angle sequence

  • angles – [out] sequence of euler angles

  • ... – [in] optional reference angles (a pointer to a vector of the same type as angles) from a nearby pose, used to obtain continuity in angles between poses

static inline void ksl_mat3x3_setFromEulerAngles(ksl_mat3x3_t*, const ksl_axis_enum_t axisType, const ksl_vec3_t*)

Set a double precision mat3x3 matrix from a sequence of Euler angles.

This function takes three Euler angles in one of twelve rotation orders and outputs a direction cosine matrix. The axis sequence is input using a ksl_axis_enum_t datastructure.

\( R_x = \begin{bmatrix} 1 & 0 & 0\\ 0 & c & -s \\ 0 & s & c \end{bmatrix}\)

\( R_y = \begin{bmatrix} c & 0 & s\\ 0 & 1 & 0 \\ -s & 0 & c \end{bmatrix}\)

\( R_z = \begin{bmatrix} c & -s & 0\\ s & c & 0 \\ 0 & 0 & 1 \end{bmatrix}\)

static inline void ksl_mat3x3_getAxisAngle(const ksl_mat3x3_t *r, ksl_vec3_t *axis, double *angle)

Get axis and angle from a double precision rotation matrix.

This function requires the input direction cosine matrix to be orthonormal, i.e., a member of the SO3 group. For efficiency, no checks are performed on the input direction cosine matrix to verify that it is orthonormal.

Note that if sin is close to 0, the axis of rotation is not well defined.

Parameters:
  • r – [in] input rotation matrix

  • axis – [out] axis of rotation

  • angle – [out] angle of rotation in radians

static inline void ksl_mat3x3_setFromAxisAngle(ksl_mat3x3_t*, const ksl_vec3_t*, const double)

Set double precision rotation matrix from axis and angle representation.

Parameters:
  • r – [out] rotation matrix will be set here

  • axis – [in] axis of rotation

  • angle – [in] angle of rotation in radians

static inline double ksl_mat3x3_determinant(const ksl_mat3x3_t *r_i)

Compute the determinant of a 3x3 double precision matrix.

Parameters:
  • r_i – [in] input 3x3 matrix

Returns:

the determinant of r_i

static inline void ksl_mat3x3_normalize(ksl_mat3x3_t *R)

Re-orthonormalize a rotation matrix in place.

Applies Gram-Schmidt orthonormalization to the columns, which removes the drift that accumulates when rotations are composed many times. The columns are contiguous in memory (column-major storage):

c0 = c0 / |c0|
c1 = c1 - (c0 . c1) c0,  c1 = c1 / |c1|
c2 = c0 x c1
The first column keeps its direction, and the result is a rotation (det R = +1) whatever the sign of the determinant of the input. The input must be close to a rotation, so that its first two columns are independent.

Parameters:
  • R – [in,out] nearly orthonormal matrix, replaced by an orthonormal one

static inline void ksl_mat3x3_normalized(const ksl_mat3x3_t *Ri, ksl_mat3x3_t *Ro)

Compute a re-orthonormalized copy of a rotation matrix.

See ksl_mat3x3_normalize().

Parameters:
  • Ri – [in] nearly orthonormal matrix

  • Ro – [out] orthonormalized copy of Ri

static inline void ksl_mat3x3_setFromAxisDC(ksl_mat3x3_t *r, const ksl_vec3_t *axis, const double *dc)

Set 3x3 rotation matrix from axis and direction cosines.

Single precision

ksl_mat3x3f_t

A general 3x3 single precision matrix.

ksl_mat3x3f()

ksl_mat3x3f_t constructor.

ksl_mat3x3f_cmo()

alternative ksl_mat3x3f_t constructor.

ksl_mat3x3f_alloc()

allocates n ksl_mat3x3f_t datastructures on the heap. Must be freed by the user.

ksl_mat3x3f_setIdentity()

Set a single precision 3x3 matrix to identity.

ksl_mat3x3f_set()

Set a value in a single precision 3x3 matrix at specified row and column index.

ksl_mat3x3f_setFromVectors()

Set a single precision 3x3 matrix from 3 column vectors.

ksl_mat3x3f_get()

Single precision version of ksl_mat3x3_get().

ksl_mat3x3f_copy()

Single precision version of ksl_mat3x3_copy().

ksl_mat3x3f_invert()

Single precision version of ksl_mat3x3_invert().

ksl_mat3x3f_inverted()

Single precision version of ksl_mat3x3_inverted().

ksl_mat3x3f_transpose()

Single precision version of ksl_mat3x3_transpose().

ksl_mat3x3f_transposed()

Single precision version of ksl_mat3x3_transposed().

ksl_mat3x3f_getEulerAngles

This macro is used to obtain a single precision sequence of Euler angles from an orthonormal rotation matrix using a specified axis sequence convention.

ksl_mat3x3f_getEulerAnglesWithReference()

Obtain single precision sequence of Euler angles using specified axis sequence convention.

ksl_mat3x3f_setFromEulerAngles()

Set a single precision mat3x3f matrix from a sequence of Euler angles.

ksl_mat3x3f_getAxisAngle()

Get axis and angle from a single precision rotation matrix.

ksl_mat3x3f_setFromAxisAngle()

Set a single precision rotation matrix from axis and angle representation.

ksl_mat3x3f_determinant()

Compute the determinant of a 3x3 single precision matrix.

ksl_mat3x3f_normalize()

Single precision version of ksl_mat3x3_normalize().

ksl_mat3x3f_normalized()

Single precision version of ksl_mat3x3_normalized().

union ksl_mat3x3f_t
#include <types.h>

A general 3x3 single precision matrix.

This union allows accessing single precision mat3x3 quantities by field name, as a singly dimensioned array, as a doubly dimensioned array, or by accessing a specific column. If using the at or as_array operators, quantities are accessed in column major order.

The following examples illustrate how to access row 2, column 1 (using 0 based indexing) of matrix R. The following access methods are equivalent.

R.as_array[2 + 1 * 3];
R.at[1][2];
R.m21;
R.v1.z;
R.v1.at[2];
R.v[1].z;
R.v[1].at[2];

See also the ksl_mat3x3f_get and ksl_mat3x3f_set functions.

Public Members

float as_array[9]
struct ksl_mat3x3f_t

anonymous union allows accessing quantities at specified index in linear array, where entities are specified in column major order

float at[3][3]
struct ksl_mat3x3f_t

anonymous union allows accessing mat3x3 quantities at specified index in a doubly dimensioned array, where entities are specified in column major order

float m00
float m10
float m20
float m01
float m11
float m21
float m02
float m12
float m22
struct ksl_mat3x3f_t

anonymous union allows accessing rotation matrix quantities by field name

ksl_vec3f_t v0
ksl_vec3f_t v1
ksl_vec3f_t v2
struct ksl_mat3x3f_t

anonymous union allows accessing columns of rotation matrix quantities by field name

ksl_vec3f_t v[3]
struct ksl_mat3x3f_t

anonymous union allows accessing columns of rotation by index matrix quantities at specified index

static inline ksl_mat3x3f_t ksl_mat3x3f(const float m00, const float m01, const float m02, const float m10, const float m11, const float m12, const float m20, const float m21, const float m22)

ksl_mat3x3f_t constructor.

Note that in the constructor, fields are specified in row major order. Internally, ksl_mat3x3f_t datastructures are stored in column major order.

static inline ksl_mat3x3f_t ksl_mat3x3f_cmo(const float m00, const float m10, const float m20, const float m01, const float m11, const float m21, const float m02, const float m12, const float m22)

alternative ksl_mat3x3f_t constructor.

In this alternate constructor, fields are specified in column major order to match the internal layout of ksl_mat3x3f_t datastructures.

ksl_mat3x3f_t *ksl_mat3x3f_alloc(const int n)

allocates n ksl_mat3x3f_t datastructures on the heap. Must be freed by the user.

static inline void ksl_mat3x3f_setIdentity(ksl_mat3x3f_t *r)

Set a single precision 3x3 matrix to identity.

\( I \rightarrow R \)

Parameters:
  • r – [in/out] input 3x3 matrix

static inline void ksl_mat3x3f_set(ksl_mat3x3f_t *R, int row, int column, float value)

Set a value in a single precision 3x3 matrix at specified row and column index.

Bounds checking are performed in debug mode. Bounds checking can be disabled by compiling in release mode using the compiler flag -DNDEBUG.

Parameters:
  • R – [in/out]

  • row – [in] row index, \(0 \le row \lt 3\)

  • column – [in] column index, \(0 \le column \lt 3\)

  • value – [in] value to set

static inline void ksl_mat3x3f_setFromVectors(ksl_mat3x3f_t *R, const ksl_vec3f_t *x, const ksl_vec3f_t *y, const ksl_vec3f_t *z)

Set a single precision 3x3 matrix from 3 column vectors.

\( \begin{bmatrix} \underline{v}_x & \underline{v}_y & \underline{v}_z \end{bmatrix} \rightarrow R \)

Parameters:
  • R – [in/out] 3x3 rotation matrix

  • x – [in] first column to set

  • y – [in] second column to set

  • z – [in] third column to set

static inline float ksl_mat3x3f_get(const ksl_mat3x3f_t *R, const int row, const int column)

Single precision version of ksl_mat3x3_get().

static inline void ksl_mat3x3f_copy(const ksl_mat3x3f_t *ri, ksl_mat3x3f_t *ro)

Single precision version of ksl_mat3x3_copy().

inline int ksl_mat3x3f_invert(ksl_mat3x3f_t *R)

Single precision version of ksl_mat3x3_invert().

Single precision version of ksl_mat3x3_invert().

inline int ksl_mat3x3f_inverted(const ksl_mat3x3f_t *ri, ksl_mat3x3f_t *ro)

Single precision version of ksl_mat3x3_inverted().

Single precision version of ksl_mat3x3_inverted().

static inline void ksl_mat3x3f_transpose(ksl_mat3x3f_t *R)

Single precision version of ksl_mat3x3_transpose().

static inline void ksl_mat3x3f_transposed(const ksl_mat3x3f_t *ri, ksl_mat3x3f_t *ro)

Single precision version of ksl_mat3x3_transposed().

ksl_mat3x3f_getEulerAngles(r, axisType, angles, ...)

This macro is used to obtain a single precision sequence of Euler angles from an orthonormal rotation matrix using a specified axis sequence convention.

Note that this function requires the input direction cosine matrix to be orthonormal, i.e., a member of the SO3 group. For efficiency, no checks are performed on the input direction cosine matrix to check whether it is orthonormal.

This function decomposes a general direction cosine matrix into three primitive direction cosine matrices, whose axes are determined by a ksl_axis_enum_t data structure which is passed in through the axisType parameter. The direction cosine matrix is passed in through r, and the three computed angles are updated and returned in angles.

Optionally, reference angles from a previous nearby position can be passed in the last argument.

Parameters:
  • r – [in] direction cosine matrix

  • axisType – [in] an enum specifying angle sequence

  • angles – [out] sequence of euler angles

  • ... – [in] optional reference angles (a pointer to a vector of the same type as angles) from a nearby pose, used to obtain continuity in angles between poses

inline void ksl_mat3x3f_getEulerAnglesWithReference(const ksl_mat3x3f_t *r, const ksl_axis_enum_t axisType, ksl_vec3f_t *angles, ...)

Obtain single precision sequence of Euler angles using specified axis sequence convention.

This function requires the input direction cosine matrix to be orthonormal, i.e., a member of the SO3 group. For efficiency, no checks are performed on the input direction cosine matrix to verify that it is orthonormal.

This function decomposes a general direction cosine matrix into three primitive direction cosine matrices, whose axes are determined by a ksl_axis_enum_t enum data structure passed in through the axisType parameter. The direction cosine matrix is passed in through the r, and the three computed angles are updated and returned in angles.

Optionally, reference angles from a previous nearby position can be passed in the last argument.

Parameters:
  • r – [in] direction cosine matrix

  • axisType – [in] an enum specifying angle sequence

  • angles – [out] sequence of euler angles

  • ... – [in] optional reference angles (a pointer to a vector of the same type as angles) from a nearby pose, used to obtain continuity in angles between poses

static inline void ksl_mat3x3f_setFromEulerAngles(ksl_mat3x3f_t*, const ksl_axis_enum_t axisType, const ksl_vec3f_t*)

Set a single precision mat3x3f matrix from a sequence of Euler angles.

This function takes three Euler angles in one of twelve rotation orders and outputs a direction cosine matrix. The axis sequence is input using a ksl_axis_enum_t datastructure.

\( R_x = \begin{bmatrix} 1 & 0 & 0\\ 0 & c & -s \\ 0 & s & c \end{bmatrix}\)

\( R_y = \begin{bmatrix} c & 0 & s\\ 0 & 1 & 0 \\ -s & 0 & c \end{bmatrix}\)

\( R_z = \begin{bmatrix} c & -s & 0\\ s & c & 0 \\ 0 & 0 & 1 \end{bmatrix}\)

static inline void ksl_mat3x3f_getAxisAngle(const ksl_mat3x3f_t *r, ksl_vec3f_t *axis, float *angle)

Get axis and angle from a single precision rotation matrix.

This function requires the input direction cosine matrix to be orthonormal, i.e., a member of the SO3 group. For efficiency, no checks are performed on the input direction cosine matrix to verify that it is orthonormal.

Note that if sin is close to 0, the axis of rotation is not well defined.

Parameters:
  • r – [in] input rotation matrix

  • axis – [out] axis of rotation

  • angle – [out] angle of rotation in radians

static inline void ksl_mat3x3f_setFromAxisAngle(ksl_mat3x3f_t *r, const ksl_vec3f_t *axis, const float angle)

Set a single precision rotation matrix from axis and angle representation.

Parameters:
  • r – [out] rotation matrix to set

  • axis – [in] axis of rotation

  • angle – [in] angle of rotation in radians

static inline float ksl_mat3x3f_determinant(const ksl_mat3x3f_t *R)

Compute the determinant of a 3x3 single precision matrix.

Parameters:
  • R – [in] input 3x3 matrix

Returns:

the determinant of R

static inline void ksl_mat3x3f_normalize(ksl_mat3x3f_t *R)

Single precision version of ksl_mat3x3_normalize().

static inline void ksl_mat3x3f_normalized(const ksl_mat3x3f_t *Ri, ksl_mat3x3f_t *Ro)

Single precision version of ksl_mat3x3_normalized().