Пример #1
0
        public void GetLength()
        {
            BezierSegment2F b = new BezierSegment2F
              {
            Point1 = new Vector2F(1, 2),
            ControlPoint1 = new Vector2F(4, 5),
            ControlPoint2 = new Vector2F(7, 8),
            Point2 = new Vector2F(10, 2),
              };

              float lowerBound = (b.Point2 - b.Point1).Length;
              float upperBound = (b.Point2 - b.ControlPoint2).Length
                         + (b.ControlPoint2 - b.ControlPoint1).Length
                         + (b.ControlPoint1 - b.Point1).Length;
              Assert.Less(lowerBound, b.GetLength(0, 1, 100, Numeric.EpsilonF));
              Assert.Greater(upperBound, b.GetLength(0, 1, 100, Numeric.EpsilonF));

              float length1 = b.GetLength(0, 1, 20, Numeric.EpsilonF);
              float length2 = b.GetLengthWithDeCasteljau(20, Numeric.EpsilonF);

              Assert.IsTrue(Numeric.AreEqual(length1, length2));
              // Compare numerical integration method and de Casteljau method.

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

              Assert.IsTrue(Numeric.AreEqual(approxLength, length1, 0.01f));
              Assert.IsTrue(Numeric.AreEqual(b.GetLength(0, 1, 100, Numeric.EpsilonF), b.GetLength(0, 0.5f, 100, Numeric.EpsilonF) + b.GetLength(0.5f, 1, 100, Numeric.EpsilonF)));
              Assert.IsTrue(Numeric.AreEqual(b.GetLength(0, 1, 100, Numeric.EpsilonF), b.GetLength(1, 0, 100, Numeric.EpsilonF)));
        }
Пример #2
0
        public void GetPoint()
        {
            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(b.Point1, b.GetPoint(0)));
            Assert.IsTrue(Vector2F.AreNumericallyEqual(b.Point2, b.GetPoint(1)));
        }
Пример #3
0
        public void GetPoint()
        {
            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(b.Point1, b.GetPoint(0)));
              Assert.IsTrue(Vector2F.AreNumericallyEqual(b.Point2, b.GetPoint(1)));
        }
Пример #4
0
        public void GetLength()
        {
            BezierSegment2F b = new BezierSegment2F
            {
                Point1        = new Vector2F(1, 2),
                ControlPoint1 = new Vector2F(4, 5),
                ControlPoint2 = new Vector2F(7, 8),
                Point2        = new Vector2F(10, 2),
            };

            float lowerBound = (b.Point2 - b.Point1).Length;
            float upperBound = (b.Point2 - b.ControlPoint2).Length
                               + (b.ControlPoint2 - b.ControlPoint1).Length
                               + (b.ControlPoint1 - b.Point1).Length;

            Assert.Less(lowerBound, b.GetLength(0, 1, 100, Numeric.EpsilonF));
            Assert.Greater(upperBound, b.GetLength(0, 1, 100, Numeric.EpsilonF));

            float length1 = b.GetLength(0, 1, 20, Numeric.EpsilonF);
            float length2 = b.GetLengthWithDeCasteljau(20, Numeric.EpsilonF);

            Assert.IsTrue(Numeric.AreEqual(length1, length2));
            // Compare numerical integration method and de Casteljau method.

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

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

            Assert.IsTrue(Numeric.AreEqual(approxLength, length1, 0.01f));
            Assert.IsTrue(Numeric.AreEqual(b.GetLength(0, 1, 100, Numeric.EpsilonF), b.GetLength(0, 0.5f, 100, Numeric.EpsilonF) + b.GetLength(0.5f, 1, 100, Numeric.EpsilonF)));
            Assert.IsTrue(Numeric.AreEqual(b.GetLength(0, 1, 100, Numeric.EpsilonF), b.GetLength(1, 0, 100, Numeric.EpsilonF)));
        }
        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)));
        }
Пример #6
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)));
        }