To determine the first cubic Bezier segment we could set its two terminal
control points and tangents. Then the second segment is determined by the first point,
two derivatives (continuous at the point) and the second control point.
All the rest segments are determined in a similar way.
It is more convinient to set terminal tangents of the whole spline curve. Fig.1' shows, that all Bezier control points of the curve are evaluated from two vectors (P0 , P1 , ... , Pn ) and (d0 , d1 , ... , dn ). Points (P0 , P1 , ... , Pn ), d0 , dn are set by user and d1 , d2 , ... , dn-1 are calculated. |
move add delete |
It is programmed as (b-interpolate.js)
function findCPoints(){ Bi[1] = -.25; Ax[1] = (Px[2] - Px[0] - dx[0])/4; Ay[1] = (Py[2] - Py[0] - dy[0])/4; for (var i = 2; i < N-1; i++){ Bi[i] = -1/(4 + Bi[i-1]); Ax[i] = -(Px[i+1] - Px[i-1] - Ax[i-1])*Bi[i]; Ay[i] = -(Py[i+1] - Py[i-1] - Ay[i-1])*Bi[i]; } for (var i = N-2; i > 0; i--){ dx[i] = Ax[i] + dx[i+1]*Bi[i]; dy[i] = Ay[i] + dy[i+1]*Bi[i]; } }
move add delete |