; poly_pocket - filled polygon pocket, concentric outward from center. ; apothem = flat-to-flat distance / 2 (center to midpoint of edge). ; rotation in degrees: 0 places first vertex on +X axis, CCW positive. ; Requires globals: #<_z_top>, #<_z_bot> ; Requires tool loaded (uses #5410 for diameter) ; Optional globals: #<_z_clearance>, #<_stepover> o sub ; o call [mode] [x][y] [n_sides] [apothem] [rotation] [fincut] ; #1=mode #2=x #3=y #4=n_sides #5=apothem #6=rotation #7=fincut # = [FIX[#1/1] MOD 2 EQ 1] # = [FIX[#1/1] MOD 2 EQ 0] G90 G90.1 M101 G17 # = #5410 # = [#/2] o1 if [EXISTS[#<_z_clearance>]] # = #<_z_clearance> o1 else # = #<_z_top> o1 endif o2 if [EXISTS[#<_stepover>]] # = #<_stepover> o2 else # = [#*0.4] o2 endif # = #7 o13 if [# LT 0] # = [0 - #] o13 endif # = [#5 - # - #] # = [360/#4] o14 if [# LE 0] o15 return o14 endif o16 if [#] # = 1 o16 else # = -1 o16 endif G0 Z# G0 X#2 Y#3 G0 Z#<_z_top> G1 Z#<_z_bot> # = # o30 while [# LT #] # = [# / COS[180/#4]] G1 X[#2 + #*COS[#6]] Y[#3 + #*SIN[#6]] # = 1 o31 while [# LE #4] # = [#6 + #*#*#] G1 X[#2 + #*COS[#]] Y[#3 + #*SIN[#]] # = [# + 1] o31 endwhile # = [# + #] o30 endwhile ; final pass at max_apothem # = [# / COS[180/#4]] G1 X[#2 + #*COS[#6]] Y[#3 + #*SIN[#6]] # = 1 o40 while [# LE #4] # = [#6 + #*#*#] G1 X[#2 + #*COS[#]] Y[#3 + #*SIN[#]] # = [# + 1] o40 endwhile G0 Z# o endsub M2