-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbirfield.py
115 lines (93 loc) · 3.87 KB
/
birfield.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from madcad import *
settings.resolution = ('rad', 0.2)
nballs = 6
rball = 6/2
rsphere = 1.5 * nballs*rball/pi
helix = 0.2
amax = radians(40)
ecage = rball*0.6
rinmax = distance(rotateY(rsphere*X, -amax/2), rotateY(rsphere*Z, amax))
routmax = rsphere * cos(amax/2)
rin = stfloor(rinmax*0.8)
rout = rinmax
hext = stceil(0.8*rsphere)
nscrews = nballs//2
dscrew = stceil(rsphere*0.2, 0.3)
rscrews = stceil(rsphere+0.8*rball+dscrew, 0.05)
balls = [icosphere(p, rball).option(color=vec3(0.1, 0.2, 0.4))
for p in regon(Axis(O,Z), rsphere, nballs).points]
guide_profile = web(Circle(Axis(rsphere*X, Z), rball)) .transform(scaledir(Y, 1.02))
guide = revolution(guide_profile, Axis(O,Y), pi, alignment=0.5).flip()
interior = intersection(
icosphere(O, rsphere-ecage),
brick(width=2*rsphere*vec3(1, 1, 1.2*sin(amax/2))),
)
exterior = union(
icosphere(O, rsphere+ecage),
intersection(
cylinder(-(rsphere+rball)*Z, (rsphere+rball)*Z, 2*rball, fill=False),
icosphere(O, rsphere+rball*1.1)),
)
for i in range(nballs):
interior = difference(interior, guide.transform(rotate(helix*(-1)**i, X)).transform(rotate(2*pi*i/nballs, Z)))
exterior = union(exterior, guide.transform(rotate(-helix*(-1)**i, X)).transform(rotate(2*pi*i/nballs, Z)))
exterior = exterior.flip()
interior = interior.finish()
cage = revolution(wire([rsphere*vec3(cos(t), 0, sin(t)) for t in linrange(-0.75*amax, 0.75*amax, div=10)]))
window = parallelogram(2.3*rball*Y, 2*rball*Z, align=vec3(0.5), fill=False) .transform(rsphere*X)
filet(window, [0, 1, 2, 3], width=rball)
cage = thicken(
pierce(cage,
repeat(extrusion(window, rball*X, alignment=0.5), nballs, rotate(2*pi/nballs, Z))),
ecage,
alignment=0.5,
)
cage = cage.option(color=vec3(0.5,0.3,0))
mesh.mesh(balls).transform(rotate(-amax/2, Y))
interior.transform(rotate(-amax, Y))
interior = difference(interior, cylinder(-rsphere*Z, rsphere*Z, min(rsphere-rball*1.2, rin)))
#in_shape = revolution(wire([
# vec3(rinmax, 0, sqrt((rsphere+rball)**2 - rinmax**2)*1.01),
# vec3(rinmax, 0, 0),
# ]).transform(rotate(amax, Y)).flip())
#
#exterior = union(exterior, square(Axis(-rsphere*Z,Z), rsphere))
## inside shaft interface
#out_shape = revolution(wire([
# vec3(min(rout, routmax), 0, -rsphere*sin(amax/2)),
## vec3(max(routmax, rout), 0, -1.05*sqrt((rsphere+rball)**2 - max(routmax, rout)**2)),
# vec3(rout, 0, -rsphere*1.01),
# vec3(rout, 0, -rsphere-hext),
# vec3(1.2*rout, 0, -rsphere-hext),
# ]).segmented().flip())
#exterior = intersection(exterior, out_shape + in_shape)
#exterior = intersection(
# inflate(convexhull(exterior + icosphere(O, rsphere+rball)).orient(), rsphere*0.1).mergegroups(),
# expand(exterior, rsphere*0.5),
# ).finish()
# exterior screws interface
in_shape = revolution(wire([
vec3(rinmax, 0, sqrt((rsphere+rball)**2 - rinmax**2)*1.1),
vec3(rinmax, 0, 0),
]).transform(rotate(amax, Y)).flip())
exterior = intersection(
icosphere(O, rsphere*1.1+rball) + exterior,
in_shape + in_shape.transform(scaledir(Z, -1)).flip(),
)
hole = bolt_slot(rscrews*Y - rball*0.99*Z, rscrews*Y + rball*0.99*Z, dscrew) .transform(rotate(pi/2+pi/nballs, Z))
support = extrusion(flatsurface(convexoutline(
repeat(web(Circle(Axis(rscrews*Y,Z), 1.2*dscrew)).transform(rotate(pi/2 + pi/nballs, Z)), nscrews, rotate(2*pi/nscrews, Z))
+ web(Circle(Axis(O,Z), rsphere*1.1 + rball))
)), 2*rball*Z, alignment=0.5).orient()
e = pierce(support, exterior).islands()[0].transform(0.999)
exterior = union(exterior, e)
exterior = intersection(exterior, repeat(hole, nscrews, rotate(2*pi/nscrews, Z)))
annotations = [
note_distance(O, rotate(pi/2 + pi/nballs, Z) * rscrews*Y, offset=1.5*rsphere*Z),
note_radius(hole.group(2), offset=rsphere),
note_radius(interior.group(9), offset=2.5*rsphere),
note_radius(balls[0], offset=1.5*rsphere),
]
#io.write(exterior, '/tmp/birfield/exterior.stl')
#io.write(interior, '/tmp/birfield/interior.stl')
#io.write(cage, '/tmp/birfield/cage.stl')