Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Welcome Guest | Log In | Register | Benefits
Channels ▼
RSS

Forward Difference Calculation of Bezier Curves


November 1997/Forward Difference Calculation of Bezier Curves/Listing 1

Listing 1: Computing a cubic polynomial and its forward differences

...

int i;
double a, b, c, d, t0, h, t, p;
double points[NUM_STEPS], col3[NUM_STEPS - 1]; 
double col4[NUM_STEPS - 2], col5[NUM_STEPS - 3];
double firstFD, secondFD, thirdFD;

    /*    Set up coefficients, step size, etc. */

a = 3.0;
b = -2.0;
c = 1.0;
d = 4.0;

t0 = 0.0;
h = 0.1;

    /*    Compute polynomial points */

for (i = 0; i < NUM_STEPS; i++) {
    t = t0 + (double)i * h;
    p = a * t * t * t + b * t * t + c * t + d;
    points[i] = p;
}

    /*    Compute colums 3, 4, and 5 */

for (i = 0; i < NUM_STEPS - 1; i++) {
    col3[i] = points[i + 1] - points[i];
}
for (i = 0; i < NUM_STEPS - 2; i++) {
    col4[i] = col3[i + 1] - col3[i];
}
for (i = 0; i < NUM_STEPS - 3; i++) {
    col5[i] = col4[i + 1] - col4[i];
}

...
/* End of File */

Related Reading


More Insights