-
Notifications
You must be signed in to change notification settings - Fork 0
/
genCarrier.py
executable file
·445 lines (318 loc) · 12 KB
/
genCarrier.py
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
#!/usr/bin/env python3
# BSD 3-Clause License
#
# Copyright (c) 2020, Adam Kunen
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# Generates laser cutter SVG files to create negative carriers for the
# Beseler 23C enlarger
#
# See README
#
import math
#
# Define parameters of the overall paddle geometery
# regardless of film size
#
# Resolution of drawing arc
arc_resolution = 0.003
# Width of line in svg file
stroke_width = 0.01
# bounding box on entire design
img_width = 8.6
img_height = 6.5
# Major diameter of paddle
large_diam = 6.375
large_rad = large_diam/2.0
# Handle parameters
handle_width = 1.135
handle_length = 8.450 - large_diam
aligner_gap = 0.005
# Side of bottom ring
ring_diam = 4.725
# Large diam to handle fillet raidus
handle_fillet = 0.750
# handle end radius
handle_rad = 0.150
# create centerpoint for carrier
# this is the center of the large diameter, and the center of the image cutout
x_center = img_height/2.0
y_center = x_center
#
# Output opening tags
#
def makeHeader():
s = "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">"
s += "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xml:space=\"preserve\" width=\"%fin\" height=\"%fin\" viewBox=\"%f %f %f %f\">" % (img_width, img_height, 0.0, 0.0, img_width, img_height)
s += "\n"
s += "<!-- Generated by genCarrier.py https://github.com/ajkunen/beseler23c -->\n\n"
return s
#
# Close out svg file
#
def makeFooter():
return "</svg>\n"
#
#
#
def makeStroke(stroke_path, close_end=True):
if close_end:
return " <path stroke=\"black\" fill=\"none\" stroke-width=\"%.5f\" d=\"%s z\" />\n\n" % (stroke_width, stroke_path)
else:
return " <path stroke=\"black\" fill=\"none\" stroke-width=\"%.5f\" d=\"%s\" />\n\n" % (stroke_width, stroke_path)
#
# Draw outline of partial arc given center, radius starting and ending angle (radians)
# if moveTo is True, it lift's the pen, otherwise it just continues path
#
def drawArc(center, rad, theta0, theta1, moveTo):
one_degree = (2.0*math.pi)/360.0
dtheta = math.atan(arc_resolution/rad)
num_segments = 1+int(abs(theta1-theta0)/dtheta)
dtheta = (theta1-theta0)/num_segments
path = ""
for i in range(0, num_segments):
theta_i = theta0 + i*dtheta
theta_i1 = theta_i + dtheta
if i == 0 and moveTo:
point0 = [center[0]+math.cos(theta_i)*rad,
center[1]+math.sin(theta_i)*rad]
path += " M%f,%f" % (point0[0], point0[1])
point1 = [center[0]+math.cos(theta_i1)*rad,
center[1]+math.sin(theta_i1)*rad]
path += " L%f,%f" % (point1[0], point1[1])
return path
#
# Draws a rectangle, lifting pen to start
#
# p is the location of upper-left corner
#
def drawRect(p, width, height):
path = "M%f,%f L%f,%f L%f,%f L%f,%f L%f,%f" % (
p[0], p[1],
p[0]+width, p[1],
p[0]+width, p[1]+height,
p[0], p[1]+height,
p[0], p[1])
return path
#
# Creates outline of paddle
#
def makePaddleOutline():
s = "<!-- Paddle outline -->\n"
#compute angle which handle intersects large diameter
handle_angle = math.tan(handle_width/large_diam)
# draw handle fillet
handle_theta0 = math.asin( (handle_width/2+handle_fillet) / (large_rad+handle_fillet) )
handle_theta1 = math.pi/2 - handle_theta0
fillet_dist = handle_fillet + large_rad
fillet_centerA = [fillet_dist*math.cos(handle_theta0) + x_center,
y_center - fillet_dist*math.sin(handle_theta0)]
fillet_centerB = [fillet_dist*math.cos(handle_theta0) + x_center,
fillet_dist*math.sin(handle_theta0) + y_center]
handle_angle = handle_theta0
outline = drawArc([x_center, y_center], large_diam/2.0, handle_angle, 2.0*math.pi-handle_angle, True)
# draw handle fillet
outline += drawArc(fillet_centerA, handle_fillet, 1.5+handle_theta1, 0.5*math.pi, False)
# draw handle corner rounds
handle_end = handle_length+x_center+large_diam/2.0
outline += drawArc([handle_end-handle_rad, y_center-0.5*handle_width+handle_rad], handle_rad, -0.5*math.pi, 0.0, False)
outline += drawArc([handle_end-handle_rad, y_center+0.5*handle_width-handle_rad], handle_rad, 0.0, 0.5*math.pi, False)
# draw handle fillet
outline += drawArc(fillet_centerB, handle_fillet, 1.5*math.pi, 1.5*math.pi-handle_theta1, False)
# draw entire outline
s += makeStroke(outline)
return s
#
# Draw hole to make it easier to separate top from bottom
#
def makePaddleSeparatorHoles():
s = "<!-- Paddle separator holes -->\n"
R = handle_width/2 * 0.6
holes = drawArc([x_center+large_rad+handle_length-handle_width/2, y_center], R, 0, 2*math.pi, True)
holes += drawArc([x_center-large_rad+R*1.2, y_center], R*0.8, 0, 2*math.pi, True)
s += makeStroke(holes)
return s
#
# Draw film cutout
#
def makeFilmCutout(cut_width, cut_height, film_width, aligner_diam):
s = "<!-- Film cutout %.4fx%.4f\" -->\n" % (cut_width, cut_height)
# draw cutout
cut_x = x_center - cut_height/2
cut_y = y_center - cut_width/2
s += makeStroke("M%f,%f l%f,0 l0,%f l%f,0" % (
cut_x, cut_y,
cut_height,
cut_width,
-cut_height))
return s
#
# Draw aligners
#
def makeAligners(cut_width, cut_height, film_width, aligner_diam, scale):
s = "<!-- Aligner pins %.4f\" diam -->\n" % (aligner_diam*scale)
cut_x = x_center - cut_height/2
cut_y = y_center - cut_width/2
aligners = ""
aligner_rad = aligner_diam/2
# aligner 0
p = [x_center-film_width/2-aligner_rad, y_center-cut_width/2+aligner_rad]
aligners += drawArc(p, aligner_rad*scale, 0, 2*math.pi, True)
# aligner 1
p = [x_center+film_width/2+aligner_rad, y_center-cut_width/2+aligner_rad]
aligners += drawArc(p, aligner_rad*scale, 0, 2*math.pi, True)
# aligner 2
p = [x_center-film_width/2-aligner_rad, y_center+cut_width/2-aligner_rad]
aligners += drawArc(p, aligner_rad*scale, 0, 2*math.pi, True)
# aligner 3
p = [x_center+film_width/2+aligner_rad, y_center+cut_width/2-aligner_rad]
aligners += drawArc(p, aligner_rad*scale, 0, 2*math.pi, True)
# draw aligners
s += makeStroke(aligners)
return s
#
# Draw ring
#
def makeRing():
s = "<!-- Ring OD=%.4f\", ID=%.4f\" -->\n" % (ring_diam, ring_diam-1.0)
ring = drawArc([x_center, y_center], ring_diam/2, 0.0, 2*math.pi, True)
ring += drawArc([x_center, y_center], ring_diam/2-0.5, 0.0, 2*math.pi, True)
s += makeStroke(ring)
return s
#
# Draw ring alignment holes
#
def makeRingAligners():
s = "<!-- Ring alignment holes -->\n"
off = ring_diam/2 - 0.25
holes = drawArc([x_center, y_center-off], 0.125, 0.0, 2*math.pi, True)
holes += drawArc([x_center, y_center+off], 0.125, 0.0, 2*math.pi, True)
holes += drawArc([x_center-off, y_center], 0.125, 0.0, 2*math.pi, True)
holes += drawArc([x_center+off, y_center], 0.125, 0.0, 2*math.pi, True)
s += makeStroke(holes)
return s
#
# Draw extra alignment pins
#
def makeExtraPins(pin_diam):
s = "<!-- Extra alignment pins -->\n"
off = (large_rad-0.625)/math.sqrt(2.0)
holes = drawArc([x_center-off, y_center-off], pin_diam/2, 0.0, 2*math.pi, True)
holes += drawArc([x_center-off, y_center+off], pin_diam/2, 0.0, 2*math.pi, True)
holes += drawArc([x_center+off, y_center-off], pin_diam/2, 0.0, 2*math.pi, True)
holes += drawArc([x_center+off, y_center+off], pin_diam/2, 0.0, 2*math.pi, True)
s += makeStroke(holes)
return s
#
# Create top layer
#
def genTop(name, cut_width, cut_height, film_width, aligner_diam, extra_pins):
s = makeHeader()
s += makePaddleOutline()
s += makeFilmCutout(cut_width, cut_height, film_width, aligner_diam)
s += makeAligners(cut_width, cut_height, film_width, aligner_diam, 1.0)
if extra_pins:
s += makeExtraPins(0.750)
s += makeFooter()
# write to file
fh = open(name, "w")
fh.write(s)
#
# Create bottom layer
#
def genBottom(name, cut_width, cut_height, film_width, aligner_diam, extra_pins):
s = makeHeader()
s += makePaddleOutline()
s += makePaddleSeparatorHoles()
s += makeFilmCutout(cut_width, cut_height, film_width, aligner_diam)
s += makeAligners(cut_width, cut_height, film_width, aligner_diam, 0.5)
if extra_pins:
s += makeExtraPins(0.375)
s += makeRingAligners()
s += makeFooter()
# write to file
print(" - writing %s" % name)
fh = open(name, "w")
fh.write(s)
#
# Create ring layer
#
def genRing(name, cut_width, cut_height, film_width, aligner_diam, extra_pins):
s = makeHeader()
s += makeRing()
s += makeRingAligners()
s += makeFooter()
# write to file
print(" - writing %s" % name)
fh = open(name, "w")
fh.write(s)
#
# Create all debugging layer
#
def genAll(name, cut_width, cut_height, film_width, aligner_diam, extra_pins):
s = makeHeader()
s += makePaddleOutline()
s += makePaddleSeparatorHoles()
s += makeFilmCutout(cut_width, cut_height, film_width, aligner_diam)
s += makeAligners(cut_width, cut_height, film_width, aligner_diam, 1.0)
s += makeAligners(cut_width, cut_height, film_width, aligner_diam, 0.5)
if extra_pins:
s += makeExtraPins(0.750)
s += makeExtraPins(0.375)
s += makeRing()
s += makeRingAligners()
s += makeFooter()
# write to file
print(" - writing %s" % name)
fh = open(name, "w")
fh.write(s)
#
# Create all 3 layers for carrier
#
def genCarrier(name, cut_width, cut_height, film_width, aligner_diam, extra_pins):
# Create Top
genTop("%s_top.svg"%name, cut_width, cut_height, film_width, aligner_diam, extra_pins)
# Create Bottom
genBottom("%s_bottom.svg"%name, cut_width, cut_height, film_width, aligner_diam, extra_pins)
# Create Ring
genRing("%s_ring.svg"%name, cut_width, cut_height, film_width, aligner_diam, extra_pins)
# Create single drawing with all 3 layers for debugging
genAll("%s_all.svg"%name, cut_width, cut_height, film_width, aligner_diam, extra_pins)
#
# Main: Draw all designs
#
if __name__ == "__main__":
print("Besseler 23C Film Carrier Generator")
print(" - Creating 35mm standard carrier")
genCarrier(name="23C_35mm", cut_width=1.425, cut_height=0.945, film_width=1.378+0.010, aligner_diam=0.500, extra_pins=True)
print(" - Creating 120 film 6x7cm carrier")
genCarrier(name="23C_120_6x7cm", cut_width=2.675, cut_height=2.200, film_width=2.425+0.010, aligner_diam=0.750, extra_pins=False)
print(" - Creating 120 film 6x6cm carrier")
genCarrier(name="23C_120_6x6cm", cut_width=2.200, cut_height=2.200, film_width=2.425+0.010, aligner_diam=0.750, extra_pins=False)
print("done")