Rounded hexagons for interior planes

This commit is contained in:
Matthias Neeracher 2021-11-24 03:16:53 +01:00
parent bf1433afe7
commit d2a9a0b8e0
2 changed files with 47 additions and 6 deletions

View File

@ -10,10 +10,12 @@ 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('--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=5.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, type=float, help='Extra padding between holes and wall')
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')
@ -39,9 +41,13 @@ else:
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.corner_inset = args.corner_s*math.sqrt(3)/math.pi
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.interior_leg = (args.interior_edge-args.horizontal_finger-args.kerf)/2-args.corner_inset
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
@ -49,6 +55,8 @@ args.n_ver_fingers = int(args.height/args.vertical_finger/2)
args.vertical_finger = args.height/args.n_ver_fingers/2
args.slots = [args.vertical_finger*2.5-args.thickness*0.5, args.vertical_finger*4.5-args.thickness*0.5]
print(args, file=sys.stderr)
DIMX = 5.0*args.grid*args.dimension
DIMY = 3.0*args.grid*args.dimension
PI3 = math.pi/3
@ -75,8 +83,9 @@ def draw_plane(cx, cy, interior=False):
turtle.penup()
turtle.forward(edge)
turtle.right(120)
turtle.pendown()
if interior:
turtle.forward(args.corner_inset)
turtle.pendown()
for side in range(5):
turtle.forward(args.interior_leg)
turtle.left(90)
@ -87,9 +96,11 @@ def draw_plane(cx, cy, interior=False):
turtle.forward(args.thickness)
turtle.left(90)
turtle.forward(args.interior_leg)
turtle.right(60)
turtle.forward(args.interior_edge)
turtle.circle(-args.corner_radius, 60, 5)
turtle.forward(args.interior_edge-2.0*args.corner_inset)
turtle.circle(-args.corner_radius, 60, 5)
else:
turtle.pendown()
for side in range(5):
for finger in range(args.n_hor_fingers):
turtle.forward(args.exterior_leg if finger == 0 else args.horizontal_finger+args.kerf)

View File

@ -40,6 +40,36 @@ class SvgTurtle():
def right(self, angle):
self.heading = (self.heading + angle*self.cvtangle) % math.tau
def circle(self, radius, extent=360, steps=None):
if steps:
w = 1.0*extent/steps
w2 = 0.5*w
l = 2.0*radius*math.sin(w2*math.pi/180.0)
if radius < 0:
l, w, w2 = -l, -w, -w2
self.left(w2)
for i in range(steps):
self.forward(l)
self.left(w)
self.right(w2)
else:
ra = extent*self.cvtangle
h = self.heading-.5*ra if radius>0 else self.heading+.5*ra
dx = abs(radius)*math.cos(h)
dy = abs(radius)*math.sin(h)
lg = 1 if extent >= 180 else 0
sw = 0 if radius > 0 else 1
if self.pen:
self.path += " a %.2f %.2f %.2f %d %d %.2f %.2f" % (radius, radius, extent, lg, sw, dx, dy)
elif self.path != '':
self.path += " m %.2f, %.2f" % (dx, dy)
self.x += dx
self.y += dy
if radius > 0:
self.left(extent)
else:
self.right(extent)
def to_s(self):
return self.path