0

我一直在查看我在这里找到的以下代码:http: //tehc0dez.blogspot.co.uk/2010/04/nice-curves-catmullrom-spline-in-c.html

/// <summary>
/// Calculates interpolated point between two points using Catmull-Rom Spline
/// </summary>
/// <remarks>
/// Points calculated exist on the spline between points two and three.
/// </remarks>/// <param name="p0">First Point</param>
/// <param name="p1">Second Point</param>
/// <param name="p2">Third Point</param>
/// <param name="p3">Fourth Point</param>
/// <param name="t">
/// Normalised distance between second and third point 
/// where the spline point will be calculated
/// </param>
/// <returns>
/// Calculated Spline Point
/// </returns>
static public PointF PointOnCurve(PointF p0, PointF p1, PointF p2, 
                                  PointF p3, float t)
{
    PointF ret = new PointF();
    float t2 = t * t;
    float t3 = t2 * t;
    ret.X = 0.5f * ((2.0f * p1.X) + (-p0.X + p2.X) * t + 
                    (2.0f * p0.X - 5.0f * p1.X + 4 * p2.X - p3.X) * t2 + 
                    (-p0.X + 3.0f * p1.X - 3.0f * p2.X + p3.X) * t3);
    ret.Y = 0.5f * ((2.0f * p1.Y) + (-p0.Y + p2.Y) * t + 
                    (2.0f * p0.Y - 5.0f * p1.Y + 4 * p2.Y - p3.Y) * t2 + 
                    (-p0.Y + 3.0f * p1.Y - 3.0f * p2.Y + p3.Y) * t3);    
    return ret;
}

我不明白的参数是 t ,它被描述为第二点和第三点之间的归一化距离。在这种情况下,什么是以及如何计算归一化距离?

4

1 回答 1

3

有关 Catmull-Rom Spline 的更好解释,请查看此页面,图 1 应该可以帮助您。

您给出了四个点,它们定义了您的样条曲线。t表示点 2 和 3 之间的位置,应为其计算坐标。t=0 第 2 点,t=1 第 3 点。t=0.5在第 2 点和第 3 点之间。

为了在屏幕上绘制样条曲线,您通常会做的是t从 0 到 1 以特定的间隔运行,例如 0.1。这将为您提供t= 0.1、0.2、0.3、... 0.9 的点的确切坐标。您可以选择一个较小的间隔并为每个结果坐标绘制一个点,或者您可以选择一个较大的间隔并在两个相邻坐标之间绘制一条直线。

于 2012-07-20T10:30:35.277 回答