Smooth interpolation using Path::cubicTo


#1

Hello!

I’d like to do some polynomial interpolation and I have found the cubicTo and quadraticTo methods which seem to do exactly what I need. Only thing is, I do not know how to set the controlPoints… Is there an easy way to do it? :stuck_out_tongue: Or do I have to dig into the maths of Catmul-Rom and Cardinal splines? :shock:

Any hints much appreciated!


#2

This might be an example of using Path.quadraticTo() to draw a curve through three given points.
Given that array “dataPoints” contains your data points:

[code]Path curve;

//in iteration

x1 = Point( dataPoints[i] ).getX();
y1 = Point( dataPoints[i] ).getY();
// next
x2 = Point( dataPoints[i+1] ).getX();
y2 = Point( dataPoints[i+1] ).getY();

x3 = Point( dataPoints[i+2] ).getX();
y3 = Point( dataPoints[i+2] ).getY();

// since you need the curve to go through all your three points, you calculate appropriate control point
cpX = 2 * x2 - 0.5 * ( x1 + x3 );
cpY = 2 * y2 - 0.5 * ( y1 + y3 );

curve.startNewSubPath( x1, y1 );
curve.quadraticTo( cpX, cpY, x3, y3 );

//in iteration
[/code]

or something similar …