inverse

Compute the inverse of a matrix

  1. M inverse(M m)
  2. M inverse(M m)
  3. M inverse(M m)
    pure @safe @nogc nothrow
    M
    inverse
    (
    M
    )
    (
    in M m
    )
    if ()

Examples

/// Example from https://en.wikipedia.org/wiki/Gaussian_elimination
const m = FMat3(
    2, -1, 0,
    -1, 2, -1,
    0, -1, 2
);
const invM = inverse(m);

import gfx.math.approx : approxUlp;
assert(approxUlp(invM, FMat3(
    0.75f, 0.5f, 0.25f,
    0.5f,  1f,   0.5f,
    0.25f, 0.5f, 0.75f
)));
assert(approxUlp(inverse(invM), m));
import gfx.math.transform : translation;
import gfx.math.approx : approxUlpAndAbs;

const trM = translation!float(3, 4, 5);
const expected = translation!float(-3, -4, -5);
const inv = inverse(trM);

assert(approxUlpAndAbs( inv, expected ));
assert(approxUlpAndAbs( inverse(inv), trM ));
assert(approxUlpAndAbs( inv * trM, FMat4.identity ));

Meta