Stretching out an array

后端 未结 3 1784
梦谈多话
梦谈多话 2021-02-08 11:03

I\'ve got a vector of samples that form a curve. Let\'s imagine there are 1000 points in it. If I want to stretch it to fill 1500 points, what is the simplest algorithm that g

3条回答
  •  生来不讨喜
    2021-02-08 11:17

    what is the simplest algorithm that gives decent results?

    Catmull-Rom splines. (if you want a smooth curve)

    http://www.mvps.org/directx/articles/catmull/
    http://en.wikipedia.org/wiki/Cubic_Hermite_spline

    For each new item calculate fractional position in old array, use use fractional part (f - floor(f)) as interpolation factor, and "integer" (i.e. floor(f)) part to find nearest elements.

    That is assuming that you're operating on data that can be mathematically interpolated (floats). If data cannot be interpolated (strings), then the only solution is to use nearest available element of old array.

    You'll need some tweaking if points in array aren't evenly distributed.

提交回复
热议问题