/// <summary> /// Computes the knot vectors used to calculate a curve global interpolation. /// </summary> private static KnotVector ComputeKnotsForInterpolation(List <double> curveParameters, int degree, bool hasTangents) { // Start knot vectors. KnotVector knots = CollectionHelpers.RepeatData(0.0, degree + 1).ToKnot(); // If we have tangent values we need two more control points and knots. int start = (hasTangents) ? 0 : 1; int end = (hasTangents) ? curveParameters.Count - degree + 1 : curveParameters.Count - degree; // Use averaging method (Eqn 9.8) to compute internal knots in the knot vector. for (int i = start; i < end; i++) { double weightSum = 0.0; for (int j = 0; j < degree; j++) { weightSum += curveParameters[i + j]; } knots.Add((1.0 / degree) * weightSum); } // Add end knot vectors. knots.AddRange(CollectionHelpers.RepeatData(1.0, degree + 1)); return(knots); }
/// <summary> /// Computes the knots vectors used to calculate an approximate curve. /// </summary> private static KnotVector ComputeKnotsForCurveApproximation(List <double> curveParameters, int degree, int numberOfCtrPts, int numberOfPts) { // Start knot vectors. KnotVector knots = CollectionHelpers.RepeatData(0.0, degree + 1).ToKnot(); // Compute 'd' value - Eqn 9.68. double d = (double)numberOfPts / (numberOfCtrPts - degree); // Find the internal knots - Eqn 9.69. for (int j = 1; j < numberOfCtrPts - degree; j++) { int i = (int)(j * d); double alpha = (j * d) - i; double knot = ((1.0 - alpha) * curveParameters[i - 1]) + (alpha * curveParameters[i]); knots.Add(knot); } // Add end knot vectors. knots.AddRange(CollectionHelpers.RepeatData(1.0, degree + 1)); return(knots); }