13 Incheckningar

3 ändrade filer med 330 tillägg och 69 borttagningar
Delad Vy
  1. +250
    -69
      battery-case-generator.py
  2. +37
    -0
      svgturtle.py
  3. +43
    -0
      svgturtletest.py

+ 250
- 69
battery-case-generator.py Visa fil

@@ -10,13 +10,21 @@ parser.add_argument('--dimension', default=5, type=int, help='Grid dimension')
parser.add_argument('--height', type=float, help='Height of battery')
parser.add_argument('--hole', default='AA', help='Hole diameter (mm or A, AA, AAA)')
parser.add_argument('--kerf', default=.1, type=float, help='Kerf')
parser.add_argument('--horizontal-finger', default=10.0, type=float, help='Width of horizontal fingers')
parser.add_argument('--vertical-finger', default=5.0, type=float, help='Width of vertical fingers')
parser.add_argument('--corner-length', default=4, help='Length of stretch corner in material thicknesses')
parser.add_argument('--stretch', default=1.05, type=float, help='Reduction factor of stretch material')
parser.add_argument('--horizontal-finger', default=5.0, type=float, help='Width of horizontal fingers')
parser.add_argument('--vertical-finger', default=15.0, type=float, help='Width of vertical fingers')
parser.add_argument('--padding', default=1.5, type=float, help='Padding around holes')
parser.add_argument('--outside-padding', default=2, type=float, help='Extra padding between holes and wall')
parser.add_argument('--outside-padding', default=4.0, type=float, help='Extra padding between holes and wall')
parser.add_argument('--extra-height', default=2.0, type=float, help='Extra vertical space')
parser.add_argument('--thickness', default=3.0, type=float, help='Thickness of material')
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-width', default=.5, type=float, help='Spacing (in material thickness) between flex lines')
parser.add_argument('--flex-cut', default=5.0, type=float, help='Length (in material thickness) of flex cuts')
parser.add_argument('--flex-gap', default=1.0, type=float, help='Gap (in material thickness) between flex cuts')
parser.add_argument('--plug-play', default=0.8, 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

@@ -36,42 +44,93 @@ 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.interior_edge = args.grid*args.dimension*0.5+args.outside_padding
args.exterior_edge = args.interior_edge+args.thickness
args.interior_leg = (args.interior_edge-args.horizontal_finger-args.kerf)/2
args.n_hor_fingers = int(args.exterior_edge/args.horizontal_finger/2)
args.exterior_leg = (args.exterior_edge-(2*args.n_hor_fingers-1)*args.horizontal_finger+args.kerf)/2
args.exterior_slot = (args.exterior_edge-args.horizontal_finger+args.kerf)/2
args.n_ver_fingers = int(args.height/args.vertical_finger/2)
args.vertical_finger = args.height/args.n_ver_fingers/2

DIMX = 2.9*args.grid*args.dimension
DIMY = 3.8*args.grid*args.dimension
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 = min(args.opening_edge, .5*math.sqrt(3)*args.interior_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.45*args.height
args.slots = [top_slot, top_slot+15.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)

BOX = 2.0*args.exterior_edge+5.0
DIMX = 3.0*BOX
DIMY = 2.0*BOX+args.height+args.extra_height+3.0*args.thickness+5.0
PI3 = math.pi/3

HOLES = ''
SHAPES = ''
MARKS = ''

def draw_grid(cx, cy):
global HOLES
for row in range(-int(args.dimension/2), int((args.dimension+1)/2)):
cyr = cy+args.grid*row*math.sin(PI3)
num_col = args.dimension-abs(row)
cxr = cx-.5*args.grid*(num_col-1.0)
for col in range(num_col):
print('<circle cx="%.2f" cy="%.2f" r="%.2f" stroke="black" fill="none"/>' % (cxr+col*args.grid, cyr, args.radius))
HOLES += '<circle cx="%.2f" cy="%.2f" r="%.2f"/>\n' % (cxr+col*args.grid, cyr, args.radius)

def draw_plane(cx, cy, interior=False):
if interior:
def draw_disc(cx, cy, layer):
global HOLES, SHAPES, MARKS
turtle = svgturtle.SvgTurtle(cx, cy)
turtle.penup()
turtle.forward(args.disc_radius)