0026605: Possible array out of bounds read in Extrema_GExtPC.gxx
[occt.git] / samples / tcl / drill.tcl
CommitLineData
07b5cb8f 1# Sample: creation of simple twist drill bit
ab91ab6f 2#Category: Modeling
3#Title: Drill
07b5cb8f 4
5pload MODELING VISUALIZATION
6
7# drill parameters (some terms taken from http://www.drill-bits.cn/drill-bits-quality.asp)
8dset R 4. ;# outer radius
9dset D 2*R ;# diameter
10dset Rr 3.5 ;# chisel radius (outer radius minus body clearance)
11
12dset b 1. ;# web thickness (approximate)
13dset d b/2
14
15dset H 80. ;# height of the spiral part
16dset a 3.*pi ;# total angle of spiral rotation
17
18dset sigma 118 ;# point angle, in degrees
19
20# Create section profile by sequence of Boolean operations
21# on simple planar objects
22puts "Creating the drill section profile..."
23
24polyline rectangle1 d -R 0 R -R 0 -d R 0 -R R 0 d -R 0
25
26circle circle1 0 0 0 0 0 1 R
27mkedge circle1 circle1
28wire circle1 circle1
29
30circle circle2 0 0 0 0 0 1 Rr
31mkedge circle2 circle2
32wire circle2 circle2
33
34plane p0
35mkface rectangle1 p0 rectangle1
36mkface circle1 p0 circle1
37mkface circle2 p0 circle2
38
39bcommon sec rectangle1 circle1
40# note use of 'fuse' instead of 'bfuse' -- we need to get single face
41fuse 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
47polyline lip d -d/2 0 d -R -R/tan(sigma/2*pi/180)
48
49polyline sp 0 0 0 0 0 H
50cylinder cc 0 0 0 0 0 1 0 -4 0 4
51line ll 0 0 a 80
52trim ll ll 0 sqrt(a*a+H*H)
53
54vertex v1 0 -R 0
55vertex v2 0 -R H
56trotate v2 0 0 0 0 0 1 180.*a/pi
57mkedge ee ll cc v1 v2
58wire gg ee
59
60mksweep sp
61setsweep -G gg 0 0
62addsweep lip
63buildsweep spiral -S
64
65mkface f0 p0 -R R -R R
66bsection 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
71explode sflute e
72mkcurve cflute sflute_1
73cvalue cflute 0. x0 y0 z0
74cvalue cflute 1. x1 y1 z1
75vertex vf0 x0 y0 z0
76vertex 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
85circle cround x0+Rr/2 y0 0 0 0 1 Rr/2
86vertex vf3 x0+Rr y0 0
87mkedge sflute_2 cround vf3 vf0
88vertex vf2 R -R 0
89edge sflute_3 vf3 vf2
90edge sflute_4 vf2 vf1
91wire w2 sflute_1 sflute_2 sflute_3 sflute_4
92mkface flute p0 w2
93
94# cut flute from profile
95bcut sec sec flute
96trotate flute 0 0 0 0 0 1 180.
97bcut sec sec flute
98donly sec
99
100# sweep profile to get a drill body
101puts "Sweeping the profile..."
102
103mksweep sp
104setsweep -G gg 0 0
105explode sec w
106addsweep sec_1
107buildsweep base -S
108
109# sharpen the drill (see http://tool-land.ru/zatochka-sverla.php)
110puts "Sharpening..."
111
112dset theta a*R/H*sin((90-sigma/2)*pi/180)
113plane ax1 d 1.9*D "H+1.9*D/tan(pi/180.*sigma/2.)" 0 -1 -1
114pcone sh1 ax1 0 100*sin((sigma-90)/2*pi/180.) 100
115trotate sh1 0 0 0 0 0 1 -theta*180/pi
116tcopy sh1 sh2
117trotate sh2 0 0 0 0 0 1 180
118box sh -D/2 -D/2 72 D D 20
119bcommon qq sh1 sh2
120bcut sharpener sh qq
121
122bcut body base sharpener
123
124# make a shank
125puts "Making a shank..."
126plane pl2 0 0 -40 0 0 1
127pcylinder shank pl2 4 40
128pcone transit R 0 R
129plane pl3 0 0 -40 0 0 -0.5
130pcone tail pl3 R 0 0.5
131bfuse shank shank tail
132bfuse shank shank transit
133bfuse drill body shank
134
135# check result
136checkshape drill
137
138# show result
139puts "Displaying result..."
140incmesh drill 0.01
141vdisplay drill
142vsetdispmode drill 1
143vfit
144
145# show section and sweep path
146ttranslate 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