public void GetLength()
        {
            CatmullRomSegment3F c = new CatmullRomSegment3F
            {
                Point1 = new Vector3(1, 2, 3),
                Point2 = new Vector3(10, 3, 6),
                Point3 = new Vector3(7, 8, 19),
                Point4 = new Vector3(10, 2, 12),
            };

            HermiteSegment3F h = new HermiteSegment3F
            {
                Point1   = c.Point2,
                Tangent1 = (c.Point3 - c.Point1) * 0.5f,
                Tangent2 = (c.Point4 - c.Point2) * 0.5f,
                Point2   = c.Point3,
            };

            float length1 = c.GetLength(0, 1, 20, Numeric.EpsilonF);
            float length2 = h.GetLength(0, 1, 20, Numeric.EpsilonF);

            Assert.IsTrue(Numeric.AreEqual(length1, length2));

            float       approxLength = 0;
            const float step         = 0.0001f;

            for (float u = 0; u <= 1.0f; u += step)
            {
                approxLength += (c.GetPoint(u) - c.GetPoint(u + step)).Length;
            }

            Assert.IsTrue(Numeric.AreEqual(approxLength, length1, 0.01f));
            Assert.IsTrue(Numeric.AreEqual(c.GetLength(0, 1, 100, Numeric.EpsilonF), c.GetLength(0, 0.5f, 100, Numeric.EpsilonF) + c.GetLength(0.5f, 1, 100, Numeric.EpsilonF)));
            Assert.IsTrue(Numeric.AreEqual(c.GetLength(0, 1, 100, Numeric.EpsilonF), c.GetLength(1, 0, 100, Numeric.EpsilonF)));
        }
Ejemplo n.º 2
0
        public void GetLength()
        {
            CatmullRomSegment3F c = new CatmullRomSegment3F
              {
            Point1 = new Vector3F(1, 2, 3),
            Point2 = new Vector3F(10, 3, 6),
            Point3 = new Vector3F(7, 8, 19),
            Point4 = new Vector3F(10, 2, 12),
              };

              HermiteSegment3F h = new HermiteSegment3F
              {
            Point1 = c.Point2,
            Tangent1 = (c.Point3 - c.Point1) * 0.5f,
            Tangent2 = (c.Point4 - c.Point2) * 0.5f,
            Point2 = c.Point3,
              };

              float length1 = c.GetLength(0, 1, 20, Numeric.EpsilonF);
              float length2 = h.GetLength(0, 1, 20, Numeric.EpsilonF);
              Assert.IsTrue(Numeric.AreEqual(length1, length2));

              float approxLength = 0;
              const float step = 0.0001f;
              for (float u = 0; u <= 1.0f; u += step)
            approxLength += (c.GetPoint(u) - c.GetPoint(u + step)).Length;

              Assert.IsTrue(Numeric.AreEqual(approxLength, length1, 0.01f));
              Assert.IsTrue(Numeric.AreEqual(c.GetLength(0, 1, 100, Numeric.EpsilonF), c.GetLength(0, 0.5f, 100, Numeric.EpsilonF) + c.GetLength(0.5f, 1, 100, Numeric.EpsilonF)));
              Assert.IsTrue(Numeric.AreEqual(c.GetLength(0, 1, 100, Numeric.EpsilonF), c.GetLength(1, 0, 100, Numeric.EpsilonF)));
        }
        public void GetPoint()
        {
            CatmullRomSegment3F c = new CatmullRomSegment3F
            {
                Point1 = new Vector3(1, 2, 3),
                Point2 = new Vector3(10, 3, 6),
                Point3 = new Vector3(7, 8, 19),
                Point4 = new Vector3(10, 2, 12),
            };

            HermiteSegment3F h = new HermiteSegment3F
            {
                Point1   = c.Point2,
                Tangent1 = (c.Point3 - c.Point1) * 0.5f,
                Tangent2 = (c.Point4 - c.Point2) * 0.5f,
                Point2   = c.Point3,
            };

            Assert.IsTrue(Vector3.AreNumericallyEqual(c.Point2, c.GetPoint(0)));
            Assert.IsTrue(Vector3.AreNumericallyEqual(c.Point3, c.GetPoint(1)));
            Assert.IsTrue(Vector3.AreNumericallyEqual(h.GetPoint(0.33f), c.GetPoint(0.33f)));
        }
