C# C语言中的三次/曲线平滑插值#

C# C语言中的三次/曲线平滑插值#,c#,math,linear-interpolation,bicubic,C#,Math,Linear Interpolation,Bicubic,下面是一个三次插值函数: 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 * am

下面是一个三次插值函数:

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));
}
如何调整此值以生成两条向内和向外的“生成切线”

要生成这样的曲线:(线性起点到立方终点)

已删除过期的图像

作为一项功能

像这样的另一个:(立方起点到线性终点)

已删除过期的图像


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

您可以使用线性插值和三次插值以及两个插值函数之间的插值

其中t的范围为0…1

您需要的是:


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

-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
或以编程方式(立体调整):

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

或以编程方式(立体调整):


我看看能不能让你的解决办法奏效。然而,理想情况下,我宁愿调整方法中的立方函数:amount=(amount*amount)*(3f-(2f*amount));我假设这很容易做到,我只是不知道怎么做。如果你想得到切线,使用我在Hanks Robert下面发布的三次Hermite样条曲线,让它看起来更漂亮:)是的。这就是做到这一点的方法。分段三次Hermite插值函数具有一个很好的性质,即它可以简单地保证在断点之间是连续的和可微的,因为区间两端的值和一阶导数都是给定的。这是一个非常漂亮的建立分段立方体的方法。投票决定结束这个问题,因为它依赖图像来显示问题/问题是什么,而这些图像显然早已消失。这样的问题(在我看来)没有价值,答案也没有价值,因为没有人知道这些答案回答了什么问题。
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)
-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;