chronophile

04-07-2010, 12:49 AM

Hi there. I'm working on a assignment for evaluating lagrange curves. I have a small error in my lagrange function that I can't seem to notice. The t value is the number of divisions from a range [0,1] used to draw the curve. The error is creating long straight lines with big values at the last few partitions. I may be confused with the meanings of t, t_i, t_j or its an iteration error, either way I don't think it would be hard to spot...

heres the formula

http://graphics.ucmerced.edu/~mkallmann/cse170/lectures/L18-lagrange.pdf (in the 5th page)

heres my function and my main loop in the main source file:

Vec eval_lagrange ( float t, float partitions, std::vector<Vec>& pnts ){

Vec *V = new Vec(0,0,0);

float n = (float)pnts.size();

float t_i = 0;

float t_j = 0;

float result = 1;

for(float i = 0; i < n; i++){

result = 1;

for(float j = 0; j < n; j++ ){

if(i != j){

t_i = i*partitions;

t_j = j*partitions;

result *= (t - t_j)/(t_i - t_j);

}

}

V->x += pnts[i].x*result;

V->y += pnts[i].y*result;

}

return *V;

}

POLYEDAPP.CPP

float delta = 1.0/10;

std::vector<Vec> curve_points;

for(int i = 0; i <= 10; i++){

float t = (float)i*delta;

// curve_points.push_back(eval_bezier (t, p));

curve_points.push_back(eval_lagrange (t, delta, p));

}

Any ideas?

thanks,

Will

heres the formula

http://graphics.ucmerced.edu/~mkallmann/cse170/lectures/L18-lagrange.pdf (in the 5th page)

heres my function and my main loop in the main source file:

Vec eval_lagrange ( float t, float partitions, std::vector<Vec>& pnts ){

Vec *V = new Vec(0,0,0);

float n = (float)pnts.size();

float t_i = 0;

float t_j = 0;

float result = 1;

for(float i = 0; i < n; i++){

result = 1;

for(float j = 0; j < n; j++ ){

if(i != j){

t_i = i*partitions;

t_j = j*partitions;

result *= (t - t_j)/(t_i - t_j);

}

}

V->x += pnts[i].x*result;

V->y += pnts[i].y*result;

}

return *V;

}

POLYEDAPP.CPP

float delta = 1.0/10;

std::vector<Vec> curve_points;

for(int i = 0; i <= 10; i++){

float t = (float)i*delta;

// curve_points.push_back(eval_bezier (t, p));

curve_points.push_back(eval_lagrange (t, delta, p));

}

Any ideas?

thanks,

Will