I've created a set of control points, and have used cubic interpolation to fit a curve to it. You can see the result here:
As is clear in the image, the 'curve' isn't very curvy. There are some sharp turns at some of the control points.
(Where the red points are the endpoints of the curve).
This is how I render the lines (Java btw);
for ( int i=1; i<cs.size()-2; i++ )
for ( double u=0.0; u<=0.9; u+=0.1 )
int x = cs.x( i, u ) ;
int y = cs.y( i, u ) ;
int x2 = cs.x( i, u+0.1 ) ;
int y2 = cs.y( i, u+0.1 ) ;
g.drawLine( x, y, x2, y2 ) ;
Where the 'cs' instance merely wraps round an ArrayList, and the x() and y() methods are:
public int y( int i, double x )
int P0, P1, P2, P3 ;
P0 = get( i-1 ).y ;
P1 = get( i ).y ;
P2 = get( i+1 ).y ;
P3 = get( i+2 ).y ;
int P = (P3 - P2) - (P0 - P1) ;
int Q = (P0 - P1) - P ;
int R = P2 - P0 ;
int S = P1 ;
return (int ) (P*x*x*x + Q*x*x + R*x + S) ;
public int x( int i, double x )
return (int ) (get( i ).x + x * (get( i+1 ).x-get( i ).x) ) ;
And the get(int i) method returns a Point instance of the control point 'i'.
Can anyone spot a problem?
Why is it not c-u-r-v-y ?