public void GetMesh() { var s = new BoxShape(1, 2, 3); var mesh = s.GetMesh(0.05f, 3); Assert.AreEqual(12, mesh.NumberOfTriangles); // No more tests necessary because we see the result in the samples. }
public void ConvexHullOfPointsTest() { var s = new BoxShape(1, 2, 3); var v0 = s.GetVolume(0.001f, 10); var s1 = new ConvexHullOfPoints(s.GetMesh(0.1f, 1).Vertices); var v1 = s1.GetVolume(0.001f, 10); Assert.IsTrue(Numeric.AreEqual(v0, v1, 0.01f * (1 + v0))); // 1% error is allowed. }
public void BoxVolume() { var s = new BoxShape(1, 2, 3); Assert.AreEqual(1 * 2 * 3, s.GetVolume(0.0001f, 10)); var m = s.GetMesh(0.001f, 4); Assert.AreEqual(1 * 2 * 3, m.GetVolume()); }
public void BoxMass() { var b = new BoxShape(1, 2, 3); float m0; Vector3F com0; Matrix33F i0; MassHelper.GetMass(b, new Vector3F(1, -2, -3), 1, true, 0.001f, 10, out m0, out com0, out i0); var m = b.GetMesh(0.1f, 1); m.Transform(Matrix44F.CreateScale(1, -2, -3)); float m1; Vector3F com1; Matrix33F i1; MassHelper.GetMass(m, out m1, out com1, out i1); Assert.AreEqual(m0, m1); Assert.AreEqual(com0, com1); Assert.AreEqual(i0, i1); // Try other density. float m2; Vector3F com2; Matrix33F i2; MassHelper.GetMass(b, new Vector3F(1, -2, -3), 0.7f, true, 0.001f, 10, out m2, out com2, out i2); Assert.AreEqual(m0 * 0.7f, m2); Assert.AreEqual(com0, com2); Assert.IsTrue(Matrix33F.AreNumericallyEqual(i0 * 0.7f, i2)); const float e = 0.01f; // Try with target mass. float m3; Vector3F com3; Matrix33F i3; MassHelper.GetMass(b, new Vector3F(1, -2, -3), 23, false, 0.001f, 10, out m3, out com3, out i3); Assert.IsTrue(Numeric.AreEqual(23, m3, e * (1 + m0))); Assert.IsTrue(Vector3F.AreNumericallyEqual(com0, com3, e * (1 + com0.Length))); Assert.IsTrue(Matrix33F.AreNumericallyEqual(i0 * 23 / m0, i3, e * (1 + i0.Trace))); }