-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCNCShapePolygon.rb~
More file actions
210 lines (191 loc) · 6.2 KB
/
CNCShapePolygon.rb~
File metadata and controls
210 lines (191 loc) · 6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# CNCShapePolygon.rb
# Calculates objects with 1 to 1000 shapes
# centered on the specified location
# and mills those shapes.
#
# # See (C) notice in http://xdobs.com/cnc/CNCUtil/license.txt for license and copyright.
require 'cncMill'
require 'cncGeometry'
require 'cncShapeBase'
# Mill a Hexagon Pocket of the specified size
# returns the polygon object created to do the
# work after the do_mill operation has been
# called.
#####################################
def mill_hex_pocket(mill, cent_x, cent_y, diam, depth=nil)
#####################################
aPoly = CNCShapePolygon.new(mill, cent_x, cent_y, nil, diam=diam, num_sides=6, depth=depth, degree_inc=nil)
aPoly.do_mill()
return aPoly
end #meth
# Primitive: Mills the outline of a polygon at the specified
# diameter. If cutter_compensation is = true then
# it will automatically compensate for cutter
# diameters. This method will not properly
# handled multiple passes to reach proper depth.
# use the class method if deep pockets wit
# multiple passess are needed.
#############################################
def mill_polygon(mill, cent_x, cent_y, diam,
no_sides, depth=nil, cutter_comp=false)
#############################################
if cutter_comp == true
diam -= mill.bit_radius
end #if
#mill.retract()
side_count = 0
curr_angle = 0.0
radius = diam / 2
degree_inc = 360 / no_sides
while (curr_angle <= 360)
cp = calc_point_from_angle(cent_x, cent_y, curr_angle, radius)
mill.move(cp.x, cp.y)
if (side_count == 0)
mill.plung(depth)
end #if
side_count = side_count + 1
curr_angle += degree_inc
end #while
end # meth
# a class that mills out polygon pockets.
# and Polygon outlines
# *****************************************
class CNCShapePolygon
# *****************************************
include CNCShapeBase
extend CNCShapeBase
# - - - - - - - - - - - - - - - - - -
def initialize(mill, cent_x, cent_y, start_z, diam=0.25, num_sides=6,
depth=nil, degree_inc=nil)
# - - - - - - - - - - - - - - - - - -
#print "L66: mill= ", mill
base_init(mill,cent_x,cent_y, start_z,depth)
@diam = 0.25
@degree_inc = 0.0
@pocket_flag = true
@island_diam = 0.0
@num_sides = num_sides
end #meth
# - - - - - - - - - - - - - - - - - -
def degree_inc=(aNum)
# - - - - - - - - - - - - - - - - - -
@degree_inc = aNum
return self
end #if
# mill out as a outline
# - - - - - - - - - - - - - - - - - -
def set_outline
# - - - - - - - - - - - - - - - - - -
@pocket_flag = false
return self
end #if
# mill out as a pocket
# - - - - - - - - - - - - - - - - - -
def set_pocket
# - - - - - - - - - - - - - - - - - -
@pocket_flag = true
return self
end #if
# mills out a polygon object that
# has been loaded with essential data.
# The assumption is that cutter_compensation
# should be used to obtain a whole that exactly
# matches specified diameter. If the pocket
# is deep then multiple passes will be used
# to reach the depth. If pocket_flag is equal
# to true then the entire polygon will be milled
# out but if it is false then only the outline will be milled.
# - - - - - - - - - - - - -
def do_mill
# - - - - - - - - - - - - -
mill.retract()
target_depth = @depth
print "(polygon do_mill target_depth=", target_depth, " mill.cut_depth_inc_curr=", mill.cut_depth_inc_curr, ")\n"
if target_depth.abs <= mill.cut_depth_inc_curr.abs
print "(polygon do_mill single pass cut )\n"
do_mill_s(target_depth)
else
# Need multiple passes
print "(polygon do_mill single pass cut )\n"
tdepth = 0 - mill.cut_depth_inc_curr.abs
print "(polygon do_mill tdepth=", tdepth, ")\n"
while true
print "(L121: tdepth=", tdepth, ")\n"
do_mill_s(tdepth)
if (tdepth == target_depth)
break # have reached target depth
end #if
tdepth -= mill.cut_depth_inc_curr.abs
if (tdepth.abs > target_depth.abs)
# want to make sure final cut doesn't
# go past tarteget.
tdepth = target_depth
end #if
end #while
end #else
end #meth
# Used by do_mill to do most of the
# milling. It driectly plunges to the
# specified depth and begins the milling
# depending on do_mill to properly handel
# multi layer milling.
# - - - - - - - - - - - - -
def do_mill_s(tmp_depth)
# - - - - - - - - - - - - -
tmp_max_diam = @diam
if (@cutter_comp == true)
tmp_max_diam -= @mill.bit_radius
end #if
if @pocket_flat == false
curr_diam = tmp_max_diam
# we only need on circle
# rather than spiraling
else
curr_diam = bit_radius
end #if
while true
mill_polygon(
mill = @mill,
cent_x = @x,
cent_y = @y,
diam = curr_diam,
no_sides = @num_sides,
depth = tmp_depth,
cutter_comp = false)
if (curr_diam == tmp_max_diam)
# we are done milling because
# we got an exact match on
# our target diameter
break
end
curr_diam += mill.cut_increment
if (curr_diam > tmp_max_diam)
curr_diam = tmp_max_diam
end #if
end #while
end #meth
# - - - - - - - - - - - - - - - - - - - -
def circ_array(circ_x, circ_y, radius, beg_degree=0.0, end_degree = 360.0, num_elem=6)
# - - - - - - - - - - - - - - - - - - - -
sweep_angle = end_degree - beg_degree
degree_inc = sweep_angle / num_elem
curr_angle = beg_degree
# illustrate an easy way to get a
# repeating array of arc pockets
for cc in (1..num_elem)
cp = calc_point_from_angle(
circ_x, circ_y, curr_angle, radius)
@x = cp.x
@y = cp.y
do_mill()
mill.retract()
if (curr_angle >= end_degree)
break
end #if
curr_angle += degree_inc
if (curr_angle > 360)
curr_angle = curr_angle % 360
end #if
end #for
end #meth
end #class