Browse Source

Automatically adjust padding; make plug hexagonal

main
Matthias Neeracher 4 months ago
parent
commit
cbc847ea42
1 changed files with 39 additions and 33 deletions
  1. +39
    -33
      battery-case-generator.py

+ 39
- 33
battery-case-generator.py View File

@@ -21,6 +21,7 @@ parser.add_argument('--thickness', default=3.0, type=float, help='Thickness of m
parser.add_argument('--lid', default=0.2, type=float, help='How much extra play to give the lid')
parser.add_argument('--tooth', default=0.8, type=float, help='How much to round the edges of the teeth')
parser.add_argument('--flex-granularity', default=1.8, type=float, help='How much space to give a pair of flex lines')
parser.add_argument('--plug-play', default=0.3, type=float, help='How much smaller to make the plug than the hole')
parser.add_argument('--verbose', action='store_true', help='Print computed parameter values')
args = parser.parse_args()
assert (args.dimension % 2) == 1
@@ -41,28 +42,36 @@ else:
args.hole = float(args.hole)
assert(args.height != None)

args.kerf2 = args.kerf/2
args.grid = args.hole+args.padding
args.radius = args.hole/2
args.corner = args.corner_length*args.thickness
args.corner_s = args.corner*args.stretch
args.corner_radius = 3*args.corner_s/math.pi
args.plug_radius = args.corner_radius-args.thickness
args.corner_inset = args.corner_s*math.sqrt(3)/math.pi
args.plug_inset = args.plug_radius/math.sqrt(3)
args.interior_edge = args.grid*args.dimension*0.5+args.outside_padding
args.plug_edge = args.interior_edge-args.thickness
args.disc_radius = 0.45*(math.sqrt(3)-1)*args.plug_edge+args.plug_inset
args.exterior_edge = args.interior_edge+2.0*args.thickness
args.interior_leg = (args.interior_edge-args.horizontal_finger-args.kerf)/2-args.corner_inset
finger_length = args.interior_edge-2.0*args.corner_inset
args.n_hor_fingers = max(int(finger_length/args.horizontal_finger/2), 1)
args.exterior_leg = (finger_length-(2*args.n_hor_fingers-1)*args.horizontal_finger+args.kerf)/2
args.wall_leg = (args.interior_edge-args.corner-(2*args.n_hor_fingers-1)*args.horizontal_finger+args.kerf)/2
args.exterior_slot = (args.interior_edge-args.horizontal_finger+args.kerf)/2
args.n_ver_fingers = int((args.height+args.extra_height)/args.vertical_finger)
top_slot = args.extra_height+args.thickness+0.5*args.height
args.slots = [top_slot, top_slot+10.0]
SUITABLE = False
while not SUITABLE:
args.kerf2 = args.kerf/2
args.grid = args.hole+args.padding
args.radius = args.hole/2
args.corner = args.corner_length*args.thickness
args.corner_s = args.corner*args.stretch
args.corner_radius = 3*args.corner_s/math.pi
args.plug_radius = args.corner_radius-args.thickness
args.corner_inset = args.corner_s*math.sqrt(3)/math.pi
args.plug_inset = args.plug_radius/math.sqrt(3)
args.interior_edge = args.grid*args.dimension*0.5+args.outside_padding
args.opening_edge = args.interior_edge-args.thickness
args.plug_edge = args.opening_edge-args.plug_play
args.disc_radius = 0.45*(math.sqrt(3)-1)*args.plug_edge+args.plug_inset
args.exterior_edge = args.interior_edge+2.0*args.thickness
args.interior_leg = (args.interior_edge-args.horizontal_finger-args.kerf)/2-args.corner_inset
finger_length = args.interior_edge-2.0*args.corner_inset
args.n_hor_fingers = max(int(finger_length/args.horizontal_finger/2), 1)
args.exterior_leg = (finger_length-(2*args.n_hor_fingers-1)*args.horizontal_finger+args.kerf)/2
args.wall_leg = (args.interior_edge-args.corner-(2*args.n_hor_fingers-1)*args.horizontal_finger+args.kerf)/2
args.exterior_slot = (args.interior_edge-args.horizontal_finger+args.kerf)/2
args.n_ver_fingers = int((args.height+args.extra_height)/args.vertical_finger)
top_slot = args.extra_height+args.thickness+0.5*args.height
args.slots = [top_slot, top_slot+10.0]
if args.exterior_leg > 2:
SUITABLE=True
else:
args.outside_padding += .5
args.padding += .2 # Try again with more padding

if args.verbose:
print(args, file=sys.stderr)
@@ -104,7 +113,9 @@ def draw_plane(cx, cy, layer):
global HOLES, SHAPES, MARKS
if layer=='interior':
edge = args.interior_edge
elif layer=='plug' or layer=='plug_mark' or layer=='opening':
elif layer=='opening':
edge = args.opening_edge
elif layer=='plug' or layer=='plug_mark':
edge = args.plug_edge
else:
edge = args.exterior_edge
@@ -131,19 +142,14 @@ def draw_plane(cx, cy, layer):
turtle.forward(edge-2.0*args.corner_inset)
turtle.circle(-args.corner_radius, 60)
elif layer=='plug' or layer=='plug_mark':
turtle.forward(args.plug_inset)
turtle.pendown()
for side in range(6):
for side in range(3):
turtle.forward(0.5*edge)
turtle.right(90)
turtle.circle(0.5*edge-args.plug_inset, 180)
turtle.circle(0.5*edge, 120)
turtle.right(90)
turtle.circle(-args.plug_radius, 60)
elif layer=='opening':
turtle.forward(args.plug_inset)
turtle.pendown()
for side in range(6):
turtle.forward(edge-2.0*args.plug_inset)
turtle.circle(-args.plug_radius, 60)
turtle.forward(0.5*edge)
turtle.right(60)
else:
turtle.pendown()
for side in range(6):


Loading…
Cancel
Save