|
| 1 | +from cadquery import * |
| 2 | +from math import * |
| 3 | + |
| 4 | +def helix(r0,r_eps,p,h,d=0,frac=1e-1): |
| 5 | + |
| 6 | + def func(t): |
| 7 | + |
| 8 | + if t>frac and t<1-frac: |
| 9 | + z = h*t + d |
| 10 | + r = r0+r_eps |
| 11 | + elif t<=frac: |
| 12 | + z = h*t + d*sin(pi/2 *t/frac) |
| 13 | + r = r0 + r_eps*sin(pi/2 *t/frac) |
| 14 | + else: |
| 15 | + z = h*t - d*sin(2*pi - pi/2*(1-t)/frac) |
| 16 | + r = r0 - r_eps*sin(2*pi - pi/2*(1-t)/frac) |
| 17 | + |
| 18 | + x = r*sin(-2*pi/(p/h)*t) |
| 19 | + y = r*cos(2*pi/(p/h)*t) |
| 20 | + |
| 21 | + return x,y,z |
| 22 | + |
| 23 | + return func |
| 24 | + |
| 25 | +def thread(radius, pitch, height, d, radius_eps, aspect= 10): |
| 26 | + |
| 27 | + e1_bottom = (cq.Workplane("XY") |
| 28 | + .parametricCurve(helix(radius,0,pitch,height,-d)).val() |
| 29 | + ) |
| 30 | + e1_top = (cq.Workplane("XY") |
| 31 | + .parametricCurve(helix(radius,0,pitch,height,d)).val() |
| 32 | + ) |
| 33 | + |
| 34 | + e2_bottom = (cq.Workplane("XY") |
| 35 | + .parametricCurve(helix(radius,radius_eps,pitch,height,-d/aspect)).val() |
| 36 | + ) |
| 37 | + e2_top = (cq.Workplane("XY") |
| 38 | + .parametricCurve(helix(radius,radius_eps,pitch,height,d/aspect)).val() |
| 39 | + ) |
| 40 | + |
| 41 | + f1 = Face.makeRuledSurface(e1_bottom, e1_top) |
| 42 | + f2 = Face.makeRuledSurface(e2_bottom, e2_top) |
| 43 | + f3 = Face.makeRuledSurface(e1_bottom, e2_bottom) |
| 44 | + f4 = Face.makeRuledSurface(e1_top, e2_top) |
| 45 | + |
| 46 | + sh = Shell.makeShell([f1,f2,f3,f4]) |
| 47 | + rv = Solid.makeSolid(sh) |
| 48 | + |
| 49 | + return rv |
| 50 | + |
| 51 | +radius = 4 |
| 52 | +pitch = 2 |
| 53 | +height = 4 |
| 54 | +d = pitch/4 |
| 55 | +radius_eps = 0.5 |
| 56 | +eps=1e-3 |
| 57 | + |
| 58 | +core = cq.Workplane("XY",origin=(0,0,-d)).circle(4).circle(3).extrude(height+1.75*d) |
| 59 | +th1 = thread(radius-eps,pitch,height,d,radius_eps) |
| 60 | +th2 =thread(radius-1+eps,pitch,height,d,-radius_eps) |
| 61 | + |
| 62 | +res = core.union(Compound.makeCompound([th1,th2])) |
| 63 | + |
| 64 | +show_object(res) |
0 commit comments