Matrix-vector operations

Overview

These functions apply a rotation or a rigid body transformation to a vector. The operand abbreviations are explained in Getting Started: dr is a rotation matrix, d a full transformation \(D = (R, \underline{t})\), and inv after either one means its inverse.

Points and free vectors transform differently. The coordinates of a point, such as the location of a marker on a body, are transformed from frame \(b\) to frame \(a\) with both the rotation and the translation:

\[\underline{p}^a = R^{ab}\, \underline{p}^b + \underline{t}^a_{ab} \qquad \text{(}\texttt{ksl\_product\_dv}\text{)}\]

A free vector, such as a velocity, a force or the direction of an axis, has no location, so its components are transformed by the rotation alone:

\[\underline{v}^a = R^{ab}\, \underline{v}^b \qquad \text{(}\texttt{ksl\_product\_drv}\text{)}\]

Using the wrong one is a common source of errors.

Inverse transformations go the other way, transforming coordinates from frame \(a\) to frame \(b\). They are applied directly from \(R\) and \(\underline{t}\), without computing and storing the inverse:

\[\underline{p}^b = (R^{ab})^T (\underline{p}^a - \underline{t}^a_{ab}) \qquad \text{(}\texttt{ksl\_product\_dinvv}\text{)}\]

Translations along an axis. The drvtx, drvty and drvtz functions rotate a vector that lies along a coordinate axis, \(R\,(t\,\underline{e}_x)\). That is just \(t\) times the first column of \(R\), so it costs 3 multiplications instead of the 9 multiplications and 6 additions of a general matrix-vector product.

Double precision

ksl_product_drv()

Compute the double precision matrix product of a 3x3 matrix \(R^{oi}\) and a 3x1 vector \(\underline{v}^i_{oi}\) .

ksl_product_drvinv()

Compute the double precision matrix product of a 3x3 matrix \(R^{oi}\) and the inverse of a 3x1 input vector \(\underline{v}^i_{oi}\) .

ksl_product_drinvv()

Rotate a vector by an inverse rotation: vo = ri^T * vi.

ksl_product_drinvvinv()

Rotate a negated vector by an inverse rotation: vo = -ri^T * vi.

ksl_product_drvtx()

Rotate a vector along the x axis: vo = ri * (ti * ex).

ksl_product_drvtxinv()

Rotate a negated vector along the x axis: vo = ri * (-ti * ex).

ksl_product_drvty()

Rotate a vector along the y axis: vo = ri * (ti * ey).

ksl_product_drvtyinv()

Rotate a negated vector along the y axis: vo = ri * (-ti * ey).

ksl_product_drvtz()

Rotate a vector along the z axis: vo = ri * (ti * ez).

ksl_product_drvtzinv()

Rotate a negated vector along the z axis: vo = ri * (-ti * ez).

ksl_product_dv()

Transform a point by an SE3 transformation: vo = Di * vi = R * vi + t.

ksl_product_dinvv()

Transform a point by an inverse SE3 transformation: vo = Di^-1 * vi = R^T (vi - t).

static inline void ksl_product_drv(const ksl_mat3x3_t *r_oi, const ksl_vec3_t *v_i, ksl_vec3_t *v_o)

Compute the double precision matrix product of a 3x3 matrix \(R^{oi}\) and a 3x1 vector \(\underline{v}^i_{oi}\).

\(R^{oi} \underline{v}^i_{oi} \rightarrow \underline{v}^o_{oi} \)

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

  • v_i – [in] input vector

  • v_o – [out] result returned in v_o

static inline void ksl_product_drvinv(const ksl_mat3x3_t *ri, const ksl_vec3_t *vi, ksl_vec3_t *vo)

Compute the double precision matrix product of a 3x3 matrix \(R^{oi}\) and the inverse of a 3x1 input vector \(\underline{v}^i_{oi}\).

\(R^{oi} (-\underline{v}^i_{oi}) \rightarrow \underline{v}^o_{io} \)

\(-R^{oi} \underline{v}^i_{oi} \rightarrow \underline{v}^o_{io} \)

\(R^{oi} \underline{v}^i_{io} \rightarrow \underline{v}^o_{io} \)

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

  • vi – [in] input vector

  • vo – [out] result, -ri * vi

static inline void ksl_product_drinvv(const ksl_mat3x3_t *ri, const ksl_vec3_t *vi, ksl_vec3_t *vo)

Rotate a vector by an inverse rotation: vo = ri^T * vi.

Parameters:
  • ri – [in] rotation matrix

  • vi – [in] vector

  • vo – [out] product ri^T * vi

static inline void ksl_product_drinvvinv(const ksl_mat3x3_t *ri, const ksl_vec3_t *vi, ksl_vec3_t *vo)

Rotate a negated vector by an inverse rotation: vo = -ri^T * vi.

Parameters:
  • ri – [in] rotation matrix

  • vi – [in] vector

  • vo – [out] product -ri^T * vi

static inline void ksl_product_drvtx(const ksl_mat3x3_t *ri, const double ti, ksl_vec3_t *vo)

Rotate a vector along the x axis: vo = ri * (ti * ex).

Parameters:
  • ri – [in] rotation matrix

  • ti – [in] length of the vector along the x axis

  • vo – [out] ti times the x column of ri

static inline void ksl_product_drvtxinv(const ksl_mat3x3_t *ri, const double ti, ksl_vec3_t *vo)

Rotate a negated vector along the x axis: vo = ri * (-ti * ex).

Parameters:
  • ri – [in] rotation matrix

  • ti – [in] length of the vector along the x axis

  • vo – [out] -ti times the x column of ri

static inline void ksl_product_drvty(const ksl_mat3x3_t *ri, const double ti, ksl_vec3_t *vo)

