public void It_Returns_A_Curve_Where_Degree_Is_Reduced_From_5_To_4() { // Arrange // Followed example Under C1 constrain condition https://www.hindawi.com/journals/mpe/2016/8140427/tab1/ List <Point3> pts = new List <Point3> { new Point3(-5.0, 0.0, 0.0), new Point3(-7.0, 2.0, 0.0), new Point3(-3.0, 5.0, 0.0), new Point3(2.0, 6.0, 0.0), new Point3(5.0, 3.0, 0.0), new Point3(3.0, 0.0, 0.0) }; int degree = 5; double tolerance = 10e-2; NurbsCurve curve = new NurbsCurve(pts, degree); Point3 ptOnCurve0 = curve.PointAt(0.5); Point3 ptOnCurve1 = curve.PointAt(0.25); // Act NurbsBase reducedCurve = curve.ReduceDegree(tolerance); Point3 ptOnReducedDegreeCurve0 = reducedCurve.PointAt(0.5); Point3 ptOnReducedDegreeCurve1 = reducedCurve.PointAt(0.25); // Assert reducedCurve.Degree.Should().Be(degree - 1); ptOnCurve0.DistanceTo(ptOnReducedDegreeCurve0).Should().BeLessThan(GSharkMath.MinTolerance); ptOnCurve1.DistanceTo(ptOnReducedDegreeCurve1).Should().BeLessThan(tolerance); }
/// <summary> /// Samples a curve at equally spaced parametric intervals. /// </summary> /// <param name="curve">The curve object.</param> /// <param name="numSamples">Number of samples.</param> /// <returns>A tuple with the set of points and the t parameter where the point was evaluated.</returns> internal static (List <double> tvalues, List <Point3> pts) RegularSample(NurbsBase curve, int numSamples) { if (numSamples < 1) { throw new Exception("Number of sample must be at least 1 and not negative."); } double start = curve.Knots[0]; double end = curve.Knots[curve.Knots.Count - 1]; double span = (end - start) / (numSamples - 1); List <Point3> pts = new List <Point3>(); List <double> tValues = new List <double>(); for (int i = 0; i < numSamples; i++) { double t = start + span * i; Point3 ptEval = curve.PointAt(t); pts.Add(ptEval); tValues.Add(t); } return(tValues, pts); }
public void It_Refines_The_Curve_Knot(double val, int insertion) { // Arrange int degree = 3; List <double> newKnots = new List <double>(); for (int i = 0; i < insertion; i++) { newKnots.Add(val); } List <Point3> pts = new List <Point3>(); for (int i = 0; i <= 12 - degree - 2; i++) { pts.Add(new Point3(i, 0.0, 0.0)); } NurbsCurve curve = new NurbsCurve(pts, degree); // Act NurbsBase curveAfterRefine = KnotVector.Refine(curve, newKnots); Point3 p0 = curve.PointAt(2.5); Point3 p1 = curveAfterRefine.PointAt(2.5); // Assert (curve.Knots.Count + insertion).Should().Be(curveAfterRefine.Knots.Count); (pts.Count + insertion).Should().Be(curveAfterRefine.ControlPointLocations.Count); (p0 == p1).Should().BeTrue(); }
public double Value(Vector v) { var p0 = _curve.PointAt(v[0]); var p1 = _plane.ClosestPoint(p0, out _); var p0P1 = p0 - p1; return(Vector3.DotProduct(p0P1, p0P1)); }
/// <summary> /// Refines an intersection pair for two curves given an initial guess.<br/> /// This is an unconstrained minimization, so the caller is responsible for providing a very good initial guess. /// </summary> /// <param name="crv0">The first curve.</param> /// <param name="crv1">The second curve.</param> /// <param name="firstGuess">The first guess parameter.</param> /// <param name="secondGuess">The second guess parameter.</param> /// <param name="tolerance">The value tolerance for the intersection.</param> /// <returns>The results collected into the object <see cref="CurvesIntersectionResult"/>.</returns> internal static CurvesIntersectionResult CurvesWithEstimation(NurbsBase crv0, NurbsBase crv1, double firstGuess, double secondGuess, double tolerance) { IObjectiveFunction objectiveFunctions = new CurvesIntersectionObjectives(crv0, crv1); Minimizer min = new Minimizer(objectiveFunctions); MinimizationResult solution = min.UnconstrainedMinimizer(new Vector { firstGuess, secondGuess }, tolerance * tolerance); // These are not the same points, also are used to filter where the intersection is not happening. Point3 pt1 = crv0.PointAt(solution.SolutionPoint[0]); Point3 pt2 = crv1.PointAt(solution.SolutionPoint[1]); return(new CurvesIntersectionResult(pt1, pt2, solution.SolutionPoint[0], solution.SolutionPoint[1])); }
public void Returns_The_Surface_Isocurve_At_V_Direction() { // Arrange NurbsSurface surface = NurbsSurfaceCollection.SurfaceFromPoints(); Point3 expectedPt = new Point3(5, 4.615385, 2.307692); Point3 expectedPtAt = new Point3(5, 3.913043, 1.695652); // Act NurbsBase Isocurve = surface.IsoCurve(0.3, SurfaceDirection.V); Point3 ptAt = Isocurve.PointAt(0.5); // Assert Isocurve.ControlPointLocations[1].DistanceTo(expectedPt).Should().BeLessThan(GSharkMath.MinTolerance); ptAt.DistanceTo(expectedPtAt).Should().BeLessThan(GSharkMath.MinTolerance); }
/// <summary> /// Refines an intersection between a curve and a plane given an initial guess.<br/> /// This is an unconstrained minimization, so the caller is responsible for providing a very good initial guess. /// </summary> /// <param name="crv">The curve to intersect.</param> /// <param name="plane">The plane to intersect with the curve.</param> /// <param name="firstGuess">The first guess parameter.</param> /// <param name="secondGuess">The second guess parameter.</param> /// <param name="tolerance">The value tolerance for the intersection.</param> /// <returns>The results collected into the object <see cref="CurvePlaneIntersectionResult"/>.</returns> internal static CurvePlaneIntersectionResult CurvePlaneWithEstimation(NurbsBase crv, Plane plane, double firstGuess, double secondGuess, double tolerance) { IObjectiveFunction objectiveFunctions = new CurvePlaneIntersectionObjectives(crv, plane); Minimizer min = new Minimizer(objectiveFunctions); MinimizationResult solution = min.UnconstrainedMinimizer(new Vector { firstGuess, secondGuess }, tolerance * tolerance); Point3 pt = crv.PointAt(solution.SolutionPoint[0]); (double u, double v)parameters = plane.ClosestParameters(pt); Vector uv = new Vector { parameters.u, parameters.v, 0.0 }; return(new CurvePlaneIntersectionResult(pt, solution.SolutionPoint[0], uv)); }
public void It_Returns_A_Curve_Where_Degree_Is_Elevated_From_1_To_Elevated_Degree_Value(int finalDegree) { // Arrange List <Point3> pts = new List <Point3> { new Point3(0.0, 0.0, 1.0), new Point3(7.0, 3.0, -10), new Point3(5.2, 5.2, -5), }; int degree = 1; NurbsCurve curve = new NurbsCurve(pts, degree); Point3 ptOnCurve = curve.PointAt(0.5); // Act NurbsBase elevatedDegreeCurve = curve.ElevateDegree(finalDegree); Point3 ptOnElevatedDegreeCurve = elevatedDegreeCurve.PointAt(0.5); // Assert elevatedDegreeCurve.Degree.Should().Be(finalDegree); ptOnElevatedDegreeCurve.DistanceTo(ptOnCurve).Should().BeLessThan(GSharkMath.MinTolerance); }