コード例 #1
0
        public void GetLength()
        {
            CardinalSegment2F c = new CardinalSegment2F
              {
            Point1 = new Vector2F(1, 2),
            Point2 = new Vector2F(10, 3),
            Point3 = new Vector2F(7, 8),
            Point4 = new Vector2F(10, 2),
            Tension = 0.3f
              };

              HermiteSegment2F h = new HermiteSegment2F
              {
            Point1 = c.Point2,
            Tangent1 = (1 - c.Tension) * (c.Point3 - c.Point1) * 0.5f,
            Tangent2 = (1 - c.Tension) * (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)));
        }
コード例 #2
0
        public void GetLength()
        {
            HermiteSegment2F s = new HermiteSegment2F
            {
                Point1   = new Vector2F(1, 2),
                Tangent1 = (new Vector2F(10, 3) - new Vector2F(1, 2)) * 3,
                Tangent2 = (new Vector2F(10, 2) - new Vector2F(7, 8)) * 3,
                Point2   = new Vector2F(10, 2),
            };

            BezierSegment2F b = new BezierSegment2F
            {
                Point1        = new Vector2F(1, 2),
                ControlPoint1 = new Vector2F(10, 3),
                ControlPoint2 = new Vector2F(7, 8),
                Point2        = new Vector2F(10, 2),
            };

            float length1 = s.GetLength(0, 1, 20, Numeric.EpsilonF);
            float length2 = b.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 += (s.GetPoint(u) - s.GetPoint(u + step)).Length;
            }

            Assert.IsTrue(Numeric.AreEqual(approxLength, length1, 0.01f));
            Assert.IsTrue(Numeric.AreEqual(s.GetLength(0, 1, 100, Numeric.EpsilonF), s.GetLength(0, 0.5f, 100, Numeric.EpsilonF) + s.GetLength(0.5f, 1, 100, Numeric.EpsilonF)));
            Assert.IsTrue(Numeric.AreEqual(s.GetLength(0, 1, 100, Numeric.EpsilonF), s.GetLength(1, 0, 100, Numeric.EpsilonF)));
        }
コード例 #3
0
        public void GetLength()
        {
            CatmullRomSegment2F c = new CatmullRomSegment2F
            {
                Point1 = new Vector2F(1, 2),
                Point2 = new Vector2F(10, 3),
                Point3 = new Vector2F(7, 8),
                Point4 = new Vector2F(10, 2),
            };

            HermiteSegment2F h = new HermiteSegment2F
            {
                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)));
        }
コード例 #4
0
        public void GetLength()
        {
            HermiteSegment2F s = new HermiteSegment2F
              {
            Point1 = new Vector2F(1, 2),
            Tangent1 = (new Vector2F(10, 3) - new Vector2F(1, 2)) * 3,
            Tangent2 = (new Vector2F(10, 2) - new Vector2F(7, 8)) * 3,
            Point2 = new Vector2F(10, 2),
              };

              BezierSegment2F b = new BezierSegment2F
              {
            Point1 = new Vector2F(1, 2),
            ControlPoint1 = new Vector2F(10, 3),
            ControlPoint2 = new Vector2F(7, 8),
            Point2 = new Vector2F(10, 2),
              };

              float length1 = s.GetLength(0, 1, 20, Numeric.EpsilonF);
              float length2 = b.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 += (s.GetPoint(u) - s.GetPoint(u + step)).Length;

              Assert.IsTrue(Numeric.AreEqual(approxLength, length1, 0.01f));
              Assert.IsTrue(Numeric.AreEqual(s.GetLength(0, 1, 100, Numeric.EpsilonF), s.GetLength(0, 0.5f, 100, Numeric.EpsilonF) + s.GetLength(0.5f, 1, 100, Numeric.EpsilonF)));
              Assert.IsTrue(Numeric.AreEqual(s.GetLength(0, 1, 100, Numeric.EpsilonF), s.GetLength(1, 0, 100, Numeric.EpsilonF)));
        }
