0025158: Visualization, OpenGl_Context - support EGL as alternative to WGL and GLX
[occt.git] / samples / tcl / drill.tcl
1 # Sample: creation of simple twist drill bit
2
3 pload MODELING VISUALIZATION
4
5 # drill parameters (some terms taken from http://www.drill-bits.cn/drill-bits-quality.asp)
6 dset R  4.    ;# outer radius
7 dset D  2*R   ;# diameter
8 dset Rr 3.5   ;# chisel radius (outer radius minus body clearance)
9
10 dset b  1.    ;# web thickness (approximate)
11 dset d  b/2
12
13 dset H  80.   ;# height of the spiral part
14 dset a  3.*pi ;# total angle of spiral rotation
15
16 dset sigma 118 ;# point angle, in degrees
17
18 # Create section profile by sequence of Boolean operations
19 # on simple planar objects
20 puts "Creating the drill section profile..."
21
22 polyline rectangle1 d -R 0  R -R 0  -d R 0  -R R 0  d -R 0
23
24 circle circle1 0 0 0  0 0 1 R
25 mkedge circle1 circle1
26 wire circle1 circle1
27
28 circle circle2 0 0 0  0 0 1 Rr
29 mkedge circle2 circle2
30 wire circle2 circle2
31
32 plane p0
33 mkface rectangle1 p0 rectangle1
34 mkface circle1 p0 circle1
35 mkface circle2 p0 circle2
36
37 bcommon sec rectangle1 circle1
38 # note use of 'fuse' instead of 'bfuse' -- we need to get single face
39 fuse sec sec circle2
40
41 # Construct flute profile so as to have cutting lip straight after sharpening.
42 # Here we need to take into account spiral shift of the flute edge
43 # along the point length -- the way to do that is to make spiral
44 # from the desired cutting lip edge and then intersect it by plane
45 polyline lip d -d/2 0  d -R -R/tan(sigma/2*pi/180)
46
47 polyline sp 0 0 0  0 0 H
48 cylinder cc 0 0 0  0 0 1  0 -4 0  4
49 line ll 0 0 a 80
50 trim ll ll 0 sqrt(a*a+H*H)
51
52 vertex v1 0 -R 0
53 vertex v2 0 -R H
54 trotate v2 0 0 0 0 0 1 180.*a/pi
55 mkedge ee ll cc v1 v2
56 wire gg ee
57  
58 mksweep sp
59 setsweep -G gg 0 0
60 addsweep lip
61 buildsweep spiral -S
62
63 mkface f0 p0 -R R -R R
64 bsection sflute spiral f0
65
66 # here we rely on that section curve is parameterized from 0 to 1 
67 # and directed as cutting lip edge;
68 # note that this can change if intersection algorithm is modified
69 explode sflute e
70 mkcurve cflute sflute_1
71 cvalue cflute 0. x0 y0 z0
72 cvalue cflute 1. x1 y1 z1
73 vertex vf0 x0 y0 z0 
74 vertex vf1 x1 y1 z1
75
76 # -- variant: replace curve by arc with start at x0,y0,z0 and end at x1,y1,z1,
77 # -- such that tanget at start point is along Y
78 #dset Rflute ((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))/(2*(x1-x0))
79 #circle aflute x0+Rflute y0 0  0 0 1  Rflute
80 #mkedge sflute_1 aflute vf0 vf1
81
82 # make rounding in the flute; use circle with radius Rr/2
83 circle cround x0+Rr/2 y0 0  0 0 1 Rr/2
84 vertex vf3 x0+Rr y0 0 
85 mkedge sflute_2 cround vf3 vf0
86 vertex vf2 R -R 0
87 edge sflute_3 vf3 vf2
88 edge sflute_4 vf2 vf1
89 wire w2 sflute_1 sflute_2 sflute_3 sflute_4
90 mkface flute p0 w2
91
92 # cut flute from profile
93 bcut sec sec flute
94 trotate flute 0 0 0 0 0 1 180.
95 bcut sec sec flute
96 donly sec
97
98 # sweep profile to get a drill body
99 puts "Sweeping the profile..."
100
101 mksweep sp
102 setsweep -G gg 0 0
103 explode sec w
104 addsweep sec_1
105 buildsweep base -S
106
107 # sharpen the drill (see http://tool-land.ru/zatochka-sverla.php)
108 puts "Sharpening..."
109
110 dset theta a*R/H*sin((90-sigma/2)*pi/180)
111 plane ax1 d 1.9*D "H+1.9*D/tan(pi/180.*sigma/2.)" 0 -1 -1
112 pcone sh1 ax1 0 100*sin((sigma-90)/2*pi/180.) 100
113 trotate sh1 0 0 0 0 0 1 -theta*180/pi
114 tcopy sh1 sh2
115 trotate sh2 0 0 0 0 0 1 180
116 box sh -D/2 -D/2 72 D D 20
117 bcommon qq sh1 sh2
118 bcut sharpener sh qq
119
120 bcut body base sharpener
121
122 # make a shank
123 puts "Making a shank..."
124 plane pl2 0 0 -40  0 0 1
125 pcylinder shank pl2 4 40
126 pcone transit R 0 R
127 plane pl3 0 0 -40  0 0 -0.5
128 pcone tail pl3 R 0 0.5
129 bfuse shank shank tail
130 bfuse shank shank transit
131 bfuse drill body shank
132
133 # check result
134 checkshape drill
135
136 # show result
137 puts "Displaying result..."
138 incmesh drill 0.01
139 vdisplay drill
140 vsetdispmode drill 1
141 vfit
142
143 # show section and sweep path
144 ttranslate sec_1 0 0 H; trotate sec_1 0 0 0 0 0 1 a*180/pi; incmesh gg 0.01; vdisplay gg sec_1