【问题标题】:Cubic/Curve Smooth Interpolation in C# [closed]C# 中的三次/曲线平滑插值 [关闭]
【发布时间】:2009-07-18 00:29:53
【问题描述】:

下面是三次插值函数:

public float Smooth(float start, float end, float amount)
{
    // Clamp to 0-1;
    amount = (amount > 1f) ? 1f : amount;
    amount = (amount < 0f) ? 0f : amount;

    // Cubicly adjust the amount value.
    amount = (amount * amount) * (3f - (2f * amount));

    return (start + ((end - start) * amount));
}

此函数将在给定 0.0f - 1.0f 之间的数量的情况下在开始值和结束值之间进行三次插值。如果你要绘制这条曲线,你最终会得到这样的结果:

已删除过期的 Imageshack 图像

这里的三次函数是:

    amount = (amount * amount) * (3f - (2f * amount));

如何调整它以产生两条进出切线?

要产生这样的曲线:(线性开始到立方结束)

已删除过期的 Imageshack 图像

作为一个功能

和另一个一样:(立方开始到线性结束)

已删除过期的 Imageshack 图像

有人有什么想法吗?提前致谢。

【问题讨论】:

  • 投票结束这个问题,因为它依赖图像来显示问题/问题是什么,而这些图像显然早已不复存在。这样的问题(在我看来)没有价值,答案也没有,因为没有人知道这些答案会回答什么问题。

标签: c# math linear-interpolation bicubic


【解决方案1】:

你想要的是Cubic Hermite Spline:

其中p0是起点,p1是终点,m0是起点切线,m1是终点切线

【讨论】:

  • 感谢罗伯特,让它看起来更漂亮:)
  • 是的。这是执行此操作的方法。分段三次 Hermite 插值具有很好的特性,即它可以简单地确保在断点上既连续又可微,因为给出了区间每一端的值和一阶导数。恕我直言,这是构建分段三次的非常漂亮的方法。
【解决方案2】:

你可以有一个线性插值和一个三次插值,并在两个插值函数之间进行插值。

即。

cubic(t) = cubic interpolation
linear(t) = linear interpolation
cubic_to_linear(t) = linear(t)*t + cubic(t)*(1-t)
linear_to_cubic(t) = cubic(t)*t + linear(t)*(1-t)

其中 t 的范围为 0...1

【讨论】:

  • 我会看看能否让您的解决方案发挥作用。但是,理想情况下,我宁愿只调整方法中的三次函数:amount = (amount * amount) * (3f - (2f * amount));我假设这可以相当容易地完成,我只是不确定如何。
  • 如果你想要切线,请使用我在下面发布的 Cubic Hermite Spline
【解决方案3】:

嗯,一个简单的方法是这样的:

-Expand your function by 2 x and y
-Move 1 to the left and 1 down
Example: f(x) = -2x³+3x²
g(x) = 2 * [-2((x-1)/2)³+3((x-1)/2)²] - 1

或以编程方式(三次调整):

double amountsub1div2 = (amount + 1) / 2;
amount = -4 * amountsub1div2 * amountsub1div2 * amountsub1div2 + 6 * amountsub1div2 * amountsub1div2 - 1;

对于另一个,只需省略“移动”:

g(x) = 2 * [-2(x/2)³+3(x/2)²]

或以编程方式(三次调整):

double amountdiv2 = amount / 2;
amount = -4 * amountdiv2 * amountdiv2 * amountdiv2 + 6 * amountdiv2 * amountdiv2;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多