OpenCascade Ruled Surface
Abstract. A ruled surface is formed by moving a line connecting points of equal relative arc length or equal relative parametric value on two parametric curves from a start point to a terminate point on the curves. The paper focus on the ruled surface in opencascade.
Key words. OpenCascade, Ruled Surface, 直紋面
1.Introduction
《解析幾何》中有關於直紋面Ruled Surface的定義:一曲面S稱為直紋面,如果存在一族直線使得這一族中的每一條直線全在S上。並且S上的每個點都在這一族的某一條直線上。這樣一族直線稱為S的一族直母線。其參數方程為:
即可以將直紋面看作是曲面對當v=0和1時得到的兩個邊界曲線之間進行線性插值得到的曲面。
Autodesk 3DS Max中的直紋面,圖片來自:
直紋面是從兩條曲線來構造曲面的方法,Coons曲面是由四邊條界曲線來構造曲面,理解直紋面的構造原理,為進一步理解通用的放樣Sweep造型打下基礎。
2.Ruled Surface Parametric Equation
直紋面的參數方程也可以寫成如下形式:
直接根據參數方程可以定義出相應的直紋面。在OpenCASCADE中話,可以從Geom_Surface派生新的類,並實現相應的虛函數。如實現計算對應參數u,v的值的虛函數D0()等。為了簡單起見,用相應的函數計算直紋面上的點,並生成OpenCASCADE Draw Test Harness的命令腳本文件,方便在Draw中可視化。
如有名的Mobius Strip也是個直紋面:
Mobius Strip的參數方程為:
根據上述參數方程在OpenCASCADE的Draw生成Mobius Strip,代碼如下所示:
const Standard_Real MOBIUS_RADIUS = 50.0; void MobiusStrip(Standard_Real theU, Standard_Real theV, gp_Pnt& thePoint) { thePoint.SetX((MOBIUS_RADIUS + theU * Cos(0.5 * theV)) * Cos(theV)); thePoint.SetY((MOBIUS_RADIUS + theU * Cos(0.5 * theV)) * Sin(theV)); thePoint.SetZ(theU * Sin(0.5 * theV)); } void TestMobiusStrip() { std::ofstream aTclFile("d:/mobius.tcl"); aTclFile << "pload ALL" << std::endl; aTclFile << "vinit" << std::endl; Standard_Real aWidth = 10.0; Standard_Integer aN = 0; for (Standard_Real s = -aWidth; s < aWidth; s += 1.0) { aTclFile << "polyline p" << ++aN ; for (Standard_Real t = 0.0; t < M_PI * 2.0; t += 0.01) { gp_Pnt aPoint; MobiusStrip(s, t, aPoint); aTclFile << " " << aPoint.X() << " " << aPoint.Y() << " " << aPoint.Z(); } aTclFile << "\n vdisplay p" << aN << std::endl; } for (Standard_Real t = 0.0; t < M_PI * 2.0; t += 0.2) { aTclFile << "polyline p" << ++aN; gp_Pnt aPoint; MobiusStrip(-aWidth, t, aPoint); aTclFile << " " << aPoint.X() << " " << aPoint.Y() << " " << aPoint.Z(); MobiusStrip(aWidth, t, aPoint); aTclFile << " " << aPoint.X() << " " << aPoint.Y() << " " << aPoint.Z(); aTclFile << "\n vdisplay p" << aN << std::endl; } } int main(int argc, char* argv[]) { TestMobiusStrip(); return 0; }
在D盤生成一個mobius.tcl腳本文件,直接在Draw Test Harness中輸入命令:
source d:/mobius.tcl
即可得到如下圖所示的Mobius環:
其他的直紋面只要知道參數方程,都可以采用這種方法在OpenCASCADE Draw Test Harness中進行顯示。有人也用POV-Ray根據直紋面的參數方程來繪制直紋面,效果更不錯。
這是使用參數方程來表示直紋面的方法,如果知道直紋面的參數方程,可以從幾何曲面來派生新類Geom_Surface,並實現幾個相關虛函數,應該可以直接給OpenCASCADE顯示了,這種方法沒有測試。
3.Ruled Surface to B Spline Surface
如果已知直紋面的參數方程,如何用NURBS曲面來表示直紋面呢?在《非均勻有理B樣條》一書中給出了一種將給定兩條曲線C1,C2轉換成直紋面的方法。他給出的限制條件是想要生成在v方向是直線的曲面,即是C1(u)和C2(u)之間的線性插值。而且還要求在兩條曲線的等參數點之間進行插值。又由於曲面是張量各曲面,兩條邊界曲線C1和C2必須具有相同的次數,並定義在相同的節點矢量上,因此表示這樣的直紋面的B樣條轉換過程為:
l 確保兩條曲線定義在相同的參數區間內;
l 確保兩條曲線的次數相同。如果不同,則將次數低的曲線升階;
l 確保兩條曲線有相同的節點矢量。
OpenCASCADE中生成直紋面的是類GeomFill的靜態函數Surface(),其實現步驟與上述類似,具體實現的類是GeomFill_Profiler。GeomFill_Profiler是個更通用的類,它可以根據多條曲線來構造曲面。下面通過Draw Test Harness腳本來根據兩條曲線構造直紋面。
3.1 根據兩條直線構造直紋面
# Ruled surface between two lines. vertex v1 0 0 0 vertex v2 0 8 8 vertex v3 8 0 8 vertex v4 8 8 0 edge e1 v1 v2 edge e2 v3 v4 pruled r1 e1 e2 vdisplay v1 v2 v3 v4 e1 e2 r1
生成直紋面是一個雙線性曲面,如下圖所示:
3.2 根據兩個圓構造直紋面
# Ruled surface between circle and ellipse. circle c1 0 0 0 5 circle c2 0 0 10 4 mkedge e3 c1 mkedge e4 c2 pruled r2 e3 e4 vdisplay e3 e4 r2
生成的直紋面是一個圓錐面,效果如下圖所示:
當頂部的圓旋轉時會得到如下圖所示的直紋面:
相應的Draw腳本如下:
# Ruled surface between circle and ellipse. circle c1 0 0 0 5 circle c2 0 0 10 4 mkedge e3 c1 mkedge e4 c2 pruled r2 e3 e4 vdisplay e3 e4 r2 wait 2 trotate e4 0 0 0 0 0 1 30 pruled r2 e3 e4 vdisplay r2 wait 2 trotate e4 0 0 0 0 0 1 30 pruled r2 e3 e4 vdisplay r2 wait 2 trotate e4 0 0 0 0 0 1 30 pruled r2 e3 e4 vdisplay r2
生成的動畫效果如下圖所示:
4.Conclusion
根據直紋面的參數方程就可以繪制出相應的曲面,然后如何用B樣條曲面來表示直紋面,需要滿足一定的條件。IGES中定義的直紋面就給出了兩種方式:等弧長和等參數構造。引用《非均勻有理B樣條》書中對兩種形式的說明如下:一般情況下,連接兩條曲線上相對弧長相等的點會產生一個幾何上不同的曲面,而這樣的曲面不能通過NURBS來表示。因此,要在NURBS的直紋面和IGES的直紋面(Type 118 Form 0/1)之間進行數學上的精確轉換是不可能的。
OpenCASCADE的直紋面也是使用的NURBS表示,所以其也是等參數形式的直紋面。希望在理解根據兩條曲線來構造曲面的方法來理解更一般的造型算法,即通過多條曲線來構造曲面的造型方法。
5.References
1. Weisstein Eric W. “Ruled Surface”. http://mathworld.wolfram.com/RuledSurface.html
2. www.ms.uky.edu/~lee/visual05/gallery/ruledsurfaces.doc
3. The Initial Graphics Exchange Specification (IGES) Version 6.0
4. 趙罡, 穆國旺, 王拉柱. 非均勻有理B樣條. 清華大學出版社. 2010
5. 丘維聲. 解析幾何. 北京大學出版社. 1996