Skip to content

Instantly share code, notes, and snippets.

@mkeeter
Created Jun 8, 2013
Embed
What would you like to do?
#
# gik.cad
#
# GIK
#
# Neil Gershenfeld
# 8/1/07
#
#
# Ported to kokopelli by Matt Keeter
# 6/13
#
#
# Library imports
#
from koko.lib.shapes import *
from math import sqrt
#
# design parameters
#
w = 0.13 # slot width
l = 0.3 # slot length
c = 0.03 # champher length
s = .1 # part space
xstart = .5 # xmin
ystart = -.5 # ymax
slot = rectangle(0,l/2,-w/2,w/2)
slot = add(slot,right_triangle(0,w/2,c))
slot = add(slot,reflect_y(right_triangle(0,w/2,c),0))
double_slot = rectangle(0,l+w/2,-w/2,w/2)
double_slot = add(double_slot,right_triangle(0,w/2,c))
double_slot = add(double_slot,reflect_y(right_triangle(0,w/2,c),0))
square_gik = rectangle(-l-w/2,l+w/2,-l-w/2,l+w/2)
square_gik = subtract(square_gik,translate(slot,-l-w/2,0,0))
square_gik = subtract(square_gik,translate(reflect_x(slot,0),l+w/2,0,0))
square_gik = subtract(square_gik,translate(reflect_xy(slot),0,-l-w/2,0))
square_gik = subtract(square_gik,translate(reflect_xy(reflect_x(slot,0)),0,l+w/2,0))
dxy = 2*l+w+s
x0 = xstart
y0 = ystart
square_giks = translate(square_gik,x0+.5*dxy,y0-.5*dxy,0)
square_giks = add(square_giks,translate(square_gik,x0+1.5*dxy,y0-.5*dxy,0))
square_giks = add(square_giks,translate(square_gik,x0+.5*dxy,y0-1.5*dxy,0))
square_giks = add(square_giks,translate(square_gik,x0+1.5*dxy,y0-1.5*dxy,0))
square_giks = add(square_giks,translate(square_gik,x0+.5*dxy,y0-2.5*dxy,0))
square_giks = add(square_giks,translate(square_gik,x0+1.5*dxy,y0-2.5*dxy,0))
square_giks = add(square_giks,translate(square_gik,x0+.5*dxy,y0-3.5*dxy,0))
square_giks = add(square_giks,translate(square_gik,x0+1.5*dxy,y0-3.5*dxy,0))
gik = square_giks
pi_gik = rectangle(-l-w/2,l+w/2,-l-w/2,l+w/2)
pi_gik = subtract(pi_gik,translate(slot,-l-w/2,0,0))
pi_gik = subtract(pi_gik,translate(reflect_x(slot,0),l+w/2,0,0))
pi_gik = subtract(pi_gik,translate(reflect_xy(double_slot),0,-l-w/2,0))
x0 = x0 + 2.5*dxy
pi_giks = translate(pi_gik,x0,y0-.5*dxy,0)
pi_giks = add(pi_giks,translate(pi_gik,x0,y0-1.5*dxy,0))
pi_giks = add(pi_giks,translate(pi_gik,x0,y0-2.5*dxy,0))
pi_giks = add(pi_giks,translate(pi_gik,x0,y0-3.5*dxy,0))
gik = add(gik,pi_giks)
tee_gik = rectangle(-l-w/2,l+w/2,-l-w/2,3*w/2)
tee_gik = subtract(tee_gik,translate(slot,-l-w/2,0,0))
tee_gik = subtract(tee_gik,translate(reflect_x(slot,0),l+w/2,0,0))
tee_gik = subtract(tee_gik,translate(reflect_xy(slot),0,-l-w/2,0))
x0 = x0 + dxy
dy0 = 3*w/2+s/2
dy = l+2*w+s
tee_giks = translate(tee_gik,x0,y0-dy0,0)
tee_giks = add(tee_giks,translate(tee_gik,x0,y0-dy0-dy,0))
tee_giks = add(tee_giks,translate(tee_gik,x0,y0-dy0-2*dy,0))
tee_giks = add(tee_giks,translate(tee_gik,x0,y0-dy0-3*dy,0))
tee_giks = add(tee_giks,translate(tee_gik,x0,y0-dy0-4*dy,0))
gik = add(gik,tee_giks)
corner_gik = rectangle(-l-w/2,3*w/2,-l-w/2,3*w/2)
corner_gik = subtract(corner_gik,translate(slot,-l-w/2,0,0))
corner_gik = subtract(corner_gik,translate(reflect_xy(slot),0,-l-w/2,0))
x0 = x0 + dxy
dx0 = l+2*w+s
corner_giks = translate(corner_gik,x0,y0-dy0,0)
corner_giks = add(corner_giks,translate(corner_gik,x0,y0-dy0-dy,0))
corner_giks = add(corner_giks,translate(corner_gik,x0,y0-dy0-2*dy,0))
corner_giks = add(corner_giks,translate(corner_gik,x0,y0-dy0-3*dy,0))
corner_giks = add(corner_giks,translate(corner_gik,x0,y0-dy0-4*dy,0))
corner_giks = add(corner_giks,translate(corner_gik,x0+dx0,y0-dy0,0))
corner_giks = add(corner_giks,translate(corner_gik,x0+dx0,y0-dy0-dy,0))
corner_giks = add(corner_giks,translate(corner_gik,x0+dx0,y0-dy0-2*dy,0))
corner_giks = add(corner_giks,translate(corner_gik,x0+dx0,y0-dy0-3*dy,0))
corner_giks = add(corner_giks,translate(corner_gik,x0+dx0,y0-dy0-4*dy,0))
gik = add(gik,corner_giks)
connector_gik = rectangle(-l,l,-3*w/2,3*w/2)
connector_gik = subtract(connector_gik,translate(slot,-l,0,0))
connector_gik = subtract(connector_gik,translate(reflect_x(slot,0),l,0,0))
x0 = x0 + 2*dx0 - w/2
dx = 2*l+s
dy0 = 3*w/2 + s/2
dy = 3*w+s
connector_giks = translate(connector_gik,x0,y0-dy0,0)
connector_giks = add(connector_giks,translate(connector_gik,x0,y0-dy0-dy,0))
connector_giks = add(connector_giks,translate(connector_gik,x0,y0-dy0-2*dy,0))
connector_giks = add(connector_giks,translate(connector_gik,x0,y0-dy0-3*dy,0))
connector_giks = add(connector_giks,translate(connector_gik,x0,y0-dy0-4*dy,0))
connector_giks = add(connector_giks,translate(connector_gik,x0,y0-dy0-5*dy,0))
gik = add(gik,connector_giks)
r = l + w/(2*sqrt(3))
round_gik = circle(0,0,r)
round_gik = subtract(round_gik,translate(slot,-r,0,0))
round_gik = subtract(rotate(round_gik,120),translate(slot,-r,0,0))
round_gik = subtract(rotate(round_gik,120),translate(slot,-r,0,0))
x0 = x0 + l + r + s
d = sqrt(3)*r
h = sqrt(3)*d
triangle_gik = triangle(-d,-r,0,h-r,d,-r)
triangle_gik = subtract(triangle_gik,translate(reflect_xy(slot),0,-r,0))
triangle_gik = subtract(rotate(triangle_gik,120),translate(reflect_xy(slot),0,-r,0))
triangle_gik = subtract(rotate(triangle_gik,120),translate(reflect_xy(slot),0,-r,0))
inverted_triangle_gik = translate(reflect_y(triangle_gik,0),0,h-2*r,0)
x0 = x0 + r/2 + d + s
dx = d + s
dy0 = -h + r
dy = h + s
triangle_giks = translate(triangle_gik,x0,y0+dy0,0)
triangle_giks = add(triangle_giks,translate(inverted_triangle_gik,x0,y0+dy0-dy,0))
triangle_giks = add(triangle_giks,translate(triangle_gik,x0,y0+dy0-2*dy,0))
triangle_giks = add(triangle_giks,translate(inverted_triangle_gik,x0+dx,y0+dy0,0))
triangle_giks = add(triangle_giks,translate(triangle_gik,x0+dx,y0+dy0-dy,0))
triangle_giks = add(triangle_giks,translate(inverted_triangle_gik,x0+dx,y0+dy0-2*dy,0))
gik = add(gik,triangle_giks)
x0 = x0 - r/2 - d - s
dy0 = -h/2
round_giks = translate(round_gik,x0,y0+dy0,0)
round_giks = add(round_giks,translate(round_gik,x0,y0+dy0-dy,0))
round_giks = add(round_giks,translate(round_gik,x0,y0+dy0-2*dy,0))
x0 = x0 + r/2 + d + s
x0 = x0 + dx
x0 = x0 + r/2 + d + s
round_giks = add(round_giks,translate(round_gik,x0,y0+dy0,0))
round_giks = add(round_giks,translate(round_gik,x0,y0+dy0-dy,0))
round_giks = add(round_giks,translate(round_gik,x0,y0+dy0-2*dy,0))
gik = add(gik,round_giks)
cad.mm_per_unit = 25.4 # use inch units
#
# assign part to cad.function
#
cad.function = gik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment