Skip to content

Commit 2e5f026

Browse files
Merge pull request #14 from CadQuery/thread
Add Thread.py
2 parents 3914a04 + 281a787 commit 2e5f026

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ A place to share CadQuery scripts, modules, tutorials and projects
5959

6060
* [Involute_Gear.py](examples/Involute_Gear.py) - Fast involute gear generator.
6161

62-
<img src="examples/images/Involute_Gear.png" width="600"/>
62+
<img src="examples/images/Involute_Gear.png" width="600"/>
63+
64+
* [Thread.py](examples/Thread.py) - Thread example.
65+
66+
<img src="examples/images/Thread.png" width="600"/>
6367

6468
### Tutorials
6569

examples/Thread.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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)

examples/images/Thread.png

60.9 KB
Loading

0 commit comments

Comments
 (0)