public void Matrix3x2DeterminantTest1() { Matrix3x2 a = new Matrix3x2(); a.M11 = 5.0f; a.M12 = 2.0f; a.M21 = 12.0f; a.M22 = 6.8f; a.M31 = 6.5f; a.M32 = 1.0f; Matrix3x2 i; Assert.True(Matrix3x2.Invert(a, out i)); float detA = a.GetDeterminant(); float detI = i.GetDeterminant(); float t = 1.0f / detI; // only accurate to 3 precision Assert.True(System.Math.Abs(detA - t) < 1e-3, "Matrix3x2.Determinant was not set correctly."); // sanity check against 4x4 version Assert.Equal(new Matrix4x4(a).GetDeterminant(), detA); Assert.Equal(new Matrix4x4(i).GetDeterminant(), detI); }
public void Matrix3x2InvertTest1() { Matrix3x2 a = new Matrix3x2(); a.M11 = 0.0f; a.M12 = 2.0f; a.M21 = 0.0f; a.M22 = 4.0f; a.M31 = 5.0f; a.M32 = 6.0f; float detA = a.GetDeterminant(); Assert.True(MathHelper.Equal(detA, 0.0f), "Matrix3x2.Invert did not return the expected value."); Matrix3x2 actual; Assert.False(Matrix3x2.Invert(a, out actual)); // all the elements in Actual is NaN Assert.True( float.IsNaN(actual.M11) && float.IsNaN(actual.M12) && float.IsNaN(actual.M21) && float.IsNaN(actual.M22) && float.IsNaN(actual.M31) && float.IsNaN(actual.M32) , "Matrix3x2.Invert did not return the expected value."); }
public static Vector2 Solve(this Matrix3x2 m, Vector2 b) { float det = 1f / m.GetDeterminant(); return(new Vector2( det * (m.M22 * b.X - m.M12 * b.Y), det * (m.M11 * b.Y - m.M21 * b.X))); }
public void Matrix3x2DeterminantTest() { Matrix3x2 target = Matrix3x2.CreateRotation(MathHelper.ToRadians(30.0f)); float val = 1.0f; float det = target.GetDeterminant(); Assert.True(MathHelper.Equal(val, det), "Matrix3x2.Determinant was not set correctly."); }
public void Matrix3x2DeterminantTest1() { Matrix3x2 a = new Matrix3x2(); a.M11 = 5.0f; a.M12 = 2.0f; a.M21 = 12.0f; a.M22 = 6.8f; a.M31 = 6.5f; a.M32 = 1.0f; Matrix3x2 i; Assert.IsTrue(Matrix3x2.Invert(a, out i)); float detA = a.GetDeterminant(); float detI = i.GetDeterminant(); float t = 1.0f / detI; // only accurate to 3 precision Assert.IsTrue(System.Math.Abs(detA - t) < 1e-3, "Matrix3x2.GetDeterminant was not set correctly."); // sanity check against 4x4 version Assert.AreEqual(new Matrix4x4(a).GetDeterminant(), detA); Assert.AreEqual(new Matrix4x4(i).GetDeterminant(), detI); }
/// <summary> /// Returns a value that indicates whether the specified matrix is degenerate /// containing one or more values equivalent to <see cref="float.NaN"/> or a /// zero determinant and therefore cannot be used for linear transforms. /// </summary> /// <param name="matrix">The transform matrix.</param> public static bool IsDegenerate(Matrix3x2 matrix) => IsNaN(matrix) || IsZero(matrix.GetDeterminant());