PDA

View Full Version : Interpolation points of a fitted curve



pkj
22nd February 2011, 06:05
What I wish to do: Find the intersection of the fitted curve with another curve(which happens to be a straight line.
How:
1. Get Curve Points
QwtSplineCurveFitter *fit = static_cast<QwtSplineCurveFitter *>(orgnlCrv->curveFitter()); ///find curve Fitter
int div = fit->splineSize();//find spline size of curve fitter
QwtSplineCurveFitter fit2;//create a local curve fitter object
fit2.setSplineSize(div); //set spline size to that of orginal curve
fit2.setFitMode(QwtSplineCurveFitter::Spline);//specify type of fit mode

QPolygonF crvPt, d_pt; //d_pt has data points of original curve
populateD_pt(); //utility function which populates d_pt
crvPt= fit2.fitCurve(d_pt); //

2. Make a QList of QlineF with crvPt //crvPt[i] and crvPt{i+1], iterate i
3.Use intersect method of QLineF with each of segments of original curve with the second curve. Find the intersection pt.

Problem QPolygonF crvPt has integer values! The resulting intersection point is at integers on graph.

Right now I assume linear interpolation between two data points of original curve, but the intersection point I get with this assumption is not exact obviously! It would be great if i can get the exact intersection point with the original curve.

Uwe
22nd February 2011, 20:31
Problem QPolygonF crvPt has integer values!
Which points are the integers - the values you pass into the interpolation or those, that you get ?

Note, that Qwt is open source. The spline interpolation is not much code and you should be able to debug and understand what is going on quite easily.

Uwe

pkj
23rd February 2011, 05:24
Thanks Uwe.
Btw, the values i pass to interpolation are double values and the values i get by interpolation are integers.
I went through QPolygonF QwtSplineCurveFitter::fitSpline( const QPolygonF &points ) const function in qwt_curve_fitter file as you suggested. There while returning the values you round it up to integers. If we use the curve fitter for very small values, it shows steps for perhaps the same reason.

Round about method I now use:
I scale up the values(multiply by say 1000) get the interpolation points, and scale it back...

Uwe
23rd February 2011, 07:29
Indeed - this rounding seems to be left from Qwt4/Qt3 days, where the spline interpolation was used inside of the curve painting code only and Qt had no double based QPainter API. So rounding to integers was merged into the interpolation code for performance reasons - to avoid an additional pass.

When the spline interpolation is used for painting only you won't notice this bug because Qwt5 and Qt internally round the values to integers anyway. But with the modified ( double based ) render engine of Qwt 6 you would see the bug, when rendering f.e. to PDF.

Fixed in trunk and the 5.2 branch.

Thanks for reporting,
Uwe