【问题标题】:Bezier Curve Arc-Length Parameterization贝塞尔曲线弧长参数化
【发布时间】:2018-12-03 00:28:51
【问题描述】:

我正在学习贝塞尔曲线,并想使用估计方法参数化距离方程。到目前为止,我的代码似乎适用于单点(EG Bezier(start=0, mid=1, end=5, nPoints=6) 产生 [0 1 2 3 4 5])。但是,当我尝试将其应用于多维曲线时,我的结果并不如预期。

C# 代码(在 Unity 中执行以实现可视化)。该函数(应该)在长度为 l% 的曲线上获取一个点(由点 pts 定义)。

Vector3 BezierL(Vector3[] pts, float l)
{
    int i;
    float[] tVals = new float[n];
    Vector3[] points = new Vector3[n];
    float[] cumDist = new float[n];
    for (i = 1; i < n; i++)
    {
        tVals[i] = i / (float)(n - 1);
        points[i] = Bezier(pts, tVals[i]);
        cumDist[i] = cumDist[i - 1] + 
            (points[i] - points[i - 1]).magnitude;
    }
    // Interpolate to estimate t
    float targetLen = l * cumDist[n - 1];
    int ind = Array.BinarySearch(cumDist, targetLen);
    if (ind < 0)
        ind = ~ind;
    float t = Mathf.Lerp(tVals[ind - 1], tVals[ind],
        (targetLen - cumDist[ind - 1]) / (cumDist[ind] - cumDist[ind - 1]));
    return Bezier(pts, t);
}

其中Bezier(Vector3[] pts, t)pts 定义的曲线上得到一个点t。无论出于何种原因,这在一定程度上是有效的,因为所有点都等距分布,但有些点在初始点堆叠,而不是沿曲线分布。

This 是我开发此算法的参考,所以我不确定我的实现是否不正确,或者它是否仅适用于低维曲线。

提前致谢!

【问题讨论】:

  • 似乎从未计算过 points[0]。

标签: c# bezier


【解决方案1】:

好尴尬,我只是忘了计算第 0 点!

【讨论】:

  • 这应该是评论,而不是答案。特别是考虑到解决方案是什么,这基本上是一个通过“额外的一双眼睛”而不是真正的编程问题来解决的非问题,并且它有自己的专用关闭选项。可能值得再次删除这个问题。
猜你喜欢
  • 1970-01-01
  • 2019-07-27
  • 2014-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多