2011-08-27 174 views
2

我的Flash應用程序接收來自外部應用程序的B樣條數據,但Flash繪圖API只允許使用Graphics#curveTo()方法的二次貝塞爾曲線。如何使用貝塞爾曲線繪製B樣條?

是否可以將B樣條轉換爲一系列curveTo()調用?

回答

1

有多種類型的B樣條。不過,我想你會把B樣條分解成Bezier。你可以迭代曲線,對於每一個你可以通過一定的細節來遍歷點,從而能夠從線中繪製曲線。

這裏有一個快速片段:

private function curve(control1:Point,anchor1:Point,control2:Point,anchor2:Point,t:Number):Point{ 
      var result:Point = new Point(); 
      var tSquared:Number = t*t; 
      var tCubed:Number = t*t*t; 
      result.x = tCubed*(anchor2.x+3*(control1.x-control2.x)-anchor1.x) 
             +3*tSquared*(anchor1.x-2*control1.x+control2.x) 
             +3*y*(control1.x-anchor1.x)+anchor1.x; 
      result.y = tCubed*(anchor2.y+3*(control1.y-control2.y)-anchor1.y) 
             +3*tSquared*(anchor1.y-2*control1.y+control2.y) 
             +3*y*(control1.y-anchor1.y)+anchor1.y; 
      return result; 
     } 

看一看Paul Tondeur's Drawing a cubic curve blog entry和引用那裏。

HTH

+0

+1。很好的資源。感興趣的是,在Flash Player 11的Drawing API中(最終)支持三次貝塞爾曲線。 – TheDarkIn1978

相關問題