Commit 375ed272 authored by Sam Calisch's avatar Sam Calisch
Browse files

added initial hex spiral cut files

parent e7e5a9e4
This diff is collapsed.
#!/usr/bin/env python
from __future__ import division,absolute_import
import rhinoscriptsyntax as rs
from math import *
import sys
#simple class for vec2
class V2(object):
def __init__(self,*args):
if len(args)>1:
self.x = args[0]
self.y = args[1]
self.x = args[0][0]
self.y = args[0][1]
self.p3l = [self.x,self.y,0]
def __add__(self,other):
return V2(self.x+other.x,self.y+other.y)
def __sub__(self,other):
return V2(self.x-other.x,self.y-other.y)
def __mul__(self,other):
return V2(self.x*other.x,self.y*other.y)
return V2(self.x*other,self.y*other)
def __rmul__(self,other):
return V2(self.x*other.x, self.y*other.y)
return V2(self.x*other,self.y*other)
def __getitem__(self,index):
return [self.x,self.y][index]
def __repr__(self):
return "V2(%.6f,%.6f)"%(self.x,self.y)
def rotate(self,th):
return V2(self.x*cos(th)-self.y*sin(th), self.x*sin(th)+self.y*cos(th))
def rotate90(self):
return V2(-self.y,self.x)
def rotate_p(self,b,th):
return b + (self-b).rotate(th)
def magnitude(self):
return sqrt(self.x*self.x + self.y*self.y)
def normalized(self):
return self*(1./self.magnitude())
def dot(self,other):
return self.x*other.x + self.y*other.y
def cross(self,other):
return self.x*other.y - self.y*other.x
def angle_between(self,other):
#unsigned angle between two vectors
c = self.cross(other)
return atan2(c,
def projected_onto(self,other):
return ((*other
def projected_orthogonal_to(self,other):
return self - self.projected_onto(other)
def close(self,other,tol=1e-6):
return (abs(self.x-other.x)<tol) and (abs(self.y-other.y)<tol)
def p3lz(self,z):
return [self.x,self.y,z]
# a few helper functions
def line(p1,p2,layer,bridge_w=0,cut_w=0):
d = p2-p1; dl = d.magnitude()
if dl==0:
return None
dn = d.normalized()
if bridge_w==0 or cut_w==0:
return rs.AddLine(p1.p3l, p2.p3l)
output = []; dist = bridge_w
ds = []
while dist < dl-2*bridge_w:#-cut_w:
ds.append((dist, dist+cut_w))
#print bridge_w, (p1+dist*dn).p3l , (p1+(dist+bridge_w)*dn).p3l
dist += cut_w+bridge_w
#leftover = dl-bridge_w-cut_w - dist + cut_w+bridge_w
leftover = dl-bridge_w - dist + cut_w+bridge_w
for pair in ds:
output.append(rs.AddLine( (p1+(pair[0] + leftover/2)*dn).p3l , (p1+(pair[1]+ leftover/2)*dn).p3l) )
return output
def circle(c,d,layer):
return rs.AddCircle(c.p3l, .5*d)
def arc(c,d,th1,th2,layer):
p1 = c + d/2*V2(cos(pi/180.*th1),sin(pi/180.*th1))
p2 = c + d/2*V2(cos(pi/180.*th2),sin(pi/180.*th2))
pm = c + d/2*V2(cos(pi/180.*(th1+th2)/2),sin(pi/180.*(th1+th2)/2))
return rs.AddArc3Pt(p1.p3l,p2.p3l,pm.p3l)
def filleted_hex(c,R,r,layer):
crvs = []
x = r/sqrt(3)
for i in range(6):
v0 = R*V2(cos(i*2*pi/6),sin(i*2*pi/6))
v1 = R*V2(cos((i+1)*2*pi/6),sin((i+1)*2*pi/6))
d = (v1 - v0).normalized()
crvs.append( line( c+v0 + x*d, c+v1 - x*d, layer) )
crvs.append( arc( c+v0-2*x*v0.normalized(),2*r,-30+i*60,30+i*60, layer) )
return crvs
def main():
mag_d = 3.12 #mm, diameter of magnets, as cut by laser
hole_d = 6 #mm, diameter of air hole
s = 6 #mm, hex lattice side length (2xmag_d?)
s32 = s*sqrt(3)/2.
frame_inner = 60 #mm, radius / side length of inner hex of frame
frame_inner_fillet = 10 #mm, fillet radius
frame_outer = 80 #mm, radius / side length of outer hex of frame
frame_outer_fillet = 20 #mm, fillet radius
frame_bolt_d = 4.1 #mm, diameter of bolt holes
wire_pitch = 2*.088 #mm, pitch, .088 = measured diameter (.080) + .008 mm slop (10% applied)
N = 11 #number of turns
Nr = 4 #number of radial layers in the hex lattice
#make frame
frame = []
frame += filleted_hex(V2(0,0), frame_inner, frame_inner_fillet, 'frame')
frame += filleted_hex(V2(0,0), frame_outer, frame_outer_fillet, 'frame')
for i in range(6):
v0 = .5*(frame_inner+frame_outer)*V2(cos(i*2*pi/6),sin(i*2*pi/6))
v1 = .5*(frame_inner+frame_outer)*V2(cos((i+1)*2*pi/6),sin((i+1)*2*pi/6))
frame += [
circle(v0, frame_bolt_d, 'frame'),
circle(.5*(v0+v1), frame_bolt_d, 'frame'),
#make magnet grid and air hole grid
magnets = [];
magnets += [circle(V2(0,0),mag_d,'magnets_a')]
for i in range(3): #3-fold angular symmetry
vr = V2(cos(i*2*pi/3),sin(i*2*pi/3))
vth = V2(cos(i*2*pi/3+pi/2),sin(i*2*pi/3+pi/2))
vk = V2(cos((i+1)*2*pi/3),sin((i+1)*2*pi/3))
for j in range(Nr):
for k in range(Nr+1):
magnets += [circle(2*s32*vr*(j+1) + 2*s32*vk*k, mag_d, 'magnets_a')]
if k<Nr:
magnets += [
circle(2*s32*vr*(j+.5) + 2*s32*vk*k + .5*s*vth, mag_d, 'magnets_b'),
circle(2*s32*vr*j + 2*s32*vk*k + s*vth, hole_d, 'holes'),
if __name__ == '__main__':
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment