/* * FitCurve : * Fit a Bezier curve to a set of digitized points */ void FitCurve(Point2 *d, int nPts, double error) /* Array of digitized points */ /* Number of digitized points */ /* User-defined error squared */ { Vector2 tHat1, tHat2; /* Unit tangent vectors at endpoints */ tHat1 = ComputeLeftTangent(d, 0); tHat2 = ComputeRightTangent(d, nPts - 1); FitCubic(d, 0, nPts - 1, tHat1, tHat2, error); }
/* * FitCurve : * Fit a Bezier curve to a set of digitized points */ void CBCStroke::FitCurve( DISCURVE& d, /* Array of digitized points */ int nPts, /* Number of digitized points */ double error) /* User-defined error squared */ { Vector2 tHat1, tHat2; /* Unit tangent vectors at endpoints */ tHat1 = ComputeLeftTangent(d, 0); tHat2 = ComputeRightTangent(d, nPts - 1); FitCubic(d, 0, nPts - 1, tHat1, tHat2, error); }
/* * FitCurve : * Fit a Bezier curve to a set of digitized points */ BezierContour FitCurve(PointContour &contour, double error) { Vector2 tHat1, tHat2; /* Unit tangent vectors at endpoints */ PointContour::iterator iter; BezierContour bezContour; int i = 0; int nPts = contour.size(); Point2 *d = (Point2 *)malloc(nPts * sizeof(Point2)); for (iter = contour.begin(); iter != contour.end(); ++iter) { Point2 a; a.x = (*iter)[0]; a.y = (*iter)[1]; d[i++] = a; } tHat1 = ComputeLeftTangent(d, 0); tHat2 = ComputeRightTangent(d, nPts - 1); FitCubic(d, 0, nPts - 1, tHat1, tHat2, error, bezContour); free(d); return bezContour; }
QPainterPath bezierFit(const QList<QPointF> &points,float error){ FitVector tHat1, tHat2; tHat1 = ComputeLeftTangent(points,0); tHat2 = ComputeRightTangent(points,points.count()-1); int width=0; QPointF *curve; curve = FitCubic(points,0,points.count()-1,tHat1,tHat2,error,width); QPainterPath path; if(width>3){ path.moveTo(curve[0]); path.cubicTo(curve[1],curve[2],curve[3]); for(int i=4;i<width;i+=4){ path.cubicTo(curve[i+1],curve[i+2],curve[i+3]); } } delete[] curve; return path; }