Ejemplo n.º 4
0
        public void GetPoint()
        {
            CatmullRomSegment3F c = new CatmullRomSegment3F
              {
            Point1 = new Vector3F(1, 2, 3),
            Point2 = new Vector3F(10, 3, 6),
            Point3 = new Vector3F(7, 8, 19),
            Point4 = new Vector3F(10, 2, 12),
              };

              HermiteSegment3F h = new HermiteSegment3F
              {
            Point1 = c.Point2,
            Tangent1 = (c.Point3 - c.Point1) * 0.5f,
            Tangent2 = (c.Point4 - c.Point2) * 0.5f,
            Point2 = c.Point3,
              };

              Assert.IsTrue(Vector3F.AreNumericallyEqual(c.Point2, c.GetPoint(0)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(c.Point3, c.GetPoint(1)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(h.GetPoint(0.33f), c.GetPoint(0.33f)));
        }
Ejemplo n.º 5
0
        public void GetPoint()
        {
            Path3F path = CreatePath();
              path.PreLoop = CurveLoopType.Constant;
              path.PostLoop = CurveLoopType.Oscillate;
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(0, 0, 1), path.GetPoint(-10)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(4, 5, 7), path.GetPoint(13)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(4, 5, 7), path.GetPoint(16)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(5, 7, 10), path.GetPoint(17)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(5, 7, 10), path.GetPoint(19)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(5, 7, 13)*0.5f + new Vector3F(6, 7, 14)*0.5f, path.GetPoint(22.5f)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(5, 7, 13) * 0.5f + new Vector3F(6, 7, 14) * 0.5f, path.GetPoint(22.5f)));
              CatmullRomSegment3F catmullOscillate = new CatmullRomSegment3F()
              {
            Point1 = new Vector3F(10, 12, 14),
            Point2 = new Vector3F(10, 14, 8),
            Point3 = new Vector3F(20, 14, 8),
            Point4 = new Vector3F(30, 14, 8),
              };
              Assert.IsTrue(Vector3F.AreNumericallyEqual(catmullOscillate.GetPoint(0.3f), path.GetPoint(43)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(catmullOscillate.GetPoint(0.9f), path.GetPoint(51)));

              CatmullRomSegment3F catmullCircle = new CatmullRomSegment3F()
              {
            Point1 = new Vector3F(10, 12, 14),
            Point2 = new Vector3F(10, 14, 8),
            Point3 = new Vector3F(20, 14, 8),
            Point4 = new Vector3F(30, 14, 8),
              };
              path.PreLoop = CurveLoopType.Linear;
              path.PostLoop = CurveLoopType.Cycle;
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(0, 0, 1) - (new Vector3F(1, 2, 3) - new Vector3F(0, 0, 1)) / 2 * 9, path.GetPoint(1)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(catmullCircle.GetPoint(0.3f), path.GetPoint(43)));

              path.PreLoop = CurveLoopType.Cycle;
              path.PostLoop = CurveLoopType.CycleOffset;
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(10, 14, 8) + new Vector3F(20, 14, 7), path.GetPoint(80f)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(10, 14, 8) + new Vector3F(20, 14, 7) * 2, path.GetPoint(120f)));

              path.PreLoop = CurveLoopType.CycleOffset;
              path.PostLoop = CurveLoopType.Linear;
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(10, 14, 8) - new Vector3F(20, 14, 7), path.GetPoint(0f)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(10, 14, 8) - new Vector3F(20, 14, 7) * 2, path.GetPoint(-40f)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(20, 14, 8) + catmullOscillate.GetTangent(1) / 10 * 50, path.GetPoint(100f)));

              path.PreLoop = CurveLoopType.Oscillate;
              path.PostLoop = CurveLoopType.Constant;
        }