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であり、これは2番目と3番目の点の間の正規化された距離として記述されます。このコンテキストで正規化された距離を計算するにはどうすればよいですか?

4

1 に答える 1

3

Catmull-Rom スプラインのより良い説明については、このページをご覧ください。図 1 が役立ちます。

スプラインを定義する 4 つのポイントが与えられています。t座標が計算されるポイント 2 と 3 の間の位置を示します。t=0 ポイント 2、ポイント 3です。t=1 t=0.5ポイント 2 と 3 の中間です。

画面にスプラインを描画するために通常行うことは、t0.1 などの特定の間隔で 0 から 1 まで実行することです。tこれにより、0.1、0.2、0.3、... 0.9の点の正確な座標が得られます。小さな間隔を選択して結果の座標ごとにドットをペイントするか、大きな間隔を選択して隣接する 2 つの座標間に直線を描くことができます。

于 2012-07-20T10:30:35.277 に答える