Beispiel #1
0
        public void GetSupportPoint()
        {
            ConvexHullOfPoints emptyConvexHullOfPoints = new ConvexHullOfPoints(Enumerable.Empty<Vector3F>());
              Assert.AreEqual(new Vector3F(0, 0, 0), emptyConvexHullOfPoints.GetSupportPoint(new Vector3F(1, 0, 0)));
              Assert.AreEqual(new Vector3F(0, 0, 0), emptyConvexHullOfPoints.GetSupportPoint(new Vector3F(0, 1, 0)));
              Assert.AreEqual(new Vector3F(0, 0, 0), emptyConvexHullOfPoints.GetSupportPoint(new Vector3F(0, 0, 1)));
              Assert.AreEqual(new Vector3F(0, 0, 0), emptyConvexHullOfPoints.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.AreEqual(p0, new ConvexHullOfPoints(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3F(1, 0, 0)));
              Assert.AreEqual(p2, new ConvexHullOfPoints(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3F(0, 1, 0)));
              Assert.AreEqual(p2, new ConvexHullOfPoints(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3F(0, 0, -1)));
              Assert.AreEqual(p1, new ConvexHullOfPoints(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3F(-1, 0, 1)));
        }
        public void GetSupportPoint()
        {
            ConvexHullOfPoints emptyConvexHullOfPoints = new ConvexHullOfPoints(Enumerable.Empty <Vector3>());

            Assert.AreEqual(new Vector3(0, 0, 0), emptyConvexHullOfPoints.GetSupportPoint(new Vector3(1, 0, 0)));
            Assert.AreEqual(new Vector3(0, 0, 0), emptyConvexHullOfPoints.GetSupportPoint(new Vector3(0, 1, 0)));
            Assert.AreEqual(new Vector3(0, 0, 0), emptyConvexHullOfPoints.GetSupportPoint(new Vector3(0, 0, 1)));
            Assert.AreEqual(new Vector3(0, 0, 0), emptyConvexHullOfPoints.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.AreEqual(p0, new ConvexHullOfPoints(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3(1, 0, 0)));
            Assert.AreEqual(p2, new ConvexHullOfPoints(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3(0, 1, 0)));
            Assert.AreEqual(p2, new ConvexHullOfPoints(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3(0, 0, -1)));
            Assert.AreEqual(p1, new ConvexHullOfPoints(new[] { p0, p1, p2 }).GetSupportPoint(new Vector3(-1, 0, 1)));
        }
        public void RandomConvexHullOfPoints()
        {
            // 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)));
                }

                ConvexHullOfPoints convex = new ConvexHullOfPoints(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),
            };

            ConvexHullOfPoints convex = new ConvexHullOfPoints(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);
            }
        }
Beispiel #5
0
        public void RandomConvexHullOfPoints()
        {
            // 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)));

            ConvexHullOfPoints convex = new ConvexHullOfPoints(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);
            }
              }
        }
Beispiel #6
0
        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),
              };

              ConvexHullOfPoints convex = new ConvexHullOfPoints(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);
              }
        }