2012-07-20 83 views
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

有關Catmull-Rom樣條的更好解釋,請看this page,圖1應該可以幫助您。

給出了四個定義你樣條的點。 t表示點2和點3之間的位置,應計算座標。 t=0 2點,t=1點3 t=0.5是中途點2和3

之間您通常會怎麼做才能得出什麼樣的屏幕是有從0到1 t運行以特定的時間間隔,例如0.1。這會給你t = 0.1,0.2,0.3,... 0.9點的確切座標。您可以選擇一個小間隔併爲每個結果座標繪製一個點,或者可以選擇更大的間隔並在兩個相鄰座標之間畫一條直線。