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