1、圆柱螺旋线绘制原理
在OCC中,圆柱面的参数方程为:
设P为(x0,y0,z0),则
x=x0+r*cos(u)
y=y0+r*sin(u)
z=z0+v
但u、v之间有关系时,此方程表达为圆柱螺旋线,u、v之间为线性关系时是等螺距螺旋线,u、v之间为非线性关系时是变螺距螺旋线。
2、Draw Test Harness命令绘制圆柱螺旋线
使用Tcl命令在Draw Test Harness中生成的圆柱螺旋线并到出Brep数据如下:
pload ALL
cylinder aCylinder 6
line aLine2d 0 0 1 1
trim aSegment aLine2d 0 2*pi
mkedge aHelixEdge aSegment aCylinder 0 6*pi
dump aHelixEdge
代码先加载所有模块,然后创建一个圆柱面aCylinder;一条二维直线aLine2d;再将参数范围限定在0到2PI之间;最后使用了用曲面及其上的pcurve来创建边的算法mkedge生成了螺旋线并导出Brep数据。
3、Brep数据
Brep数据如下所示,下面直接在该数据中进行解释说明。
*********** Dump of aHelixEdge *************
Shape : 3, FORWARD
Dump of 3 TShapes
-----------------
Flags : Free, Modified, Checked, Orientable, Closed, Infinite, Convex, Locked
TShape # 1 : EDGE11010000 0000027C9109C6E0
+3 -2
Tolerance : 1e-07
same parametrisation of curves
same range on curves
- PCurve : 1 on surface 1, range : 0 18.8495559215388
UV Points : 0, 0 13.3286488144751, 13.3286488144751
- Polygon 3D : 1
这里存储螺旋线的起点、终点Pcurve以及Polygon 3D
该螺旋线始于Tshape3,终于Tshape2,其是圆柱面上的参数曲线,其参数范围为:
u:[0, 13.3286488144751]
v:[0, 13.3286488144751]
参数由Curve2ds中的1号直线的起点、方向,及范围[0,18.8495559215388]确定
螺旋线的参数方程由参数范围及surface中的1号面确定
TShape # 2 : VERTEX01011010 0000027C910A35A0
Tolerance : 1e-07
- Point 3D : 4.33958778097726, 4.14342586408793, 13.3286488144751
这里存储螺旋线的终点,坐标为(4.33958778097726,4.14342586408793,13.3286488144751)
TShape # 3 : VERTEX01011010 0000027C910A2F20
Tolerance : 1e-07
- Point 3D : 6, 0, 0
这里存储螺旋线的起点,坐标为(6,0,0)
-------
Dump of 1 Curve2ds
-------
1 : Line
Origin :0, 0
Axis :0.707106781186547, 0.707106781186547
这里存储Pcurve的起点及方向,这个方向是归一化后的
-------
Dump of 0 Curves
-------
-------
Dump of 1 Polygon3Ds
-------
1 : Polygon3D with 79 Nodes
with parameters
Deflection : 0.054777818570848
Nodes :
1 : 6 0 0
2 : 5.91147846277275 1.02685071172685 0.171988435739901
3 : 5.64852587194202 2.02340195561871 0.343976871479801
4 : 5.21890121669389 2.96024831566391 0.515965307219702
5 : 4.63528150866612 3.80974609855013 0.687953742959602
6 : 3.91488771909563 4.54682902107328 0.859942178699503
7 : 3.07897663653632 5.14974784544481 1.0319306144394
8 : 2.15221363899269 5.60071213794584 1.2039190501793
9 : 1.16194488819403 5.88641521444077 1.3759074859192
10 : 0.137390421503272 5.99842678308898 1.54789592165911
11 : -0.891218048958075 5.9334416984758 1.71988435739901
12 : -1.89352918885328 5.69337748713017 1.89187279313891
13 : -2.83996762388782 5.28531776672595 2.06386122887881
14 : -3.70260662567498 4.7213032285067 2.23584966461871
15 : -4.45599215071128 4.01797635045298 2.40783810035861
16 : -5.07789391739641 3.19609032470432 2.57982653609851
17 : -5.54996135893326 2.27989668940233 2.75181497183841
18 : -5.85826509678857 1.29642973421194 2.92380340757831
19 : -5.99370795735972 0.274708794695026 3.09579184331821
20 : -5.95229340390531 -0.755118026420635 3.26778027905811
21 : -5.73524346307045 -1.76266344470738 3.43976871479801
22 : -5.34896266632775 -2.71819763708086 3.61175715053791
23 : -4.80484907032021 -3.59352548501371 3.78374558627782
24 : -4.11895793236278 -4.36281853294699 3.95573402201772
25 : -3.31152796508963 -5.00337711315361 4.12772245775762
26 : -2.40638414913624 -5.49630014889888 4.29971089349752
27 : -1.43023472516923 -5.82704287189653 4.47169932923742
28 : -0.41188310904629 -5.98584599739104 4.64368776497732
29 : 0.618622015733548 -5.96802369312068 4.81567620071722
30 : 1.63087334991494 -5.77410184500908 4.98766463645712
31 : 2.59500221211051 -5.40980253975517 5.15965307219702
32 : 3.48255987933138 -4.88587522219627 5.33164150793692
33 : 4.26735702855079 -4.21777950951424 5.50362994367683
34 : 4.92623650974859 -3.42522902154295 5.67561837941673
35 : 5.43975664808373 -2.53160968745753 5.84760681515663
36 : 5.79276491287537 -1.5632896929744 6.01959525089653
37 : 5.97484502603907 -0.548841429573404 6.19158368663643
38 : 5.98062431706958 0.481801596174212 6.36357212237633
39 : 5.80993225539153 1.49822801594453 6.53556055811623
40 : 5.46780548223566 2.47044595335207 6.70754899385613
41 : 4.9643391935641 3.36976799961708 6.87953742959603
42 : 4.31438925931528 4.16965769807366 7.05152586533593
43 : 3.53713386858935 4.8465125601486 7.22351430107583
44 : 2.65550763538804 5.38036050821837 7.39550273681573
45 : 1.69552486285233 5.75544919528003 7.56749117255563
46 : 0.685511934561036 5.96071081227519 7.73947960829553
47 : -0.344728517141907 5.99008866791378 7.91146804403543
48 : -1.36479700275703 5.84271590454862 8.08345647977533
49 : -2.34459417880975 5.52294107669921 8.25544491551523
50 : -3.25520899456837 5.04019983747482 8.42743335125513
51 : -4.06977177559527 4.40873651906849 8.59942178699503
52 : -4.76424707204225 3.6471838226962 8.77141022273493
53 : -5.31814287697335 2.77801302014544 8.94339865847483
54 : -5.71511528768318 1.82687088993449 9.11538709421473
55 : -5.94345076816078 0.821822953225958 9.28737552995463
56 : -5.99641178249436 -0.207474660531981 9.45936396569454
57 : -5.87243560054993 -1.23065028232791 9.63135240143444
58 : -5.57518040972927 -2.21751288586357 9.80334083717434
59 : -5.11341737217911 -3.13894293957327 9.97532927291424
60 : -4.50077181253901 -3.96775164185642 10.1473177086541
61 : -3.75532117304723 -4.67948318591521 10.319306144394
62 : -2.89906159921539 -5.25313638162524 10.4912945801339
63 : -1.95725889562388 -5.67178434141331 10.6632830158738
64 : -0.95770300330158 -5.92307394496026 10.8352714516137
65 : 0.0701120030405293 -5.99959034493436 11.0072598873536
66 : 1.09585820195355 -5.89907575821934 11.1792483230935
67 : 2.08926871665989 -5.62449608672513 11.3512367588334
68 : 3.02103080520639 -5.18395340198907 11.5232251945733
69 : 3.8636507967903 -4.59044687590017 11.6952136303132
70 : 4.59226535242716 -3.86148921180638 11.8672020660531
71 : 5.18537511194659 -3.01858989404074 12.039190501793
72 : 5.62547907946288 -2.08662050371539 12.2111789375329
73 : 5.89959102839457 -1.09308082852379 12.3831673732728
74 : 5.99962268837775 -0.0672874215806556 12.5551558090127
75 : 5.92262240730803 0.960491447360601 12.7271442447526
76 : 5.67086224626782 1.95992892316386 12.8991326804925
77 : 5.25177093741309 2.90153442525559 13.0711211162324
78 : 4.83571236765298 3.55188483728401 13.1998849653538
79 : 4.33958778097726 4.14342586408793 13.3286488144751
这里存储螺旋线的数据点,一共80个点
Parameters :
0 0.243228378394701 0.486456756789402 0.729685135184103 0.972913513578804 1.2161418919735 1.45937027036821 1.70259864876291 1.94582702715761 2.18905540555231 2.43228378394701 2.67551216234171 2.91874054073641 3.16196891913111 3.40519729752581 3.64842567592052 3.89165405431522 4.13488243270992 4.37811081110462 4.62133918949932 4.86456756789402 5.10779594628872 5.35102432468343 5.59425270307813 5.83748108147283 6.08070945986753 6.32393783826223 6.56716621665693 6.81039459505164 7.05362297344634 7.29685135184104 7.54007973023574 7.78330810863044 8.02653648702514 8.26976486541984 8.51299324381454 8.75622162220924 8.99945000060394 9.24267837899865 9.48590675739335 9.72913513578805 9.97236351418275 10.2155918925774 10.4588202709721 10.7020486493668 10.9452770277616 11.1885054061563 11.431733784551 11.6749621629457 11.9181905413404 12.1614189197351 12.4046472981298 12.6478756765245 12.8911040549192 13.1343324333139 13.3775608117086 13.6207891901033 13.864017568498 14.1072459468927 14.3504743252874 14.5937027036821 14.8369310820768 15.0801594604715 15.3233878388662 15.5666162172609 15.8098445956556 16.0530729740503 16.296301352445 16.5395297308397 16.7827581092344 17.0259864876291 17.2692148660237 17.5124432444184 17.7556716228131 17.9989000012078 18.2421283796025 18.4853567579972 18.667456339768 18.8495559215388
这里存储输入的参数
-------
Dump of 0 PolygonOnTriangulations
-------
-------
Dump of 1 surfaces
-------
1 : CylindricalSurface
Origin :0, 0, 0
Axis :0, 0, 1
XAxis :1, 0, -0
YAxis :-0, 1, 0
Radius :6
这里存储确定圆柱面参数方程所需的起点、向量及半径
-------
Dump of 0 Triangulations
-------
-------
Dump of 0 Locations
-------
从这个文件数据可以看出,该螺旋线的参数方程为
x=0+6*cos(u)
y=0+6*sin(u)
z=0+v
v=u,u取6*PI*[0,√2/2]即[0, 13.3286488144751]
此螺旋线螺旋角为45°
4、C++代码绘制圆柱螺旋线
TopoDS_Shape createHelix()
{Handle_Geom_CylindricalSurface aCylinder = new Geom_CylindricalSurface(gp::XOY(), 6.0);gp_Lin2d aLine2d(gp_Pnt2d(0.0, 0.0), gp_Dir2d(1.0, 1.0));Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(aLine2d, 0.0, M_PI * 2.0);TopoDS_Shape aHelixEdge = BRepBuilderAPI_MakeEdge(aSegment, aCylinder, 0.0, 6.0 * M_PI);//BRepTools::Write(aHelixEdge, "d:/helix.brep");return aHelixEdge;
}
参考文献:
1、https://www.cppblog.com/eryar/archive/2015/07/09/211212.html
2、https://dev.opencascade.org/doc/occt-7.7.0/overview/html/specification__brep_format.html