Exemplo n.º 1
0
        public void It_Returns_The_Tangent_At_Given_Parameter(double t, double[] tangentData)
        {
            // Arrange
            int           degree = 3;
            List <Point3> pts    = new List <Point3>
            {
                new (0, 0, 0),
                new (1, 0, 0),
                new (2, 0, 0),
                new (3, 0, 0),
                new (4, 0, 0)
            };
            List <double> weights = new List <double> {
                1, 1, 1, 1, 1
            };
            NurbsCurve curve = new NurbsCurve(pts, weights, degree);
            Vector3    tangentExpectedLinearCurve = new Vector3(1, 0, 0);
            Vector3    tangentExpectedPlanarCurve = new Vector3(tangentData[0], tangentData[1], tangentData[2]);

            // Act
            // Act on a linear nurbs curve.
            Vector3 tangentLinearCurve = curve.TangentAt(t);
            Vector3 tangentPlanarCurve = NurbsCurveCollection.PlanarCurveDegreeThree().TangentAt(t);

            // Assert
            (tangentLinearCurve == tangentExpectedLinearCurve).Should().BeTrue();
            tangentPlanarCurve.EpsilonEquals(tangentExpectedPlanarCurve, GSharkMath.MaxTolerance).Should().BeTrue();
        }
Exemplo n.º 2
0
        public void It_Returns_Parameter_At_The_Given_Length(double segmentLength, double tValueExpected)
        {
            // Arrange
            NurbsBase curve = NurbsCurveCollection.PlanarCurveDegreeThree();

            // Act
            double parameter = curve.ParameterAtLength(segmentLength);

            // Assert
            parameter.Should().BeApproximately(tValueExpected, GSharkMath.MinTolerance);
        }
Exemplo n.º 3
0
        public void It_Returns_The_Length_Of_The_Curve()
        {
            // Arrange
            NurbsBase curve          = NurbsCurveCollection.PlanarCurveDegreeThree();
            double    expectedLength = 50.334675;

            // Act
            double crvLength = curve.Length;

            // Assert
            crvLength.Should().BeApproximately(expectedLength, GSharkMath.MinTolerance);
        }
Exemplo n.º 4
0
        public void It_Returns_The_Closest_Point_And_Parameter(double[] ptToCheck, double[] ptExpected, double tValExpected)
        {
            // Arrange
            NurbsBase curve      = NurbsCurveCollection.PlanarCurveDegreeThree();
            Point3    testPt     = new Point3(ptToCheck[0], ptToCheck[1], ptToCheck[2]);
            Point3    expectedPt = new Point3(ptExpected[0], ptExpected[1], ptExpected[2]);

            // Act
            Point3 pt        = curve.ClosestPoint(testPt);
            double parameter = curve.ClosestParameter(testPt);

            // Assert
            parameter.Should().BeApproximately(tValExpected, GSharkMath.MaxTolerance);
            pt.EpsilonEquals(expectedPt, GSharkMath.MaxTolerance).Should().BeTrue();
        }
Exemplo n.º 5
0
        public void It_Returns_Parameter_At_The_Given_Length_Of_A_Bezier()
        {
            // Arrange
            NurbsBase curve = NurbsCurveCollection.PlanarCurveDegreeThree();

            double[] tValuesExpected = new[] { 0, 0.122941, 0.265156, 0.420293, 0.579707, 0.734844, 0.877059, 1 };

            int    steps      = 7;
            double length     = curve.Length / steps;
            double sumLengths = 0.0;

            for (int i = 0; i < steps + 1; i++)
            {
                // Act
                double t             = curve.ParameterAtLength(sumLengths);
                double segmentLength = curve.LengthAt(t);

                // Assert
                t.Should().BeApproximately(tValuesExpected[i], GSharkMath.MaxTolerance);
                segmentLength.Should().BeApproximately(sumLengths, GSharkMath.MaxTolerance);

                sumLengths += length;
            }
        }