/// <summary>True if 'm' is orthonormal</summary> public static bool IsOrthonormal(m2x2 m) { return (FEql(m.x.LengthSq, 1f) && FEql(m.y.LengthSq, 1f) && FEql(Dot(m.x, m.y), 0f)); }
// Permute the rotation vectors in a matrix by 'n' public static m2x2 PermuteRotation(m2x2 mat, int n) { switch (n % 2) { default: return(mat); case 1: return(new m2x2(mat.y, mat.x)); } }
/// <summary>Return the inverse of 'm'</summary> public static m2x2 Invert(m2x2 m) { Debug.Assert(IsInvertible(m), "Matrix has no inverse"); var det = Determinant(m); var tmp = new m2x2( new v2(m.y.y, -m.x.y) / det, new v2(-m.y.x, m.x.x) / det); return(tmp); }
public static bool FEqlRelative(m2x2 a, m2x2 b, float tol) { var max_a = MaxElement(Abs(a)); var max_b = MaxElement(Abs(b)); if (max_b == 0) { return(max_a < tol); } if (max_a == 0) { return(max_b < tol); } var abs_max_element = Max(max_a, max_b); return(FEqlAbsolute(a, b, tol * abs_max_element)); }
/// <summary>True if 'm' can be inverted</summary> public static bool IsInvertible(m2x2 m) { return(Determinant(m) != 0); }
/// <summary>Return the inverse of 'm' assuming m is orthonormal</summary> public static m2x2 InvertFast(m2x2 m) { InvertFast(ref m); return(m); }
/// <summary>Invert 'm' in place assuming m is orthonormal</summary> public static void InvertFast(ref m2x2 m) { Debug.Assert(IsOrthonormal(m), "Matrix is not orthonormal"); Transpose(ref m); }
/// <summary>Return the transpose of 'm'</summary> public static m2x2 Transpose(m2x2 m) { Transpose(ref m); return(m); }
/// <summary>Return true if any components of 'm' are NaN</summary> public static bool IsNaN(m2x2 m) { return (IsNaN(m.x) || IsNaN(m.y)); }
/// <summary>Finite test of matrix elements</summary> public static bool IsFinite(m2x2 m) { return (IsFinite(m.x) && IsFinite(m.y)); }
/// <summary>Return the minimum element value in 'm'</summary> public static float MinElement(m2x2 m) { return(Min( MinElement(m.x), MinElement(m.y))); }
/// <summary>Return the maximum element value in 'mm'</summary> public static float MaxElement(m2x2 m) { return(Max( MaxElement(m.x), MaxElement(m.y))); }
/// <summary>Absolute value of 'x'</summary> public static m2x2 Abs(m2x2 x) { return(new m2x2( Abs(x.x), Abs(x.y))); }
public static bool FEql(m2x2 a, m2x2 b) { return(FEqlRelative(a, b, TinyF)); }
/// <summary>Orthonormalise 'm' in-place</summary> public static void Orthonormalise(ref m2x2 m) { m.x = Normalise(m.x); m.y = Normalise(m.y - Dot(m.x, m.y) * m.x); }
/// <summary>Return an orthonormalised version of 'm'</summary> public static m2x2 Orthonormalise(m2x2 m) { Orthonormalise(ref m); return(m); }
/// <summary>Return the determinant of 'm'</summary> public static float Determinant(m2x2 m) { return((float)((double)m.x.x * m.y.y - (double)m.x.y * m.y.x)); }
/// <summary>Transpose 'm' in-place</summary> public static void Transpose(ref m2x2 m) { Swap(ref m.x.y, ref m.y.x); }
/// <summary>Approximate equal</summary> public static bool FEqlAbsolute(m2x2 a, m2x2 b, float tol) { return (FEqlAbsolute(a.x, b.x, tol) && FEqlAbsolute(a.y, b.y, tol)); }