2015-06-25 71 views
2

我的問題是如何獲得位於定義爲給定軸向座標的NURBS曲線的曲線上的點的第二個座標(2D)。我有結矢量,控制點,它們的權重和基礎函數。給定一個軸向座標的NURBS曲線的點評估

我翻看類似的問題(How to find out Y coordinate of specific point in bezier curve in canvas?),但到目前爲止沒有找到一個好的答案。 謝謝, M

+0

澄清我正在尋找一種方法來確定NURBS參數的基礎上位於NURBS曲線上的點的x位置,以便我可以然後評估該參數的曲線,並找到相應的y值點 –

回答

0

如果您需要從頭開始實施一切,這不是一件容易的事情。儘管如此,該代碼將是這樣的:

 
for each non-null knot interval in the knot vector of the NURBS 
{ 
    extract Bezier curve B(t) from the NURBS for this knot interval [a, b]; 
    compute the minimum and maximum X values of the Bezier curve's control points. 
    if (X0 is within [Xmin, Xmax]) 
    { 
     t0 = a; 
     t1 = b; 
     epsilon = 1.0e-06; // a small value;

 while ((t1-t0) > epsilon) 
     { 
      Subdivide B(t) at t=0.5 to generate two Bezier curves: B1(t) and B2(t); 
      compute the [Xmin1, Xmax1] for B1(t) and [Xmin2, Xmax2] for B2(t); 
      if (X0 is within [Xmin1, Xmax1]) 
      { 
       B(t) = B1(t); 
       t0 = a; 
       t1 = (a+b)/2; 
      } 
      else 
      { 
       B(t) = B2(t); 
       t0 = (a+b)/2; 
       t1 = b; 
      } 
     } // end while loop 

     return ((t0+t1)/2); // This is the parameter value you are looking for 
    } // end if() 

} //結束for循環

的(T0 + T1)/ 2就是你正在尋找的參數值。請注意,您可能會發現給定相同X0值的多個解決方案。

+0

感謝您的回答。我有幾個後續問題。通過提取給定結間隔的貝塞爾曲線,你的意思是什麼?另外,Xmin2和Xmax2沒有在您的示例代碼中使用。他們不需要嗎? –

+0

NURBS曲線由在每個非空結點間隔內定義的多個曲線段組成。這些曲線段中的每一個實際上都是貝塞爾曲線(如果NURBS曲線確實是有理的,則爲有理貝塞爾曲線)。因此,提取結區間的貝塞爾曲線就意味着要爲結區間[a,b]創建一個貝塞爾曲線表示。要做到這一點的算法應該可以在線或在任何幾何建模教科書中使用。 – fang

+0

Xmin2和Xmax2並未真正使用。如果X0在[Xmin,Xmax]之內但不在[Xmin1,Xmax1]之內,則X0必須在[Xmin2,Xmax2]之內。你可以用它來檢查計算是否正確。 – fang