Rotate a vector along the y axis: vo = ri * (ti * ey).

Parameters:
  • ri – [in] rotation matrix

  • ti – [in] length of the vector along the y axis

  • vo – [out] ti times the y column of ri

static inline void ksl_product_drvtyinv(const ksl_mat3x3_t *ri, const double ti, ksl_vec3_t *vo)

Rotate a negated vector along the y axis: vo = ri * (-ti * ey).

Parameters:
  • ri – [in] rotation matrix

  • ti – [in] length of the vector along the y axis

  • vo – [out] -ti times the y column of ri

static inline void ksl_product_drvtz(const ksl_mat3x3_t *ri, const double ti, ksl_vec3_t *vo)

Rotate a vector along the z axis: vo = ri * (ti * ez).

Parameters:
  • ri – [in] rotation matrix

  • ti – [in] length of the vector along the z axis

  • vo – [out] ti times the z column of ri

static inline void ksl_product_drvtzinv(const ksl_mat3x3_t *ri, const double ti, ksl_vec3_t *vo)

Rotate a negated vector along the z axis: vo = ri * (-ti * ez).

Parameters:
  • ri – [in] rotation matrix

  • ti – [in] length of the vector along the z axis

  • vo – [out] -ti times the z column of ri

static inline void ksl_product_dv(const ksl_SE3_t *Di, const ksl_vec3_t *vi, ksl_vec3_t *vo)

Transform a point by an SE3 transformation: vo = Di * vi = R * vi + t.

Parameters:
  • Di – [in] SE3 transformation

  • vi – [in] point

  • vo – [out] transformed point

static inline void ksl_product_dinvv(const ksl_SE3_t *Di, const ksl_vec3_t *vi, ksl_vec3_t *vo)

Transform a point by an inverse SE3 transformation: vo = Di^-1 * vi = R^T (vi - t).

Expresses a point given in the reference frame in the frame of Di.

Parameters:
  • Di – [in] SE3 transformation to invert

  • vi – [in] point

  • vo – [out] transformed point

Single precision

ksl_product_drvf()

Compute the single precision matrix product of a 3x3 matrix \(R^{oi}\) and a 3x1 vector \(\underline{v}^i_{oi}\) .

ksl_product_drvinvf()

Single precision version of ksl_product_drvinv().

ksl_product_drinvvf()

Single precision version of ksl_product_drinvv().

ksl_product_drinvvinvf()

Single precision version of ksl_product_drinvvinv().

ksl_product_drvtxf()

Single precision version of ksl_product_drvtx().

ksl_product_drvtxinvf()

Single precision version of ksl_product_drvtxinv().

ksl_product_drvtyf()

Single precision version of ksl_product_drvty().

ksl_product_drvtyinvf()

Single precision version of ksl_product_drvtyinv().

ksl_product_drvtzf()

Single precision version of ksl_product_drvtz().

ksl_product_drvtzinvf()

Single precision version of ksl_product_drvtzinv().

ksl_product_dvf()

Single precision version of ksl_product_dv().

ksl_product_dinvvf()

Single precision version of ksl_product_dinvv().

static inline void ksl_product_drvf(const ksl_mat3x3f_t *r_oi, const ksl_vec3f_t *v_i, ksl_vec3f_t *v_o)

Compute the single precision matrix product of a 3x3 matrix \(R^{oi}\) and a 3x1 vector \(\underline{v}^i_{oi}\).

\(R^{oi} \underline{v}^i_{oi} \rightarrow \underline{v}^o_{oi} \)

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

  • v_i – [in] input vector

  • v_o – [out] result returned in v_o

static inline void ksl_product_drvinvf(const ksl_mat3x3f_t *ri, const ksl_vec3f_t *vi, ksl_vec3f_t *vo)

Single precision version of ksl_product_drvinv().

static inline void ksl_product_drinvvf(const ksl_mat3x3f_t *ri, const ksl_vec3f_t *vi, ksl_vec3f_t *vo)

Single precision version of ksl_product_drinvv().

static inline void ksl_product_drinvvinvf(const ksl_mat3x3f_t *ri, const ksl_vec3f_t *vi, ksl_vec3f_t *vo)

Single precision version of ksl_product_drinvvinv().

static inline void ksl_product_drvtxf(const ksl_mat3x3f_t *ri, const float ti, ksl_vec3f_t *vo)

Single precision version of ksl_product_drvtx().

static inline void ksl_product_drvtxinvf(const ksl_mat3x3f_t *ri, const float ti, ksl_vec3f_t *vo)

Single precision version of ksl_product_drvtxinv().

static inline void ksl_product_drvtyf(const ksl_mat3x3f_t *ri, const float ti, ksl_vec3f_t *vo)

Single precision version of ksl_product_drvty().

static inline void ksl_product_drvtyinvf(const ksl_mat3x3f_t *ri, const float ti, ksl_vec3f_t *vo)

Single precision version of ksl_product_drvtyinv().

static inline void ksl_product_drvtzf(const ksl_mat3x3f_t *ri, const float ti, ksl_vec3f_t *vo)

Single precision version of ksl_product_drvtz().

static inline void ksl_product_drvtzinvf(const ksl_mat3x3f_t *ri, const float ti, ksl_vec3f_t *vo)

Single precision version of ksl_product_drvtzinv().

static inline void ksl_product_dvf(const ksl_SE3f_t *Di, const ksl_vec3f_t *vi, ksl_vec3f_t *vo)

Single precision version of ksl_product_dv().

static inline void ksl_product_dinvvf(const ksl_SE3f_t *Di, const ksl_vec3f_t *vi, ksl_vec3f_t *vo)

Single precision version of ksl_product_dinvv().