Math module

inverse_lengyel

procedure · 1 overloadSource

Inverts a Matrix4 through its adjugate and determinant, returning (success, result). Fails when abs(determinant) is below epsilon (default 0.0001, an absolute limit), giving the identity as result. Less robust than inverse for badly scaled matrices.

ExampleOpen in playground ↗
ok, inv := inverse_lengyel(make_scale_matrix4(xyz(2, 4, 8)));
assert(ok && inv._11 == 0.5 && inv._22 == 0.25 && inv._33 == 0.125);
inverse_lengyel :: (
    m: Matrix4,
    epsilon := 0.0001
) -> (success: bool, result: Matrix4)

The inverse from the adjugate and determinant. False and the identity when there is none.

Parameters

m: Matrix4
the matrix.
epsilon := 0.0001
a determinant with a smaller magnitude counts as having no inverse.

Returns

success: bool
result: Matrix4

See also