B-Splines in C++
<p>I'm trying to write a program to generate a curve in C++ to plot a B-Spline curve. This is what my code looks like.</p>

<pre><code>void drawBSplineCurve(vector&lt;point&gt; poly)
{
    int n, d;
    cout &lt;&lt; "Enter degree of curve: ";
    cin &gt;&gt; d;
    n = poly.size();
    vector&lt;double&gt; uVec;
    int i;
    for(i=0;i&lt;n+d;i++)
    {
        uVec.push_back(((double)i)/(n+d-1));
    }
    double x, y, basis, u;
    for(u=0;u&lt;=1;u+=0.0001)
    {
        x = 0;
        y = 0;
        for(i=0;i&lt;poly.size();i++)
        {
            basis = blend(uVec, u, i, d);
            x += basis*poly[i].x;
            y += basis*poly[i].y;
        }
        putpixel(roundOff(x), roundOff(y), YELLOW);
    }
}

double blend(vector&lt;double&gt; &amp;uVec, double u, int k, int d)
{
    if(d==1)
    {
        if(uVec[k]&lt;=u &amp;&amp; u&lt;uVec[k+1])
            return 1;
        return 0;
    }
    double b;
    b = ((u-uVec[k])/(uVec[k+d-1]-uVec[k])*blend(uVec, u, k, d-1)) + ((uVec[k+d]-u)/(uVec[k+d]-uVec[k+1])*blend(uVec, u, k+1, d-1));
    return b;
}
</code></pre>

<p>However, as you can see from my output, the curve, for some reason, tends to start and end at the origin (y-axis is inverted). Any help on the reason for this would be appreciated. Thanks :D</p>

<p><a href="https://i.stack.imgur.com/Pd6qy.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/Pd6qy.jpg" alt="Output"></a></p>