public void GetLength() { BezierSegment3F b = new BezierSegment3F { Point1 = new Vector3F(1, 2, 3), ControlPoint1 = new Vector3F(4, 5, 6), ControlPoint2 = new Vector3F(7, 8, 19), Point2 = new Vector3F(10, 2, 12), }; 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() { BezierSegment3F b = new BezierSegment3F { Point1 = new Vector3(1, 2, 3), ControlPoint1 = new Vector3(10, 3, 6), ControlPoint2 = new Vector3(7, 8, 19), Point2 = new Vector3(10, 2, 12), }; Assert.IsTrue(Vector3.AreNumericallyEqual(b.Point1, b.GetPoint(0))); Assert.IsTrue(Vector3.AreNumericallyEqual(b.Point2, b.GetPoint(1))); }
public void GetPoint() { BezierSegment3F b = new BezierSegment3F { Point1 = new Vector3F(1, 2, 3), ControlPoint1 = new Vector3F(10, 3, 6), ControlPoint2 = new Vector3F(7, 8, 19), Point2 = new Vector3F(10, 2, 12), }; Assert.IsTrue(Vector3F.AreNumericallyEqual(b.Point1, b.GetPoint(0))); Assert.IsTrue(Vector3F.AreNumericallyEqual(b.Point2, b.GetPoint(1))); }
public void GetLength() { BezierSegment3F b = new BezierSegment3F { Point1 = new Vector3(1, 2, 3), ControlPoint1 = new Vector3(4, 5, 6), ControlPoint2 = new Vector3(7, 8, 19), Point2 = new Vector3(10, 2, 12), }; 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() { HermiteSegment3F s = new HermiteSegment3F { Point1 = new Vector3F(1, 2, 3), Tangent1 = (new Vector3F(10, 3, 6) - new Vector3F(1, 2, 3)) * 3, Tangent2 = (new Vector3F(10, 2, 12) - new Vector3F(7, 8, 19)) * 3, Point2 = new Vector3F(10, 2, 12), }; BezierSegment3F b = new BezierSegment3F { Point1 = new Vector3F(1, 2, 3), ControlPoint1 = new Vector3F(10, 3, 6), ControlPoint2 = new Vector3F(7, 8, 19), Point2 = new Vector3F(10, 2, 12), }; Assert.IsTrue(Vector3F.AreNumericallyEqual(s.Point1, s.GetPoint(0))); Assert.IsTrue(Vector3F.AreNumericallyEqual(s.Point2, s.GetPoint(1))); Assert.IsTrue(Vector3F.AreNumericallyEqual(b.GetPoint(0.33f), s.GetPoint(0.33f))); }