public void ScaledConvexMass() { var s = new ScaledConvexShape(new CapsuleShape(1, 3), new Vector3F(0.9f, -0.8f, 1.2f)); float m0; Vector3F com0; Matrix33F i0; MassHelper.GetMass(s, new Vector3F(1, -2, -3), 1, true, 0.001f, 10, out m0, out com0, out i0); var m = s.GetMesh(0.001f, 6); m.Transform(Matrix44F.CreateScale(1, -2, -3)); float m1; Vector3F com1; Matrix33F i1; MassHelper.GetMass(m, out m1, out com1, out i1); const float e = 0.01f; Assert.IsTrue(Numeric.AreEqual(m0, m1, e * (1 + m0))); Assert.IsTrue(Vector3F.AreNumericallyEqual(com0, com1, e * (1 + com0.Length))); Assert.IsTrue(Matrix33F.AreNumericallyEqual(i0, i1, e * (1 + i0.Trace))); // Try other density. float m2; Vector3F com2; Matrix33F i2; MassHelper.GetMass(s, new Vector3F(1, -2, -3), 0.7f, true, 0.001f, 10, out m2, out com2, out i2); Assert.IsTrue(Numeric.AreEqual(m0 * 0.7f, m2, e * (1 + m0))); Assert.IsTrue(Vector3F.AreNumericallyEqual(com0, com2, e * (1 + com0.Length))); Assert.IsTrue(Matrix33F.AreNumericallyEqual(i0 * 0.7f, i2, e * (1 + i0.Trace))); }
public void ScaledConvexShape() { var s = new CylinderShape(1, 2); var v0 = s.GetVolume(0.001f, 10); var s1 = new ScaledConvexShape(new CylinderShape(10, 10), new Vector3F(0.1f, 0.2f, 0.1f)); var v1 = s1.GetVolume(0.0001f, 10); Assert.IsTrue(Numeric.AreEqual(v0, v1, 0.01f * (1 + v0))); // 1% error is allowed. }