-
Notifications
You must be signed in to change notification settings - Fork 0
/
parametric_btl_code.py
68 lines (46 loc) · 2.46 KB
/
parametric_btl_code.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
import cadquery as cq
from math import pi
import random as rd
#Generate 100 random bottles
for i in range(100):
#Setting parameters
a=rd.random()
THeight, MHeight, BHeight, radius = 2*a, rd.random() ,3*a , rd.gauss(2.2, 0.6)
RDiff=1/4
ROffset=1/4
NRings = rd.randint(2,10)
RRadius = radius - RDiff
#Volume Calculation
BPart_Volume = pi*(radius**2)*BHeight
TPart_Volume = pi*(radius**2)*THeight
MPart_Height = NRings*((pi/3)*ROffset*((radius**2)+(RRadius**2) + radius*RRadius) + pi*(radius**2)*MHeight)
Bottle_Volume = BPart_Volume + TPart_Volume + MPart_Height
#Construction of the Bottom Part
Bresult = (cq.Workplane("front").
circle(radius).workplane(offset=BHeight).circle(radius).loft(combine = True).edges('%CIRCLE and <Z').fillet(1))
for i in range(NRings):
Bresult = (Bresult.faces(">Z").workplane(centerOption="CenterOfMass")
.circle(radius).workplane(offset=ROffset).circle(RRadius).loft(combine = True)
.faces(">Z").workplane(centerOption="CenterOfMass")
.circle(RRadius).workplane(offset=ROffset).circle(radius).loft(combine = True)
.faces(">Z").workplane(centerOption="CenterOfMass")
.circle(radius).workplane(offset=MHeight).circle(radius).loft(combine = True))
Tresult = (Bresult.faces(">Z").workplane(centerOption="CenterOfMass")
.circle(radius).workplane(offset=THeight).circle(radius).loft(combine = True)
.shell(.15)
)
#Construction of the Top Part
distZ, distX = rd.uniform(0.4,0.85), radius/3
sPnts = [
(distX,distZ*4),
(2*distX+0.1,distZ*2),
(distX*3+0.15,0)
]
topPart = cq.Workplane("XZ").lineTo(0,distZ*5).lineTo(distX,distZ*5).lineTo(distX,distZ*4+0.01)
topPart = topPart.spline(sPnts,includeCurrent=True).close()
topPart = topPart.revolve(axisStart=(0,0), axisEnd=(0,1),clean=True)
#Assembly of both parts
topPart=topPart.translate((0,0,THeight + BHeight + 2*ROffset*NRings + (NRings)*MHeight))
result = Bresult.union(Tresult).union(topPart)
#Exporting the mesh in STL format
exporters.export(result, 'btl'+str(i)+'.png')