public void IsRotation() { Assert.IsTrue(!Matrix33D.Zero.IsRotation); Assert.IsTrue(Matrix33D.Identity.IsRotation); Assert.IsTrue(Matrix33D.CreateRotation(new Vector3D(1, 2, 3).Normalized, 0.5).IsRotation); Assert.IsTrue(!new Matrix33D(1, 0, 0, 0, 1, 0, 0, 0, -1).IsRotation); }
public void CreateRotationZ() { double angle = (double)MathHelper.ToRadians(30); Matrix33D m = Matrix33D.CreateRotationZ(angle); Assert.IsTrue(Vector3D.AreNumericallyEqual(new Vector3D((double)Math.Cos(angle), (double)Math.Sin(angle), 0), m * Vector3D.UnitX)); QuaternionD q = QuaternionD.CreateRotation(Vector3D.UnitZ, angle); Assert.IsTrue(Vector3D.AreNumericallyEqual(q.Rotate(Vector3D.One), m * Vector3D.One)); Assert.IsTrue(Matrix33D.AreNumericallyEqual(Matrix33D.CreateRotation(Vector3D.UnitZ, angle), m)); }
public void RotationMatrix33() { double angle = -1.6; Vector3D axis = new Vector3D(1.0, 2.0, -3.0); QuaternionD q = QuaternionD.CreateRotation(axis, angle); Matrix33D m33 = Matrix33D.CreateRotation(axis, angle); Vector3D v = new Vector3D(0.3, -2.4, 5.6); Vector3D result1 = q.ToRotationMatrix33() * v; Vector3D result2 = m33 * v; Assert.IsTrue(Vector3D.AreNumericallyEqual(result1, result2)); }
public void CreateRotation() { Matrix33D m = Matrix33D.CreateRotation(Vector3D.UnitX, 0.0); Assert.AreEqual(Matrix33D.Identity, m); m = Matrix33D.CreateRotation(Vector3D.UnitX, (double)Math.PI / 2); Assert.IsTrue(Vector3D.AreNumericallyEqual(Vector3D.UnitZ, m * Vector3D.UnitY)); m = Matrix33D.CreateRotation(Vector3D.UnitY, (double)Math.PI / 2); Assert.IsTrue(Vector3D.AreNumericallyEqual(Vector3D.UnitX, m * Vector3D.UnitZ)); m = Matrix33D.CreateRotation(Vector3D.UnitZ, (double)Math.PI / 2); Assert.IsTrue(Vector3D.AreNumericallyEqual(Vector3D.UnitY, m * Vector3D.UnitX)); }
public void QuaternionDFromMatrix33() { Vector3D v = Vector3D.One; Matrix33D m = Matrix33D.Identity; QuaternionD q = QuaternionD.CreateRotation(m); Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v))); m = Matrix33D.CreateRotation(Vector3D.UnitX, 0.3); q = QuaternionD.CreateRotation(m); Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v))); m = Matrix33D.CreateRotation(Vector3D.UnitY, 1.0); q = QuaternionD.CreateRotation(m); Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v))); m = Matrix33D.CreateRotation(Vector3D.UnitZ, 4.0); q = QuaternionD.CreateRotation(m); Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v))); m = Matrix33D.Identity; q = QuaternionD.CreateRotation(m); Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v))); m = Matrix33D.CreateRotation(-Vector3D.UnitX, 1.3); q = QuaternionD.CreateRotation(m); Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v))); m = Matrix33D.CreateRotation(-Vector3D.UnitY, -1.4); q = QuaternionD.CreateRotation(m); Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v))); m = Matrix33D.CreateRotation(-Vector3D.UnitZ, -0.1); q = QuaternionD.CreateRotation(m); Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v))); m = new Matrix33D(0, 0, 1, 0, -1, 0, 1, 0, 0); q = QuaternionD.CreateRotation(m); Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v))); m = new Matrix33D(-1, 0, 0, 0, 1, 0, 0, 0, -1); q = QuaternionD.CreateRotation(m); Assert.IsTrue(Vector3D.AreNumericallyEqual(m * v, q.Rotate(v))); }
public void Division() { double angle1 = 0.4; Vector3D axis1 = new Vector3D(1.0, 2.0, 3.0); QuaternionD q1 = QuaternionD.CreateRotation(axis1, angle1); Matrix33D m1 = Matrix33D.CreateRotation(axis1, angle1); double angle2 = -1.6; Vector3D axis2 = new Vector3D(1.0, -2.0, -3.5); QuaternionD q2 = QuaternionD.CreateRotation(axis2, angle2); Matrix33D m2 = Matrix33D.CreateRotation(axis2, angle2); Vector3D v = new Vector3D(0.3, -2.4, 5.6); Vector3D result1 = QuaternionD.Divide(q2, q1).Rotate(v); Vector3D result2 = m2 * m1.Inverse * v; Assert.IsTrue(Vector3D.AreNumericallyEqual(result1, result2)); }
public void Test1() { PoseD p = PoseD.Identity; Assert.AreEqual(Matrix44D.Identity, p.ToMatrix44D()); Assert.AreEqual(Matrix33D.Identity, p.Orientation); Assert.AreEqual(Vector3D.Zero, p.Position); p.Position = new Vector3D(1, 2, 3); p.Orientation = Matrix33D.CreateRotation(new Vector3D(3, -4, 9), 0.49); Assert.IsTrue(Vector4D.AreNumericallyEqual(new Vector4D(p.ToWorldDirection(Vector3D.UnitX), 0), p * new Vector4D(1, 0, 0, 0))); Assert.IsTrue(Vector4D.AreNumericallyEqual(new Vector4D(p.ToWorldDirection(Vector3D.UnitY), 0), p * new Vector4D(0, 1, 0, 0))); Assert.IsTrue(Vector4D.AreNumericallyEqual(new Vector4D(p.ToWorldDirection(Vector3D.UnitZ), 0), p * new Vector4D(0, 0, 1, 0))); Assert.IsTrue(Vector4D.AreNumericallyEqual(new Vector4D(p.ToWorldPosition(Vector3D.UnitX), 1), p * new Vector4D(1, 0, 0, 1))); Assert.IsTrue(Vector4D.AreNumericallyEqual(new Vector4D(p.ToWorldPosition(Vector3D.UnitY), 1), p * new Vector4D(0, 1, 0, 1))); Assert.IsTrue(Vector4D.AreNumericallyEqual(new Vector4D(p.ToWorldPosition(Vector3D.UnitZ), 1), p * new Vector4D(0, 0, 1, 1))); Assert.IsTrue(Vector4D.AreNumericallyEqual(new Vector4D(p.ToLocalDirection(Vector3D.UnitX), 0), p.Inverse * new Vector4D(1, 0, 0, 0))); Assert.IsTrue(Vector4D.AreNumericallyEqual(new Vector4D(p.ToLocalDirection(Vector3D.UnitY), 0), p.Inverse * new Vector4D(0, 1, 0, 0))); Assert.IsTrue(Vector4D.AreNumericallyEqual(new Vector4D(p.ToLocalDirection(Vector3D.UnitZ), 0), p.Inverse * new Vector4D(0, 0, 1, 0))); Assert.IsTrue(Vector4D.AreNumericallyEqual(new Vector4D(p.ToLocalPosition(Vector3D.UnitX), 1), p.Inverse * new Vector4D(1, 0, 0, 1))); Assert.IsTrue(Vector4D.AreNumericallyEqual(new Vector4D(p.ToLocalPosition(Vector3D.UnitY), 1), p.Inverse * new Vector4D(0, 1, 0, 1))); Assert.IsTrue(Vector4D.AreNumericallyEqual(new Vector4D(p.ToLocalPosition(Vector3D.UnitZ), 1), p.Inverse * new Vector4D(0, 0, 1, 1))); PoseD p2 = PoseD.FromMatrix(new Matrix44D(p.Orientation, Vector3D.Zero)); Assert.IsTrue(Matrix33D.AreNumericallyEqual(p.Orientation, p2.Orientation)); Assert.IsTrue(Vector3D.AreNumericallyEqual(p2.Position, Vector3D.Zero)); Matrix44D m = p2; m.SetColumn(3, new Vector4D(p.Position, 1)); p2 = PoseD.FromMatrix(m); Assert.IsTrue(Matrix33D.AreNumericallyEqual(p.Orientation, p2.Orientation)); Assert.AreEqual(p.Position, p2.Position); //Assert.IsTrue(Vector3D.AreNumericallyEqual(p.Position, p2.Position)); // Test other constructors. Assert.AreEqual(Vector3D.Zero, new PoseD(QuaternionD.CreateRotationX(0.3)).Position); Assert.AreEqual(Matrix33D.CreateRotationX(0.3), new PoseD(Matrix33D.CreateRotationX(0.3)).Orientation); Assert.AreEqual(new Vector3D(1, 2, 3), new PoseD(new Vector3D(1, 2, 3)).Position); Assert.AreEqual(Matrix33D.Identity, new PoseD(new Vector3D(1, 2, 3)).Orientation); }
public void Axis() { Vector3D axis = new Vector3D(1.0, 2.0, 3.0); double angle = 0.2; QuaternionD q = QuaternionD.CreateRotation(axis, angle); Assert.IsTrue(Numeric.AreEqual(angle, q.Angle)); Assert.IsTrue(Vector3D.AreNumericallyEqual(axis.Normalized, q.Axis)); axis = new Vector3D(1.0, 1.0, 1.0); q.Axis = axis; Assert.IsTrue(Numeric.AreEqual(angle, q.Angle)); Assert.IsTrue(Vector3D.AreNumericallyEqual(axis.Normalized, q.Axis)); Assert.IsTrue(Vector3D.AreNumericallyEqual(Matrix33D.CreateRotation(axis, angle) * Vector3D.One, q.Rotate(Vector3D.One))); Assert.AreEqual(Vector3D.Zero, QuaternionD.Identity.Axis); q.Axis = Vector3D.Zero; Assert.AreEqual(QuaternionD.Identity, q); }
public void CreateRotation() { QuaternionD q; // From matrix vs. from angle/axis Matrix33D m = Matrix33D.CreateRotation(Vector3D.UnitX, (double)Math.PI / 4); q = QuaternionD.CreateRotation(m); QuaternionD q2 = QuaternionD.CreateRotation(Vector3D.UnitX, (double)Math.PI / 4); Assert.IsTrue(QuaternionD.AreNumericallyEqual(q2, q)); m = Matrix33D.CreateRotation(Vector3D.UnitY, (double)Math.PI / 4); q = QuaternionD.CreateRotation(m); q2 = QuaternionD.CreateRotation(Vector3D.UnitY, (double)Math.PI / 4); Assert.IsTrue(QuaternionD.AreNumericallyEqual(q2, q)); m = Matrix33D.CreateRotation(Vector3D.UnitZ, (double)Math.PI / 4); q = QuaternionD.CreateRotation(m); q2 = QuaternionD.CreateRotation(Vector3D.UnitZ, (double)Math.PI / 4); Assert.IsTrue(QuaternionD.AreNumericallyEqual(q2, q)); // From vector-vector Vector3D start, end; start = Vector3D.UnitX; end = Vector3D.UnitY; q = QuaternionD.CreateRotation(start, end); Assert.IsTrue(Vector3D.AreNumericallyEqual(end, q.ToRotationMatrix33() * start)); start = Vector3D.UnitY; end = Vector3D.UnitZ; q = QuaternionD.CreateRotation(start, end); Assert.IsTrue(Vector3D.AreNumericallyEqual(end, q.ToRotationMatrix33() * start)); start = Vector3D.UnitZ; end = Vector3D.UnitX; q = QuaternionD.CreateRotation(start, end); Assert.IsTrue(Vector3D.AreNumericallyEqual(end, q.ToRotationMatrix33() * start)); start = new Vector3D(1, 1, 1); end = new Vector3D(1, 1, 1); q = QuaternionD.CreateRotation(start, end); Assert.IsTrue(Vector3D.AreNumericallyEqual(end, q.ToRotationMatrix33() * start)); start = new Vector3D(1.0, 1.0, 1.0); end = new Vector3D(-1.0, -1.0, -1.0); q = QuaternionD.CreateRotation(start, end); Assert.IsTrue(Vector3D.AreNumericallyEqual(end, q.ToRotationMatrix33() * start)); start = new Vector3D(-1.0, 2.0, 1.0); end = new Vector3D(-2.0, -1.0, -1.0); q = QuaternionD.CreateRotation(start, end); Assert.IsTrue(Vector3D.AreNumericallyEqual(end, q.ToRotationMatrix33() * start)); double degree45 = MathHelper.ToRadians(45); q = QuaternionD.CreateRotation(degree45, Vector3D.UnitZ, degree45, Vector3D.UnitY, degree45, Vector3D.UnitX, false); QuaternionD expected = QuaternionD.CreateRotation(Vector3D.UnitZ, degree45) * QuaternionD.CreateRotation(Vector3D.UnitY, degree45) * QuaternionD.CreateRotation(Vector3D.UnitX, degree45); Assert.IsTrue(QuaternionD.AreNumericallyEqual(expected, q)); q = QuaternionD.CreateRotation(degree45, Vector3D.UnitZ, degree45, Vector3D.UnitY, degree45, Vector3D.UnitX, true); expected = QuaternionD.CreateRotation(Vector3D.UnitX, degree45) * QuaternionD.CreateRotation(Vector3D.UnitY, degree45) * QuaternionD.CreateRotation(Vector3D.UnitZ, degree45); Assert.IsTrue(QuaternionD.AreNumericallyEqual(expected, q)); }
public void CreateRotationException() { Matrix33D.CreateRotation(Vector3D.Zero, 1); }