/// <summary>
 /// 要求的:N+1 = curveParam.PointList.Count;
 /// 要求的:  k = curveParam.Degree;
 ///   k = i
 ///   i = j
 ///                  t - t[j]                              t[i + j + 1] - t
 /// N[i, j](t) = ----------------- * N[i - 1, j](t) + ------------------------- * N[i - 1, j + 1](t)
 ///               t[i + j] - t[j]                      t[i + j + 1] - t[j + 1]
 ///               numerator11 * t + numerator10                      numerator21 * t + numerator20
 ///            = ------------------------------- * N[i - 1, j](t) + ------------------------------- * N[i - 1, j + 1](t)
 ///                      denominator10                                       denominator20
 /// numerator11   = 1
 /// numerator10   = -t[j]
 /// numerator21   = -1
 /// numerator20   = t[i + j + 1]
 /// denominator10 = t[i + j] - t[j]
 /// denominator20 = t[i + j + 1] - t[j + 1]
 /// </summary>
 /// <param name="curveParam"></param>
 /// <returns></returns>
 protected virtual void calculateBasisFunction(ICurveParam curveParam)
 {
     if (curveParam.getCurveType() == InterpolationCurveType.bsCurve)
     {
         BSplineCurveParam param = (BSplineCurveParam)curveParam;
         Dynamic2DArray<PiecewiseIntervalPolynomialCurveElement> basisFunctions = new Dynamic2DArray<PiecewiseIntervalPolynomialCurveElement>();
         int total = param.Degree + param.PointList.Count;
         DoubleExtension denominator10, denominator20, numerator11, numerator10, numerator21, numerator20;
         PiecewiseIntervalPolynomialCurveElement curve1, curve2;
         numerator11 = new DoubleExtension(1);
         numerator21 = new DoubleExtension(-1);
         for (int i = 0; i < total; i++)
         {
             basisFunctions.SetArrayElement(0, i, new PiecewiseIntervalPolynomialCurveElement(i, param.Interval));
         }
         for (int i = 1; i <= param.Degree; i++)
         {
             for (int j = 0; j < total - i; j++)
             {
                 denominator10 = param.Interval.CutPoints[i + j] - param.Interval.CutPoints[j];
                 denominator20 = param.Interval.CutPoints[i + j + 1] - param.Interval.CutPoints[j + 1];
                 numerator10 = 0 - param.Interval.CutPoints[j];
                 numerator20 = param.Interval.CutPoints[i + j + 1];
                 curve1 = basisFunctions.GetArrayElement(i - 1, j).DivideByNumber(denominator10).MultiplyByLinear(numerator11, numerator10);
                 curve2 = basisFunctions.GetArrayElement(i - 1, j + 1).DivideByNumber(denominator20).MultiplyByLinear(numerator21, numerator20);
                 basisFunctions.SetArrayElement(i, j, curve1 + curve2);
             }
         }
         this.basisFunctions = basisFunctions[param.Degree];
     }
     else
     {
         throw new UnmatchedCurveParamTypeException(InterpolationCurveType.bsCurve, curveParam.getCurveType());
     }
 }
Exemplo n.º 2
0
 public BezierCurve(ICurveParam curveParam)
 {
     if (canDrawCurve(curveParam))
     {
         canDraw = true;
         this.curveParam = (BezierCurveParam)curveParam;
     }
 }
 public CubicSplineInterpolationCurve(ICurveParam curveParam)
 {
     if (canDrawCurve(curveParam))
     {
         canDraw = true;
         this.curveParam = (CubicSplineInterpolationCurveParam)curveParam;
     }
 }
Exemplo n.º 4
0
 public PolynomialCurve(ICurveParam curveParam)
 {
     if (canDrawCurve(curveParam))
     {
         canDraw = true;
         this.curveParam = (PolynomialCurveParam)curveParam;
     }
 }
Exemplo n.º 5
0
 public NurbsCurve(ICurveParam curveParam)
 {
     if (canDrawCurve(curveParam))
     {
         canDraw = true;
         this.curveParam = (NurbsCurveParam)curveParam;
     }
 }
Exemplo n.º 6
0
 public BSplineCurve(ICurveParam curveParam)
 {
     if (canDrawCurve(curveParam))
     {
         canDraw = true;
         this.curveParam = (BSplineCurveParam)curveParam;
     }
 }
 protected virtual void InitialCurve(ICurveParam curveParam)
 {
     if (curveParam.getCurveType() == InterpolationCurveType.bsCurve)
     {
         BSplineCurveParam param = (BSplineCurveParam)curveParam;
         this.curve = new BSplineParametricCurveElement(param);
     }
     else
     {
         throw new UnmatchedCurveParamTypeException(InterpolationCurveType.bsCurve, curveParam.getCurveType());
     }
 }
 protected override void InitialCurve(ICurveParam curveParam)
 {
     if (curveParam.getCurveType() == InterpolationCurveType.nurbsCurve)
     {
         NurbsCurveParam param = (NurbsCurveParam)curveParam;
         this.curve = new NurbsParametricCurveElement(param);
     }
     else
     {
         throw new UnmatchedCurveParamTypeException(InterpolationCurveType.nurbsCurve, curveParam.getCurveType());
     }
 }
Exemplo n.º 9
0
 private bool canDrawCurve(ICurveParam curveParam)
 {
     if (curveParam.getCurveType() == InterpolationCurveType.bezierCurve)
     {
         BezierCurveParam param = (BezierCurveParam)curveParam;
         if (param.Count < 2)
             throw new InvalidBasePointsException(InterpolationCurveType.bezierCurve, "At least two points are needed to draw Bezier Curve");
     }
     else
     {
         throw new UnmatchedCurveParamTypeException(InterpolationCurveType.bezierCurve, curveParam.getCurveType());
     }
     return true;
 }
 private bool canDrawCurve(ICurveParam curveParam)
 {
     if (curveParam.getCurveType() == InterpolationCurveType.csiCurve)
     {
         CubicSplineInterpolationCurveParam param = (CubicSplineInterpolationCurveParam)curveParam;
         if (param.Count < 2)
             throw new InvalidBasePointsException(InterpolationCurveType.csiCurve, "At least two points are needed to draw Cubic Spline Interpolation Curve");
         if (!param.PointList.NoDuplicatedX())
             throw new InvalidBasePointsException(InterpolationCurveType.csiCurve, "At least two points given have the same X value.");
     }
     else
     {
         throw new UnmatchedCurveParamTypeException(InterpolationCurveType.csiCurve, curveParam.getCurveType());
     }
     return true;
 }
Exemplo n.º 11
0
 private bool canDrawCurve(ICurveParam curveParam)
 {
     if (curveParam.getCurveType() == InterpolationCurveType.nurbsCurve)
     {
         NurbsCurveParam param = (NurbsCurveParam)curveParam;
         if (param.Count <= param.Degree)
             throw new InvalidBasePointsException(InterpolationCurveType.nurbsCurve, (param.Degree - param.Count + 1).ToString() + " more data points are needed to draw NURBS Curve");
         if (param.Interval.CutPoints[param.Degree] == param.Interval.CutPoints[param.PointList.Count])
             throw new InvalidBasePointsException(InterpolationCurveType.bsCurve, "The degree is too high or the base points are insufficient or too many duplicated nodes are specified.");
     }
     else
     {
         throw new UnmatchedCurveParamTypeException(InterpolationCurveType.nurbsCurve, curveParam.getCurveType());
     }
     return true;
 }