0
 GsVec curve_eval::eval_lagrange(float t, float numberofsegmentsn, const GsArray<GsVec>& ctrlpnts) //f(t) = sum of p.i * B.i(t)
 {  
//float interval = 1 / numberofsegmentsn; //so if 4, then 0.25
float interval = 1 / ctrlpnts.size(); 

//remember that for interval that is put in above, it's based on numbers of ctrlpnts

//for lagrange, let t 
GsVec ft(0.0f, 0.0f, 0.0f);
int sizeofctrlpnts = ctrlpnts.size();
float result = 0;   
std::cout << "interval = " << interval << "  \\ number of segments = " << numberofsegmentsn << " \\ ctrlpnts.size() = " << ctrlpnts.size() << "\n";

float tt = 0;
float ti[50] = { 0 }; 
float tj[50] = { 0 }; //only this might be used
for (int x = 0; x < ctrlpnts.size(); x++) //changed from 'numberofsegmentsn'
{
    tj[x] = tt;//
    std::cout << "tt in tj[" << x << "]= " << tt <<  "\n";
    tt = tt + interval;

}

float tb = 1;
tt = 1;
int i = 0;
for (int i = 0; i < ctrlpnts.size(); i ++)
{
    tt = 1;
    tb = 1;
    for (int j = 0; j < ctrlpnts.size(); j++) // 
    {           
        if (i != j)
        {
            std::cout << "Before cal: i = " << i << " :: j = " << j << " :: tt = " << tt << " :: tb = " << tb << " :: t = " << t << " :: tj[i" << j << "] = " << tj[j] << " :: tj[j" << i << "] = " << tj[i] << "\n";

            tt = (t - tj[j]) * tt;
            tb = (tj[i] - tj[j])* tb;

            std::cout << "After cal: tt = " << tt << " :: tb = " << tb << "\n";
        }
        //t gotta change
    }
    result = tt / tb;
    ft = ft+(ctrlpnts[i]*result);
}

return ft;

Above is my written algorithm for Lagrange function for opengl.

Following link is the screenshot of the formula that i had to impliment, https://i.stack.imgur.com/0JJ36.jpg.

I have been tweaking it for awhile, and i can't seem to find what is wrong with it.

HolyMeow
  • 19
  • 6
  • 1
    A how, how, how, how are we supposed to help if you don't say what is going wrong? Is it not compiling? Not producing the right answers? Please add the incorrect output and the desired output. – The Dark Nov 06 '15 at 01:06
  • Also `1 / ctrlpnts.size()` is `0` due to integer rounding, use `1.0 / ctrlpnts.size()`. This might be your problem, but now I might be mistaken – The Dark Nov 06 '15 at 01:22
  • That's not exactly well structured code, and that may well be the cause both for a bug tunneling itself the code and for your difficulties to spot it. the b_i(t) of the parametric form literally cries for a function for, even better, a [functor](http://stackoverflow.com/questions/356950/c-functors-and-their-uses) which holds the parametrization gathered from the sample as internal state. – decltype_auto Nov 06 '15 at 01:39

0 Answers0