affineMult

Affine matrix multiplication.

Perform a multiplication of two 2x3 or two 3x4 matrices as if their last row were [ 0, 0, 1] or [ 0, 0, 0, 1 ]. Allows manipulation of smaller matrices when only affine transformation are required. Note: translation, rotation, scaling, shearing and any combination of those are affine transforms. Projection is not affine. I.e. for 2D, an affine transform is held in 2x3 matrix, 2x2 for rotation and scaling and an additional column for translation. The same applies with 3D and 3x4 matrices.

This is not implemented as an operator as it is not a mathematical operation (ml.columnLength != mr.rowLength).

pure @safe @nogc nothrow
affineMult
(
ML
MR
)
(
in ML ml
,
in MR mr
)
if (
areMat!(2, 3, ML, MR) ||
areMat!(3, 4, ML, MR)
)

Examples

import gfx.math.approx : approxUlp;

/// full matrices
immutable fm1 = FMat3x3(
    1, 2, 3,
    4, 5, 6,
    0, 0, 1
);
immutable fm2 = DMat3x3(
     7,  8,  9,
    10, 11, 12,
     0,  0,  1
);

/// affine matrices
immutable am1 = FMat2x3(
    1, 2, 3,
    4, 5, 6,
);
immutable am2 = DMat2x3(
     7,  8,  9,
    10, 11, 12,
);

immutable expected = (fm1 * fm2).slice!(0, 2, 0, 3);
immutable result = affineMult(am1, am2);
assert( approxUlp(expected, result) );

Meta