-
Notifications
You must be signed in to change notification settings - Fork 0
/
sweep_stuff.py
103 lines (89 loc) · 2.55 KB
/
sweep_stuff.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
import cadquery as cq
pts = [
cq.Vector(-62.78522300238056, 44.083497276049606, 54.49411726978384),
cq.Vector(-67.05887174864904, 22.819295987438935, 46.79247812371094),
cq.Vector(-68.51653369264845, 0.0, 44.165592538074314),
cq.Vector(-67.05887174864904, -22.819295987438935, 46.79247812371094)
]
# X axis line length 20.0
path = cq.Edge.makeSpline(pts)
# for pt in pts:
# if start:
# path.moveTo(pt)
# else:
# path.lineTo(pt)
# Sweep a circle from diameter 2.0 to diameter 1.0 to diameter 2.0 along X axis length 10.0 + 10.0
defaultSweep = (
cq.Workplane("YZ")
.workplane(offset=-10.0)
.circle(2.0)
.workplane(offset=10.0)
.circle(1.0)
.workplane(offset=10.0)
.circle(2.0)
.sweep(path, multisection=True)
)
# We can sweep through different shapes
recttocircleSweep = (
cq.Workplane("YZ")
.workplane(offset=-10.0)
.rect(2.0, 2.0)
.workplane(offset=8.0)
.circle(1.0)
.workplane(offset=4.0)
.circle(1.0)
.workplane(offset=8.0)
.rect(2.0, 2.0)
.sweep(path, multisection=True)
)
circletorectSweep = (
cq.Workplane("YZ")
.workplane(offset=-10.0)
.circle(1.0)
.workplane(offset=7.0)
.rect(2.0, 2.0)
.workplane(offset=6.0)
.rect(2.0, 2.0)
.workplane(offset=7.0)
.circle(1.0)
.sweep(path, multisection=True)
)
# Placement of the Shape is important otherwise could produce unexpected shape
specialSweep = (
cq.Workplane("YZ")
.circle(1.0)
.workplane(offset=10.0)
.rect(2.0, 2.0)
.sweep(path, multisection=True)
)
# Switch to an arc for the path : line l=5.0 then half circle r=4.0 then line l=5.0
path = (
cq.Workplane("XZ")
.moveTo(-5, 4)
.lineTo(0, 4)
.threePointArc((4, 0), (0, -4))
.lineTo(-5, -4)
)
# Placement of different shapes should follow the path
# cylinder r=1.5 along first line
# then sweep along arc from r=1.5 to r=1.0
# then cylinder r=1.0 along last line
arcSweep = (
cq.Workplane("YZ")
.workplane(offset=-5)
.moveTo(0, 4)
.circle(1.5)
.workplane(offset=5, centerOption="CenterOfMass")
.circle(1.5)
.moveTo(0, -8)
.circle(1.0)
.workplane(offset=-5, centerOption="CenterOfMass")
.circle(1.0)
.sweep(path, multisection=True)
)
# Translate the resulting solids so that they do not overlap and display them left to right
show_object(defaultSweep)
# show_object(circletorectSweep.translate((0, 5, 0)))
# show_object(recttocircleSweep.translate((0, 10, 0)))
# show_object(specialSweep.translate((0, 15, 0)))
# show_object(arcSweep.translate((0, -5, 0)))