Function decompose_matrix(std::array<double, 6>)

Function Documentation

std::array<double, 6> decompose_matrix(std::array<double, 6> mat)

Decomposes a 2x3 affine transformation matrix into its underlying geometric components.

A transformation matrix \( \begin{pmatrix} a & b & c \\ d & e & f \end{pmatrix} \) can be decomposed in rotation \( \phi \), scale in X- and Y direction \( sx, sy \), shearing \( s \) and translation in X- and Y \( tx, ty \).

The decomposition is not unique, there exist other decompositions. However, it seems that this particular decomposition is rather stable and for each component one gets a rather smooth function across an order.

Warning

When rotation \( \phi \) is close to 0, it sometimes alters between \( \pm 2\pi \). This is a problem when trying to make a smooth spline across an order. Temporary fix is to add \( 2 \pi \) when values are near \( -\pi \).

Parameters

mat – 2x3 transformation matrix

Returns

[sx, sy, shear, \( \phi \), tx, ty]