Exemplo n.º 1
0
 /// <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));
 }
Exemplo n.º 2
0
        // 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));
            }
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
 /// <summary>True if 'm' can be inverted</summary>
 public static bool IsInvertible(m2x2 m)
 {
     return(Determinant(m) != 0);
 }
Exemplo n.º 6
0
 /// <summary>Return the inverse of 'm' assuming m is orthonormal</summary>
 public static m2x2 InvertFast(m2x2 m)
 {
     InvertFast(ref m);
     return(m);
 }
Exemplo n.º 7
0
 /// <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);
 }
Exemplo n.º 8
0
 /// <summary>Return the transpose of 'm'</summary>
 public static m2x2 Transpose(m2x2 m)
 {
     Transpose(ref m);
     return(m);
 }
Exemplo n.º 9
0
 /// <summary>Return true if any components of 'm' are NaN</summary>
 public static bool IsNaN(m2x2 m)
 {
     return
         (IsNaN(m.x) ||
          IsNaN(m.y));
 }
Exemplo n.º 10
0
 /// <summary>Finite test of matrix elements</summary>
 public static bool IsFinite(m2x2 m)
 {
     return
         (IsFinite(m.x) &&
          IsFinite(m.y));
 }
Exemplo n.º 11
0
 /// <summary>Return the minimum element value in 'm'</summary>
 public static float MinElement(m2x2 m)
 {
     return(Min(
                MinElement(m.x),
                MinElement(m.y)));
 }
Exemplo n.º 12
0
 /// <summary>Return the maximum element value in 'mm'</summary>
 public static float MaxElement(m2x2 m)
 {
     return(Max(
                MaxElement(m.x),
                MaxElement(m.y)));
 }
Exemplo n.º 13
0
 /// <summary>Absolute value of 'x'</summary>
 public static m2x2 Abs(m2x2 x)
 {
     return(new m2x2(
                Abs(x.x),
                Abs(x.y)));
 }
Exemplo n.º 14
0
 public static bool FEql(m2x2 a, m2x2 b)
 {
     return(FEqlRelative(a, b, TinyF));
 }
Exemplo n.º 15
0
 /// <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);
 }
Exemplo n.º 16
0
 /// <summary>Return an orthonormalised version of 'm'</summary>
 public static m2x2 Orthonormalise(m2x2 m)
 {
     Orthonormalise(ref m);
     return(m);
 }
Exemplo n.º 17
0
 /// <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));
 }
Exemplo n.º 18
0
 /// <summary>Transpose 'm' in-place</summary>
 public static void Transpose(ref m2x2 m)
 {
     Swap(ref m.x.y, ref m.y.x);
 }
Exemplo n.º 19
0
 /// <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));
 }