This page was generated from unit-4.4-occ/bottle.ipynb.
4.4.1 OpenCascade Bottle-tutorial¶
Please consult the OCCT - documentation for more explanations:
https://dev.opencascade.org/doc/overview/html/occt__tutorial.html
[1]:
from netgen.occ import *
from netgen.webgui import Draw as DrawGeo
[2]:
myHeight = 70
myWidth = 50
myThickness = 30
[3]:
pnt1 = Pnt(-myWidth / 2., 0, 0);
pnt2 = Pnt(-myWidth / 2., -myThickness / 4., 0);
pnt3 = Pnt(0, -myThickness / 2., 0);
pnt4 = Pnt(myWidth / 2., -myThickness / 4., 0);
pnt5 = Pnt(myWidth / 2., 0, 0);
[4]:
seg1 = Segment(pnt1, pnt2)
arc = ArcOfCircle(pnt2, pnt3, pnt4)
seg2 = Segment(pnt4, pnt5)
[5]:
wire = Wire ([seg1, arc, seg2])
mirrored_wire = wire.Mirror(Axis((0,0,0), X))
w = Wire([wire, mirrored_wire])
[6]:
f = Face (w)
body = f.Extrude( myHeight*Z )
[7]:
body = body.MakeFillet (body.edges, myThickness / 12.)
DrawGeo (body);
[8]:
from ngsolve import Mesh
from ngsolve.webgui import Draw
[9]:
geo = OCCGeometry(body)
mesh = Mesh(geo.GenerateMesh(maxh=5))
[10]:
Draw (mesh);
Adding the neck:¶
[11]:
neckax = Axes(body.faces.Max(Z).center, Z)
[12]:
myNeckRadius = myThickness / 4.
myNeckHeight = myHeight / 10
neck = Cylinder(neckax, myNeckRadius, myNeckHeight);
[13]:
body = body+neck
DrawGeo (body);
[14]:
mesh = Mesh(OCCGeometry(body).GenerateMesh(maxh=5))
Draw (mesh);
find face with maximal z-coordinate:
[15]:
fmax = body.faces.Max(Z)
thickbody = body.MakeThickSolid([fmax], -myThickness / 50, 1.e-3)
DrawGeo (thickbody);
[16]:
mesh = Mesh(OCCGeometry(thickbody).GenerateMesh(maxh=3))
Draw (mesh);
Defining the threading¶
[17]:
cyl1 = Cylinder(neckax, myNeckRadius * 0.99, 1).faces[0]
cyl2 = Cylinder(neckax, myNeckRadius * 1.05, 1).faces[0]
[18]:
import math
aPnt = Pnt(2.*math.pi, myNeckHeight / 2.)
aDir = Dir( 2.*math.pi, myNeckHeight / 4. )
anAx2d = gp_Ax2d(aPnt, aDir)
[19]:
aMajor = 2. * math.pi
aMinor = myNeckHeight / 10
arc1 = Ellipse(anAx2d, aMajor, aMinor).Trim(0, math.pi)
arc2 = Ellipse(anAx2d, aMajor, aMinor/4).Trim(0, math.pi)
[20]:
seg = Segment(arc1.start, arc1.end)
[21]:
wire1 = Wire( [Edge(arc1, cyl1), Edge(seg, cyl1)] )
wire2 = Wire( [Edge(arc2, cyl2), Edge(seg, cyl2)] )
[22]:
threading = ThruSections ([wire1, wire2])
[23]:
res = thickbody+threading
DrawGeo (res);
[24]:
# mesh = Mesh(OCCGeometry(res).GenerateMesh(maxh=3))
# Draw (mesh);
[ ]: