Interpolation along a BSpline

85 views Asked by At

I have a very simple Bspline-- it's two points, in/out normals pointing at each other. In fact, just a line.

I wrote a little for-next loop to get positions along the spline, like so:

    for (float aCount=0;aCount<mSpline.Max();aCount+=1.0f/18.0f)
    {
        Vector aPos=mSpline.Get(aCount);
        PlotPoint(aPos,Color(1,0,1));
    }

Which produces the following result: enter image description here

Now, since I was stepping 1/18th of the way each time, I expected each dot to be aligned with the checkers (since there's 18 checkers). However, they tend to wobble, with the halfway point being exactly on the checker boundary, and the alternate spots on either side tending to gather towards the center a little bit.

For what I'm doing, I need them to be on the checker borders (or at least, very, very close).

I assume the clustering is caused by some light interpolation error along the spline. Here are my relevant spline functions (assume vtype = Vector):

vtype Get(float thePos)
    {
        float aPos=thePos-floorf(thePos);
        int aIPos=(int)floorf(thePos);

        BSplinePoint& aP1=mPoints[_clamp(0,aIPos,mPoints.Size()-1)];
        BSplinePoint& aP2=mPoints[_clamp(0,aIPos+1,mPoints.Size()-1)];

        vtype aResult;
        vtype aAB, aBC, aCD, aABBC, aBCCD;
        Lerp(aAB,aP1.mPos,aP1.mOut,aPos);
        Lerp(aBC,aP1.mOut,aP2.mIn,aPos);
        Lerp(aCD,aP2.mIn,aP2.mPos,aPos);
        Lerp(aABBC,aAB,aBC,aPos);
        Lerp(aBCCD,aBC,aCD,aPos);
        Lerp(aResult,aABBC,aBCCD,aPos);
        return aResult;
    }

    inline void Lerp(vtype& theResult, vtype a, vtype b, float thePos) {theResult=a+(b-a)*thePos;}

Is there a way to massage this to get my desired result, or is this just going to an artifact of this kind of spline interpolation? Or is there some factor of the location of the spline control points? (Moving them closer/further doesn't seem to improve anything, I still get a center-bias)

0

There are 0 answers