public void CreateRotation2() { double angle = (double)MathHelper.ToRadians(30); Matrix22D m = Matrix22D.CreateRotation(angle); Assert.IsTrue(Vector2D.AreNumericallyEqual(new Vector2D((double)Math.Cos(angle), (double)Math.Sin(angle)), m * Vector2D.UnitX)); }
public void Transform2D() { // Transform forward and inverse and compare with initial values. var random = new Random(1234567); var s = new Vector2D[16, 8]; var t = new Vector2D[16, 8]; for (int i = 0; i < s.GetLength(0); i++) { for (int j = 0; j < s.GetLength(1); j++) { s[i, j] = random.NextVector2D(-10, 10); t[i, j] = s[i, j]; } } var fft = new FastFourierTransformD(16); fft.Transform2D(t, true); Assert.IsFalse(Vector2D.AreNumericallyEqual(s[0, 0], t[0, 0])); fft.Transform2D(t, false); for (int i = 0; i < s.GetLength(0); i++) { for (int j = 0; j < s.GetLength(1); j++) { Assert.IsTrue(Vector2D.AreNumericallyEqual(s[i, j], t[i, j])); } } }
public void CreateRotation() { Matrix22D m = Matrix22D.CreateRotation(0.0); Assert.AreEqual(Matrix22D.Identity, m); m = Matrix22D.CreateRotation((double)Math.PI / 2); Assert.IsTrue(Vector2D.AreNumericallyEqual(Vector2D.UnitY, m * Vector2D.UnitX)); }
public void InverseWithNearSingularMatrix() { Matrix22D m = new Matrix22D(0.0001, 0, 0, 0.0001); Vector2D v = Vector2D.One; Vector2D w = m * v; Assert.IsTrue(Vector2D.AreNumericallyEqual(v, m.Inverse * w)); Assert.IsTrue(Matrix22D.AreNumericallyEqual(Matrix22D.Identity, m * m.Inverse)); }
public void AreEqualWithEpsilon() { double epsilon = 0.001; Vector2D u = new Vector2D(1.0, 2.0); Vector2D v = new Vector2D(1.002, 2.002); Vector2D w = new Vector2D(1.0001, 2.0001); Assert.IsTrue(Vector2D.AreNumericallyEqual(u, u, epsilon)); Assert.IsFalse(Vector2D.AreNumericallyEqual(u, v, epsilon)); Assert.IsTrue(Vector2D.AreNumericallyEqual(u, w, epsilon)); }
public void Inverse() { Assert.AreEqual(Matrix22D.Identity, Matrix22D.Identity.Inverse); Matrix22D m = new Matrix22D(1, 2, 3, 4); Vector2D v = Vector2D.One; Vector2D w = m * v; Assert.IsTrue(Vector2D.AreNumericallyEqual(v, m.Inverse * w)); Assert.IsTrue(Matrix22D.AreNumericallyEqual(Matrix22D.Identity, m * m.Inverse)); }
public void CosineInterpolationVector2D() { Vector2D v = new Vector2D(1.0, 10.0); Vector2D w = new Vector2D(2.0, 20.0); Vector2D lerp0 = InterpolationHelper.CosineInterpolation(v, w, 0.0); Vector2D lerp1 = InterpolationHelper.CosineInterpolation(v, w, 1.0); Vector2D lerp05 = InterpolationHelper.CosineInterpolation(v, w, 0.5); Assert.AreEqual(v, lerp0); Assert.AreEqual(w, lerp1); Assert.IsTrue(Vector2D.AreNumericallyEqual(new Vector2D(1.5, 15.0), lerp05)); }
public void AreEqual() { double originalEpsilon = Numeric.EpsilonD; Numeric.EpsilonD = 1e-8; Vector2D u = new Vector2D(1.0, 2.0); Vector2D v = new Vector2D(1.000001, 2.000001); Vector2D w = new Vector2D(1.00000001, 2.00000001); Assert.IsTrue(Vector2D.AreNumericallyEqual(u, u)); Assert.IsFalse(Vector2D.AreNumericallyEqual(u, v)); Assert.IsTrue(Vector2D.AreNumericallyEqual(u, w)); Numeric.EpsilonD = originalEpsilon; }
public void MultiplyVector() { Vector2D v = new Vector2D(2.34, 3.45); Assert.AreEqual(v, Matrix22D.Multiply(Matrix22D.Identity, v)); Assert.AreEqual(Vector2D.Zero, Matrix22D.Multiply(Matrix22D.Zero, v)); Matrix22D m = new Matrix22D(12, 23, 45, 67); Assert.IsTrue(Vector2D.AreNumericallyEqual(v, Matrix22D.Multiply(m * m.Inverse, v))); for (int i = 0; i < 2; i++) { Assert.AreEqual(Vector2D.Dot(m.GetRow(i), v), Matrix22D.Multiply(m, v)[i]); } }
public void Transform1D() { // Transform forward and inverse and compare with initial values. var random = new Random(1234567); var s = new Vector2D[16]; var t = new Vector2D[16]; for (int i = 0; i < s.Length; i++) { s[i] = random.NextVector2D(-10, 10); t[i] = s[i]; } FastFourierTransformD.Transform1D(t, true); FastFourierTransformD.Transform1D(t, false); for (int i = 0; i < s.Length; i++) { Assert.IsTrue(Vector2D.AreNumericallyEqual(s[i], t[i])); } }