public void Clone() { ConvexPolyhedron convexPolyhedron = new ConvexPolyhedron( new[] { new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 2, 0), new Vector3(0, 0, 3), new Vector3(1, 5, 0), new Vector3(0, 1, 7), }); ConvexPolyhedron clone = convexPolyhedron.Clone() as ConvexPolyhedron; Assert.IsNotNull(clone); for (int i = 0; i < clone.Vertices.Count; i++) { Assert.AreEqual(convexPolyhedron.Vertices[i], clone.Vertices[i]); } Assert.AreEqual(convexPolyhedron.GetAabb(Pose.Identity), clone.GetAabb(Pose.Identity)); Assert.AreEqual(convexPolyhedron.InnerPoint, clone.InnerPoint); Assert.AreEqual(convexPolyhedron.GetSupportPoint(new Vector3(1, 1, 1)), clone.GetSupportPoint(new Vector3(1, 1, 1))); Assert.AreEqual(convexPolyhedron.GetAabb(Pose.Identity).Minimum, clone.GetAabb(Pose.Identity).Minimum); Assert.AreEqual(convexPolyhedron.GetAabb(Pose.Identity).Maximum, clone.GetAabb(Pose.Identity).Maximum); }
public void SerializationBinary() { var a = new ConvexPolyhedron( new[] { new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 2, 0), new Vector3(0, 0, 3), new Vector3(1, 5, 0), new Vector3(0, 1, 7), }); // Serialize object. var stream = new MemoryStream(); var formatter = new BinaryFormatter(); formatter.Serialize(stream, a); // Deserialize object. stream.Position = 0; var deserializer = new BinaryFormatter(); var b = (ConvexPolyhedron)deserializer.Deserialize(stream); for (int i = 0; i < b.Vertices.Count; i++) { Assert.AreEqual(a.Vertices[i], b.Vertices[i]); } Assert.AreEqual(a.GetAabb(Pose.Identity), b.GetAabb(Pose.Identity)); Assert.AreEqual(a.InnerPoint, b.InnerPoint); Assert.AreEqual(a.GetSupportPoint(new Vector3(1, 1, 1)), b.GetSupportPoint(new Vector3(1, 1, 1))); }
public void GetSupportPoint() { ConvexPolyhedron emptyConvexPolyhedron = new ConvexPolyhedron(Enumerable.Empty<Vector3F>()); Assert.AreEqual(new Vector3F(0, 0, 0), emptyConvexPolyhedron.GetSupportPoint(new Vector3F(1, 0, 0))); Assert.AreEqual(new Vector3F(0, 0, 0), emptyConvexPolyhedron.GetSupportPoint(new Vector3F(0, 1, 0))); Assert.AreEqual(new Vector3F(0, 0, 0), emptyConvexPolyhedron.GetSupportPoint(new Vector3F(0, 0, 1))); Assert.AreEqual(new Vector3F(0, 0, 0), emptyConvexPolyhedron.GetSupportPoint(new Vector3F(1, 1, 1))); Vector3F p0 = new Vector3F(2, 0, 0); Vector3F p1 = new Vector3F(-1, -1, -2); Vector3F p2 = new Vector3F(0, 2, -3); Assert.IsTrue(Vector3F.AreNumericallyEqual(p0, new ConvexPolyhedron(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3F(1, 0, 0)))); Assert.IsTrue(Vector3F.AreNumericallyEqual(p2, new ConvexPolyhedron(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3F(0, 1, 0)))); Assert.IsTrue(Vector3F.AreNumericallyEqual(p2, new ConvexPolyhedron(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3F(0, 0, -1)))); Assert.IsTrue(Vector3F.AreNumericallyEqual(p1, new ConvexPolyhedron(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3F(-1, 0, 1)))); }
public void Clone() { ConvexPolyhedron convexPolyhedron = new ConvexPolyhedron( new[] { new Vector3F(0, 0, 0), new Vector3F(1, 0, 0), new Vector3F(0, 2, 0), new Vector3F(0, 0, 3), new Vector3F(1, 5, 0), new Vector3F(0, 1, 7), }); ConvexPolyhedron clone = convexPolyhedron.Clone() as ConvexPolyhedron; Assert.IsNotNull(clone); for (int i = 0; i < clone.Vertices.Count; i++) Assert.AreEqual(convexPolyhedron.Vertices[i], clone.Vertices[i]); Assert.AreEqual(convexPolyhedron.GetAabb(Pose.Identity), clone.GetAabb(Pose.Identity)); Assert.AreEqual(convexPolyhedron.InnerPoint, clone.InnerPoint); Assert.AreEqual(convexPolyhedron.GetSupportPoint(new Vector3F(1,1,1)), clone.GetSupportPoint(new Vector3F(1, 1, 1))); Assert.AreEqual(convexPolyhedron.GetAabb(Pose.Identity).Minimum, clone.GetAabb(Pose.Identity).Minimum); Assert.AreEqual(convexPolyhedron.GetAabb(Pose.Identity).Maximum, clone.GetAabb(Pose.Identity).Maximum); }
public void GetSupportPoint() { ConvexPolyhedron emptyConvexPolyhedron = new ConvexPolyhedron(Enumerable.Empty <Vector3>()); Assert.AreEqual(new Vector3(0, 0, 0), emptyConvexPolyhedron.GetSupportPoint(new Vector3(1, 0, 0))); Assert.AreEqual(new Vector3(0, 0, 0), emptyConvexPolyhedron.GetSupportPoint(new Vector3(0, 1, 0))); Assert.AreEqual(new Vector3(0, 0, 0), emptyConvexPolyhedron.GetSupportPoint(new Vector3(0, 0, 1))); Assert.AreEqual(new Vector3(0, 0, 0), emptyConvexPolyhedron.GetSupportPoint(new Vector3(1, 1, 1))); Vector3 p0 = new Vector3(2, 0, 0); Vector3 p1 = new Vector3(-1, -1, -2); Vector3 p2 = new Vector3(0, 2, -3); Assert.IsTrue(Vector3.AreNumericallyEqual(p0, new ConvexPolyhedron(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3(1, 0, 0)))); Assert.IsTrue(Vector3.AreNumericallyEqual(p2, new ConvexPolyhedron(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3(0, 1, 0)))); Assert.IsTrue(Vector3.AreNumericallyEqual(p2, new ConvexPolyhedron(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3(0, 0, -1)))); Assert.IsTrue(Vector3.AreNumericallyEqual(p1, new ConvexPolyhedron(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3(-1, 0, 1)))); }
public void RandomConvexPolyhedron() { // Use a fixed seed. RandomHelper.Random = new Random(12345); // Try polyhedra with 0, 1, 2, ... points. for (int numberOfPoints = 0; numberOfPoints < 100; numberOfPoints++) { List <Vector3> points = new List <Vector3>(numberOfPoints); // Create random polyhedra. for (int i = 0; i < numberOfPoints; i++) { points.Add( new Vector3( RandomHelper.Random.NextFloat(-10, 10), RandomHelper.Random.NextFloat(-20, 20), RandomHelper.Random.NextFloat(-100, 100))); } //var convexHull = GeometryHelper.CreateConvexHull(points); ConvexPolyhedron convex = new ConvexPolyhedron(points); // Sample primary directions Vector3 right = new Vector3(2, 0, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(right, points), convex.GetSupportPoint(right), right); Vector3 left = new Vector3(-2, 0, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(left, points), convex.GetSupportPoint(left), left); Vector3 up = new Vector3(0, 2, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(up, points), convex.GetSupportPoint(up), up); Vector3 down = new Vector3(0, -2, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(down, points), convex.GetSupportPoint(down), down); Vector3 back = new Vector3(0, 0, 2); AssertSupportPointsAreEquivalent(GetSupportPoint(back, points), convex.GetSupportPoint(back), back); Vector3 front = new Vector3(0, 0, -2); AssertSupportPointsAreEquivalent(GetSupportPoint(front, points), convex.GetSupportPoint(front), front); // Sample random directions for (int i = 0; i < 10; i++) { Vector3 direction = RandomHelper.Random.NextVector3(-1, 1); if (direction.IsNumericallyZero) { continue; } Vector3 supportPoint = convex.GetSupportPoint(direction); Vector3 reference = GetSupportPoint(direction, points); // The support points can be different, e.g. if a an edge of face is normal to the // direction. When projected onto the direction both support points must be at equal // distance. AssertSupportPointsAreEquivalent(reference, supportPoint, direction); } } }
public void SimpleTetrahedron() { List <Vector3> points = new List <Vector3> { new Vector3(0, 0, 0), new Vector3(0, 1, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1), }; ConvexPolyhedron convex = new ConvexPolyhedron(points); // Sample primary directions Vector3 right = new Vector3(2, 0, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(right, points), convex.GetSupportPoint(right), right); Vector3 left = new Vector3(-2, 0, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(left, points), convex.GetSupportPoint(left), left); Vector3 up = new Vector3(0, 2, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(up, points), convex.GetSupportPoint(up), up); Vector3 down = new Vector3(0, -2, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(down, points), convex.GetSupportPoint(down), down); Vector3 back = new Vector3(0, 0, 2); AssertSupportPointsAreEquivalent(GetSupportPoint(back, points), convex.GetSupportPoint(back), back); Vector3 front = new Vector3(0, 0, -2); AssertSupportPointsAreEquivalent(GetSupportPoint(front, points), convex.GetSupportPoint(front), front); // Sample random directions for (int i = 0; i < 10; i++) { Vector3 direction = RandomHelper.Random.NextVector3(-1, 1); Vector3 supportPoint = convex.GetSupportPoint(direction); Vector3 reference = GetSupportPoint(direction, points); // The support points can be different, e.g. if a an edge of face is normal to the // direction. When projected onto the direction both support points must be at equal // distance. AssertSupportPointsAreEquivalent(reference, supportPoint, direction); } }
public void RandomConvexPolyhedron() { // Use a fixed seed. RandomHelper.Random = new Random(12345); // Try polyhedra with 0, 1, 2, ... points. for (int numberOfPoints = 0; numberOfPoints < 100; numberOfPoints++) { List<Vector3F> points = new List<Vector3F>(numberOfPoints); // Create random polyhedra. for (int i = 0; i < numberOfPoints; i++) points.Add( new Vector3F( RandomHelper.Random.NextFloat(-10, 10), RandomHelper.Random.NextFloat(-20, 20), RandomHelper.Random.NextFloat(-100, 100))); //var convexHull = GeometryHelper.CreateConvexHull(points); ConvexPolyhedron convex = new ConvexPolyhedron(points); // Sample primary directions Vector3F right = new Vector3F(2, 0, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(right, points), convex.GetSupportPoint(right), right); Vector3F left = new Vector3F(-2, 0, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(left, points), convex.GetSupportPoint(left), left); Vector3F up = new Vector3F(0, 2, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(up, points), convex.GetSupportPoint(up), up); Vector3F down = new Vector3F(0, -2, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(down, points), convex.GetSupportPoint(down), down); Vector3F back = new Vector3F(0, 0, 2); AssertSupportPointsAreEquivalent(GetSupportPoint(back, points), convex.GetSupportPoint(back), back); Vector3F front = new Vector3F(0, 0, -2); AssertSupportPointsAreEquivalent(GetSupportPoint(front, points), convex.GetSupportPoint(front), front); // Sample random directions for (int i = 0; i < 10; i++) { Vector3F direction = RandomHelper.Random.NextVector3F(-1, 1); if (direction.IsNumericallyZero) continue; Vector3F supportPoint = convex.GetSupportPoint(direction); Vector3F reference = GetSupportPoint(direction, points); // The support points can be different, e.g. if a an edge of face is normal to the // direction. When projected onto the direction both support points must be at equal // distance. AssertSupportPointsAreEquivalent(reference, supportPoint, direction); } } }
public void SimpleTetrahedron() { List<Vector3F> points = new List<Vector3F> { new Vector3F(0, 0, 0), new Vector3F(0, 1, 0), new Vector3F(1, 0, 0), new Vector3F(0, 0, 1), }; ConvexPolyhedron convex = new ConvexPolyhedron(points); // Sample primary directions Vector3F right = new Vector3F(2, 0, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(right, points), convex.GetSupportPoint(right), right); Vector3F left = new Vector3F(-2, 0, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(left, points), convex.GetSupportPoint(left), left); Vector3F up = new Vector3F(0, 2, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(up, points), convex.GetSupportPoint(up), up); Vector3F down = new Vector3F(0, -2, 0); AssertSupportPointsAreEquivalent(GetSupportPoint(down, points), convex.GetSupportPoint(down), down); Vector3F back = new Vector3F(0, 0, 2); AssertSupportPointsAreEquivalent(GetSupportPoint(back, points), convex.GetSupportPoint(back), back); Vector3F front = new Vector3F(0, 0, -2); AssertSupportPointsAreEquivalent(GetSupportPoint(front, points), convex.GetSupportPoint(front), front); // Sample random directions for (int i = 0; i < 10; i++) { Vector3F direction = RandomHelper.Random.NextVector3F(-1, 1); Vector3F supportPoint = convex.GetSupportPoint(direction); Vector3F reference = GetSupportPoint(direction, points); // The support points can be different, e.g. if a an edge of face is normal to the // direction. When projected onto the direction both support points must be at equal // distance. AssertSupportPointsAreEquivalent(reference, supportPoint, direction); } }
public void SerializationBinary() { var a = new ConvexPolyhedron( new[] { new Vector3F(0, 0, 0), new Vector3F(1, 0, 0), new Vector3F(0, 2, 0), new Vector3F(0, 0, 3), new Vector3F(1, 5, 0), new Vector3F(0, 1, 7), }); // Serialize object. var stream = new MemoryStream(); var formatter = new BinaryFormatter(); formatter.Serialize(stream, a); // Deserialize object. stream.Position = 0; var deserializer = new BinaryFormatter(); var b = (ConvexPolyhedron)deserializer.Deserialize(stream); for (int i = 0; i < b.Vertices.Count; i++) Assert.AreEqual(a.Vertices[i], b.Vertices[i]); Assert.AreEqual(a.GetAabb(Pose.Identity), b.GetAabb(Pose.Identity)); Assert.AreEqual(a.InnerPoint, b.InnerPoint); Assert.AreEqual(a.GetSupportPoint(new Vector3F(1, 1, 1)), b.GetSupportPoint(new Vector3F(1, 1, 1))); }