2009-07-18 95 views
14

下面是三次插值函数:三次/曲线平滑插补

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图片已删除

任何人有任何想法?提前致谢。

+2

投票结束这个问题,因为它依靠图像来显示问题是什么,一个那些图像显然早已消失。这样的问题(在我看来)没有价值,也没有答案,因为没有人知道这些答案会回答什么问题。 – 2015-08-15 19:50:17

回答

12

你想要的是一个Cubic Hermite Spline

alt text

其中P0为起点,P1是终点,M0是起点切线,而m1是终点切线

3

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

即。

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

+0

我会看看我是否可以解决您的解决方案。但是,理想情况下,我宁愿只调整方法中的三次函数: amount =(amount * amount)*(3f - (2f * amount)); 我假设这可以做得相当容易,我只是不知道如何。 – Rob 2009-07-18 00:53:49

+1

如果你想有切线,使用我发布在 – 2009-07-18 01:33:52

0

那么,一个简单的方法是:

-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;