コード例 #5
0
        public void GetTangent()
        {
            HermiteSegment2F s = new HermiteSegment2F
            {
                Point1   = new Vector2F(1, 2),
                Tangent1 = (new Vector2F(10, 3) - new Vector2F(1, 2)) * 3,
                Tangent2 = (new Vector2F(10, 2) - new Vector2F(7, 8)) * 3,
                Point2   = new Vector2F(10, 2),
            };

            BezierSegment2F b = new BezierSegment2F
            {
                Point1        = new Vector2F(1, 2),
                ControlPoint1 = new Vector2F(10, 3),
                ControlPoint2 = new Vector2F(7, 8),
                Point2        = new Vector2F(10, 2),
            };

            Assert.IsTrue(Vector2F.AreNumericallyEqual(s.Tangent1, s.GetTangent(0)));
            Assert.IsTrue(Vector2F.AreNumericallyEqual(s.Tangent2, s.GetTangent(1)));
            Assert.IsTrue(Vector2F.AreNumericallyEqual(b.GetTangent(0.7f), s.GetTangent(0.7f)));
        }
コード例 #6
0
        public void GetTangent()
        {
            CatmullRomSegment2F c = new CatmullRomSegment2F
            {
                Point1 = new Vector2F(1, 2),
                Point2 = new Vector2F(10, 3),
                Point3 = new Vector2F(7, 8),
                Point4 = new Vector2F(10, 2),
            };

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

            Assert.IsTrue(Vector2F.AreNumericallyEqual(h.Tangent1, c.GetTangent(0)));
            Assert.IsTrue(Vector2F.AreNumericallyEqual(h.Tangent2, c.GetTangent(1)));
            Assert.IsTrue(Vector2F.AreNumericallyEqual(h.GetTangent(0.7f), c.GetTangent(0.7f)));
        }
コード例 #7
0
        public void GetPoint()
        {
            CatmullRomSegment2F c = new CatmullRomSegment2F
              {
            Point1 = new Vector2F(1, 2),
            Point2 = new Vector2F(10, 3),
            Point3 = new Vector2F(7, 8),
            Point4 = new Vector2F(10, 2),
              };

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

              Assert.IsTrue(Vector2F.AreNumericallyEqual(c.Point2, c.GetPoint(0)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(c.Point3, c.GetPoint(1)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(h.GetPoint(0.33f), c.GetPoint(0.33f)));
        }
コード例 #8
0
        public void GetPoint()
        {
            HermiteSegment2F s = new HermiteSegment2F
              {
            Point1 = new Vector2F(1, 2),
            Tangent1 = (new Vector2F(10, 3) - new Vector2F(1, 2)) * 3,
            Tangent2 = (new Vector2F(10, 2) - new Vector2F(7, 8)) * 3,
            Point2 = new Vector2F(10, 2),
              };

              BezierSegment2F b = new BezierSegment2F
              {
            Point1 = new Vector2F(1, 2),
            ControlPoint1 = new Vector2F(10, 3),
            ControlPoint2 = new Vector2F(7, 8),
            Point2 = new Vector2F(10, 2),
              };

              Assert.IsTrue(Vector2F.AreNumericallyEqual(s.Point1, s.GetPoint(0)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(s.Point2, s.GetPoint(1)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(b.GetPoint(0.33f), s.GetPoint(0.33f)));
        }
コード例 #9
0
        public void GetPoint()
        {
            CardinalSegment2F c = new CardinalSegment2F
            {
                Point1  = new Vector2F(1, 2),
                Point2  = new Vector2F(10, 3),
                Point3  = new Vector2F(7, 8),
                Point4  = new Vector2F(10, 2),
                Tension = 0.3f
            };

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

            Assert.IsTrue(Vector2F.AreNumericallyEqual(c.Point2, c.GetPoint(0)));
            Assert.IsTrue(Vector2F.AreNumericallyEqual(c.Point3, c.GetPoint(1)));
            Assert.IsTrue(Vector2F.AreNumericallyEqual(h.GetPoint(0.33f), c.GetPoint(0.33f)));
        }
コード例 #10
0
        public void GetTangent()
        {
            CardinalSegment2F c = new CardinalSegment2F
              {
            Point1 = new Vector2F(1, 2),
            Point2 = new Vector2F(10, 3),
            Point3 = new Vector2F(7, 8),
            Point4 = new Vector2F(10, 2),
            Tension = 0.3f
              };

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

              Assert.IsTrue(Vector2F.AreNumericallyEqual(h.Tangent1, c.GetTangent(0)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(h.Tangent2, c.GetTangent(1)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(h.GetTangent(0.7f), c.GetTangent(0.7f)));
        }