de castlejau algorithm

Im trying to implement de castlejau algorithm and ran into a propblem and really don't know how to fix.

I searched all over the web for help but couldn't find anything similar to this..


the following is the 2 method that are used to implement the algorithm ,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
 * Render the interpolated points and the edges between them 
 * for each stage of the de casteljau algorithm. Colour each final
 * point (the points on the curve) differently.
 */
void GLWidget::drawDeCasteljau(float t) {
    
    Point p;
    int N_PTS = 4;
    
    p.x = pow((1-t),3)*vertices[0].x+3* t * pow((1 -t), 2) * vertices[1].x + 3 * (1-t)*pow(t,2)*vertices[2].x+ pow (t, 3)*vertices[3].x;
    p.y = pow((1-t),3)*vertices[0].y+3* t * pow((1 -t), 2) * vertices[1].y + 3 * (1-t)*pow(t,2)*vertices[2].y+ pow (t, 3)*vertices[3].y;
    p.z = pow((1-t),3)*vertices[0].z+3* t * pow((1 -t), 2) * vertices[1].z + 3 * (1-t)*pow(t,2)*vertices[2].z+ pow (t, 3)*vertices[3].z;
    
    int bezPoints[3][3] ;
    

    
    for (float u = 0.0; u <= 1.0; u += t) {
        for (int diag = N_PTS-2; diag >= 0; diag--) {
            for (int i = 0; i <= diag; i++) {
                int j = diag - i;
                bezPoints[i][j] = (1.0-u)*bezPoints[i][j+1] + u*bezPoints[i+1][j];
            }
        }
        // set the pixel for this parameter value

//Set pixel method for theImage object.
//        void setPixel(Index row, Index col, Byte red, Byte green, Byte blue, Byte alpha=255);
//        void setPixel(Index row, Index col, RGBValue colour, Byte alpha = 255);
                theImage.setPixel(bezPoints[0][0], bezPoints[0][0], RGBValue());

    }
    
}
void GLWidget::drawBezierCurve() {
	
}




Any help will be appreciated
Last edited on
OMG... such a complicated....
I don't even know about this algorithm.. :'(
and ran into a propblem and really don't know how to fix.


.... and that problem is?
its not displaying the curved line as it should , instead its not doing anything.
I don't know that algorithm, but I see:
1) in line 23 you used variable bezPoints, which is not initialized
2) in line 31, I suspect the argument you passed to setPixel are wrong
Topic archived. No new replies allowed.