沿BSPLINE插值

发布于 2025-01-21 20:24:44 字数 1462 浏览 0 评论 0原文

我有一个非常简单的bspline-是两个点,互相指向对方。实际上,只是一行。

我写了一个邻接循环以沿着样条获得位置,就像这样:

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

产生以下结果:

现在,由于我每次都在步行1/18,所以我希望每个点都与Checkers对齐(因为有18个检查员)。但是,它们倾向于摆动,中间点正好在Checker边界上,两侧的替代点倾向于稍微聚集到中心。

对于我正在做的事情,我需要它们在Checker Borders上(或至少非常非常接近)。

我认为聚类是由沿着样条沿线的一些光插值误差引起的。这是我相关的样条函数(假设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;}

是否有一种方法可以按摩它以获得我所需的结果,还是只是去做这种样条插值的工件?还是样条控制点的位置有某个因素? (将它们靠近/进一步移动似乎并没有改善任何东西,我仍然得到中心偏见)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文