From 07b5cb8f23a4230be0c830e09332d33537157a66 Mon Sep 17 00:00:00 2001 From: abv Date: Thu, 27 Mar 2014 16:54:50 +0400 Subject: [PATCH] 0024758: Sample DRAW scripts for demonstrating sweeping algorithm Two scripts added: samples/tcl/drill.tcl: creates model of a twist drill bit samples/tcl/cutter.tcl: creates simplified model of a milling cutter Added test cases bugs/modalg_5/bug24758_1 bug24758_2 --- samples/tcl/cutter.tcl | 87 +++++++++++++++++++ samples/tcl/drill.tcl | 144 +++++++++++++++++++++++++++++++ tests/bugs/modalg_5/bug24758_1 | 96 +++++++++++++++++++++ tests/bugs/modalg_5/bug24758_2 | 152 +++++++++++++++++++++++++++++++++ 4 files changed, 479 insertions(+) create mode 100644 samples/tcl/cutter.tcl create mode 100644 samples/tcl/drill.tcl create mode 100644 tests/bugs/modalg_5/bug24758_1 create mode 100644 tests/bugs/modalg_5/bug24758_2 diff --git a/samples/tcl/cutter.tcl b/samples/tcl/cutter.tcl new file mode 100644 index 0000000000..953726ee8b --- /dev/null +++ b/samples/tcl/cutter.tcl @@ -0,0 +1,87 @@ +# Sample: creation of milling cutter + +pload MODELING VISUALIZATION + +# parameters +dset R 10. ;# outer radius +dset H 20. ;# height of the spiral part +dset a 0.5*pi ;# total angle of spiral rotation + +# make profile + +circle outer 0 0 0 0 0 1 R +circle inner 0 0 0 0 0 1 R-2 +circle round 3 6 0 0 0 1 5 +polyline cut -2 0 0 -2 R+1 0 0.5 R+1 0 -1 0 0 -2 0 0 + +proc _curvetoface {name} { + uplevel #0 mkedge $name $name + uplevel #0 wire $name $name + uplevel #0 mkface $name p0 $name +} + +plane p0 +_curvetoface outer +_curvetoface inner +_curvetoface round +mkface cut p0 cut + +bcommon teeth cut round +bcommon teeth teeth outer + +tcopy inner profile +set nbteeths 25 +for {set i 0} {$i < $nbteeths} {incr i} { + fuse profile profile teeth + trotate teeth 0 0 0 0 0 1 360./$nbteeths +} + +# sweep profile along curved shape + +polyline sp 0 0 0 0 0 H +cylinder ss 0 0 0 0 0 1 1 0 0 R +vertex v1 R 0 0 +vertex v2 R 0 H +line ll 0 0 a H +trim ll ll 0 sqrt(a*a+H*H) + +trotate v2 0 0 0 0 0 1 180.*a/pi +mkedge ee ll ss v1 v2 +wire gg ee + +donly profile sp gg +explode profile w +tcopy profile_1 profile_2 +tcopy profile_1 profile_3 +tscale profile_1 0 0 0 1./(R-2) +ttranslate profile_2 0 0 H/2 +tscale profile_2 0 0 H/2 4./(R-2) +ttranslate profile_3 0 0 H +tscale profile_3 0 0 H 3./(R-2) + +mksweep sp +setsweep -G gg 0 0 +addsweep profile_1 +addsweep profile_2 +addsweep profile_3 +vclear + +buildsweep base -S + +# make a shank +plane p1 0 0 H 0 0 1 +pcylinder shank p1 1.4 H +plane p2 0 0 H+1 0 0 1 +pcylinder sh2 p2 1.5 H-1 +bfuse shank shank sh2 +bfuse cutter base shank + +# check result +checkshape cutter + +# show result +incmesh cutter 0.01 +vdisplay cutter +vsetdispmode cutter 1 +incmesh profile_1 0.01; vdisplay profile_1 +vfit diff --git a/samples/tcl/drill.tcl b/samples/tcl/drill.tcl new file mode 100644 index 0000000000..03fe96d590 --- /dev/null +++ b/samples/tcl/drill.tcl @@ -0,0 +1,144 @@ +# Sample: creation of simple twist drill bit + +pload MODELING VISUALIZATION + +# drill parameters (some terms taken from http://www.drill-bits.cn/drill-bits-quality.asp) +dset R 4. ;# outer radius +dset D 2*R ;# diameter +dset Rr 3.5 ;# chisel radius (outer radius minus body clearance) + +dset b 1. ;# web thickness (approximate) +dset d b/2 + +dset H 80. ;# height of the spiral part +dset a 3.*pi ;# total angle of spiral rotation + +dset sigma 118 ;# point angle, in degrees + +# Create section profile by sequence of Boolean operations +# on simple planar objects +puts "Creating the drill section profile..." + +polyline rectangle1 d -R 0 R -R 0 -d R 0 -R R 0 d -R 0 + +circle circle1 0 0 0 0 0 1 R +mkedge circle1 circle1 +wire circle1 circle1 + +circle circle2 0 0 0 0 0 1 Rr +mkedge circle2 circle2 +wire circle2 circle2 + +plane p0 +mkface rectangle1 p0 rectangle1 +mkface circle1 p0 circle1 +mkface circle2 p0 circle2 + +bcommon sec rectangle1 circle1 +# note use of 'fuse' instead of 'bfuse' -- we need to get single face +fuse sec sec circle2 + +# Construct flute profile so as to have cutting lip straight after sharpening. +# Here we need to take into account spiral shift of the flute edge +# along the point length -- the way to do that is to make spiral +# from the desired cutting lip edge and then intersect it by plane +polyline lip d -d/2 0 d -R -R/tan(sigma/2*pi/180) + +polyline sp 0 0 0 0 0 H +cylinder cc 0 0 0 0 0 1 0 -4 0 4 +line ll 0 0 a 80 +trim ll ll 0 sqrt(a*a+H*H) + +vertex v1 0 -R 0 +vertex v2 0 -R H +trotate v2 0 0 0 0 0 1 180.*a/pi +mkedge ee ll cc v1 v2 +wire gg ee + +mksweep sp +setsweep -G gg 0 0 +addsweep lip +buildsweep spiral -S + +mkface f0 p0 -R R -R R +bsection sflute spiral f0 + +# here we rely on that section curve is parameterized from 0 to 1 +# and directed as cutting lip edge; +# note that this can change if intersection algorithm is modified +explode sflute e +mkcurve cflute sflute_1 +cvalue cflute 0. x0 y0 z0 +cvalue cflute 1. x1 y1 z1 +vertex vf0 x0 y0 z0 +vertex vf1 x1 y1 z1 + +# -- variant: replace curve by arc with start at x0,y0,z0 and end at x1,y1,z1, +# -- such that tanget at start point is along Y +#dset Rflute ((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))/(2*(x1-x0)) +#circle aflute x0+Rflute y0 0 0 0 1 Rflute +#mkedge sflute_1 aflute vf0 vf1 + +# make rounding in the flute; use circle with radius Rr/2 +circle cround x0+Rr/2 y0 0 0 0 1 Rr/2 +vertex vf3 x0+Rr y0 0 +mkedge sflute_2 cround vf3 vf0 +vertex vf2 R -R 0 +edge sflute_3 vf3 vf2 +edge sflute_4 vf2 vf1 +wire w2 sflute_1 sflute_2 sflute_3 sflute_4 +mkface flute p0 w2 + +# cut flute from profile +bcut sec sec flute +trotate flute 0 0 0 0 0 1 180. +bcut sec sec flute +donly sec + +# sweep profile to get a drill body +puts "Sweeping the profile..." + +mksweep sp +setsweep -G gg 0 0 +explode sec w +addsweep sec_1 +buildsweep base -S + +# sharpen the drill (see http://tool-land.ru/zatochka-sverla.php) +puts "Sharpening..." + +dset theta a*R/H*sin((90-sigma/2)*pi/180) +plane ax1 d 1.9*D "H+1.9*D/tan(pi/180.*sigma/2.)" 0 -1 -1 +pcone sh1 ax1 0 100*sin((sigma-90)/2*pi/180.) 100 +trotate sh1 0 0 0 0 0 1 -theta*180/pi +tcopy sh1 sh2 +trotate sh2 0 0 0 0 0 1 180 +box sh -D/2 -D/2 72 D D 20 +bcommon qq sh1 sh2 +bcut sharpener sh qq + +bcut body base sharpener + +# make a shank +puts "Making a shank..." +plane pl2 0 0 -40 0 0 1 +pcylinder shank pl2 4 40 +pcone transit R 0 R +plane pl3 0 0 -40 0 0 -0.5 +pcone tail pl3 R 0 0.5 +bfuse shank shank tail +bfuse shank shank transit +bfuse drill body shank + +# check result +checkshape drill + +# show result +puts "Displaying result..." +incmesh drill 0.01 +vdisplay drill +vsetdispmode drill 1 +vfit + +# show section and sweep path +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 diff --git a/tests/bugs/modalg_5/bug24758_1 b/tests/bugs/modalg_5/bug24758_1 new file mode 100644 index 0000000000..d7f0befc89 --- /dev/null +++ b/tests/bugs/modalg_5/bug24758_1 @@ -0,0 +1,96 @@ +puts "===========" +puts "OCC24758" +puts "===========" +puts "" +############################################################## +# Sample Draw scripts for demonstrating sweeping algorithm +############################################################## + +# parameters +dset R 10. ;# outer radius +dset H 20. ;# height of the spiral part +dset a 0.5*pi ;# total angle of spiral rotation + +# make profile +circle outer 0 0 0 0 0 1 R +circle inner 0 0 0 0 0 1 R-2 +circle round 3 6 0 0 0 1 5 +polyline cut -2 0 0 -2 R+1 0 0.5 R+1 0 -1 0 0 -2 0 0 + +proc _curvetoface {name} { + uplevel #0 mkedge $name $name + uplevel #0 wire $name $name + uplevel #0 mkface $name p0 $name +} + +plane p0 +_curvetoface outer +_curvetoface inner +_curvetoface round +mkface cut p0 cut + +bcommon teeth cut round +bcommon teeth teeth outer + +tcopy inner profile +set nbteeths 25 +for {set i 0} {$i < $nbteeths} {incr i} { + fuse profile profile teeth + trotate teeth 0 0 0 0 0 1 360./$nbteeths +} + +# sweep profile along curved shape +polyline sp 0 0 0 0 0 H +cylinder ss 0 0 0 0 0 1 1 0 0 R +vertex v1 R 0 0 +vertex v2 R 0 H +line ll 0 0 a H +trim ll ll 0 sqrt(a*a+H*H) + +trotate v2 0 0 0 0 0 1 180.*a/pi +mkedge ee ll ss v1 v2 +wire gg ee + +donly profile sp gg +explode profile w +tcopy profile_1 profile_2 +tcopy profile_1 profile_3 +tscale profile_1 0 0 0 1./(R-2) +ttranslate profile_2 0 0 H/2 +tscale profile_2 0 0 H/2 4./(R-2) +ttranslate profile_3 0 0 H +tscale profile_3 0 0 H 3./(R-2) + +mksweep sp +setsweep -G gg 0 0 +addsweep profile_1 +addsweep profile_2 +addsweep profile_3 +vclear + +buildsweep base -S + +# make a shank +plane p1 0 0 H 0 0 1 +pcylinder shank p1 1.4 H +plane p2 0 0 H+1 0 0 1 +pcylinder sh2 p2 1.5 H-1 +bfuse shank shank sh2 +bfuse cutter base shank + +# check result +checkshape cutter + +# show result +incmesh cutter 0.01 +vinit +vdisplay cutter +vsetdispmode cutter 1 +incmesh profile_1 0.01; vdisplay profile_1 +vfit + +# check square +renamevar cutter result +set square 1403.85 + +set only_screen 1 diff --git a/tests/bugs/modalg_5/bug24758_2 b/tests/bugs/modalg_5/bug24758_2 new file mode 100644 index 0000000000..8bc65f2bfc --- /dev/null +++ b/tests/bugs/modalg_5/bug24758_2 @@ -0,0 +1,152 @@ +puts "===========" +puts "OCC24758" +puts "===========" +puts "" +############################################################## +# Sample Draw scripts for demonstrating sweeping algorithm +############################################################## + +# drill parameters (some terms taken from http://www.drill-bits.cn/drill-bits-quality.asp) +dset R 4. ;# outer radius +dset D 2*R ;# diameter +dset Rr 3.5 ;# chisel radius (outer radius minus body clearance) + +dset b 1. ;# web thickness (approximate) +dset d b/2 + +dset H 80. ;# height of the spiral part +dset a 3.*pi ;# total angle of spiral rotation + +dset sigma 118 ;# point angle, in degrees + +# Create section profile by sequence of Boolean operations +# on simple planar objects +puts "Creating the drill section profile..." +polyline rectangle1 d -R 0 R -R 0 -d R 0 -R R 0 d -R 0 + +circle circle1 0 0 0 0 0 1 R +mkedge circle1 circle1 +wire circle1 circle1 + +circle circle2 0 0 0 0 0 1 Rr +mkedge circle2 circle2 +wire circle2 circle2 + +plane p0 +mkface rectangle1 p0 rectangle1 +mkface circle1 p0 circle1 +mkface circle2 p0 circle2 + +bcommon sec rectangle1 circle1 +# note use of 'fuse' instead of 'bfuse' -- we need to get single face +fuse sec sec circle2 + +# Construct flute profile so as to have cutting lip straight after sharpening. +# Here we need to take into account spiral shift of the flute edge +# along the point length -- the way to do that is to make spiral +# from the desired cutting lip edge and then intersect it by plane +polyline lip d -d/2 0 d -R -R/tan(sigma/2*pi/180) + +polyline sp 0 0 0 0 0 H +cylinder cc 0 0 0 0 0 1 0 -4 0 4 +line ll 0 0 a 80 +trim ll ll 0 sqrt(a*a+H*H) + +vertex v1 0 -R 0 +vertex v2 0 -R H +trotate v2 0 0 0 0 0 1 180.*a/pi +mkedge ee ll cc v1 v2 +wire gg ee + +mksweep sp +setsweep -G gg 0 0 +addsweep lip +buildsweep spiral -S + +mkface f0 p0 -R R -R R +bsection sflute spiral f0 + +# here we rely on that section curve is parameterized from 0 to 1 +# and directed as cutting lip edge; +# note that this can change if intersection algorithm is modified +explode sflute e +mkcurve cflute sflute_1 +cvalue cflute 0. x0 y0 z0 +cvalue cflute 1. x1 y1 z1 +vertex vf0 x0 y0 z0 +vertex vf1 x1 y1 z1 + +# -- variant: replace curve by arc with start at x0,y0,z0 and end at x1,y1,z1, +# -- such that tanget at start point is along Y +#dset Rflute ((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))/(2*(x1-x0)) +#circle aflute x0+Rflute y0 0 0 0 1 Rflute +#mkedge sflute_1 aflute vf0 vf1 + +# make rounding in the flute; use circle with radius Rr/2 +circle cround x0+Rr/2 y0 0 0 0 1 Rr/2 +vertex vf3 x0+Rr y0 0 +mkedge sflute_2 cround vf3 vf0 +vertex vf2 R -R 0 +edge sflute_3 vf3 vf2 +edge sflute_4 vf2 vf1 +wire w2 sflute_1 sflute_2 sflute_3 sflute_4 +mkface flute p0 w2 + +# cut flute from profile +bcut sec sec flute +trotate flute 0 0 0 0 0 1 180. +bcut sec sec flute +donly sec + +# sweep profile to get a drill body +puts "Sweeping the profile..." +mksweep sp +setsweep -G gg 0 0 +explode sec w +addsweep sec_1 +buildsweep base -S + +# sharpen the drill (see http://tool-land.ru/zatochka-sverla.php) +puts "Sharpening..." +dset theta a*R/H*sin((90-sigma/2)*pi/180) +plane ax1 d 1.9*D "H+1.9*D/tan(pi/180.*sigma/2.)" 0 -1 -1 +pcone sh1 ax1 0 100*sin((sigma-90)/2*pi/180.) 100 +trotate sh1 0 0 0 0 0 1 -theta*180/pi +tcopy sh1 sh2 +trotate sh2 0 0 0 0 0 1 180 +box sh -D/2 -D/2 72 D D 20 +bcommon qq sh1 sh2 +bcut sharpener sh qq + +bcut body base sharpener + +# make a shank +puts "Making a shank..." +plane pl2 0 0 -40 0 0 1 +pcylinder shank pl2 4 40 +pcone transit R 0 R +plane pl3 0 0 -40 0 0 -0.5 +pcone tail pl3 R 0 0.5 +bfuse shank shank tail +bfuse shank shank transit +bfuse drill body shank + +# check result +checkshape drill + +# show result +puts "Displaying result..." +incmesh drill 0.01 +vinit +vdisplay drill +vsetdispmode drill 1 +vfit + +# show section and sweep path +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 + +# check square +renamevar drill result +set square 3277.87 + +set only_screen 1 -- 2.20.1