def make_face_to_contour_from(): v1 = make_vertex(gp_Pnt(0, 0, 0)) v2 = make_vertex(gp_Pnt(10, 0, 0)) v3 = make_vertex(gp_Pnt(7, 10, 0)) v4 = make_vertex(gp_Pnt(10, 20, 0)) v5 = make_vertex(gp_Pnt(0, 20, 0)) v6 = make_vertex(gp_Pnt(3, 10, 0)) e1 = make_edge(v1, v2) e2 = make_edge(v2, v3) e3 = make_edge(v3, v4) e4 = make_edge(v4, v5) e5 = make_edge(v5, v6) e6 = make_edge(v6, v1) v7 = make_vertex(gp_Pnt(2, 2, 0)) v8 = make_vertex(gp_Pnt(8, 2, 0)) v9 = make_vertex(gp_Pnt(7, 3, 0)) v10 = make_vertex(gp_Pnt(3, 3, 0)) e7 = make_edge(v7, v8) e8 = make_edge(v8, v9) e9 = make_edge(v9, v10) e10 = make_edge(v10, v7) w1 = make_wire([e1, e2, e3, e4, e5, e6]) f = make_face(w1) w2 = make_wire(e7, e8, e9, e10) f2 = make_face(w2) f3 = boolean_cut(f, f2) return f3
def cross_sec_face(sec_profile: SectionProfile, placement: Placement, solid_repre) -> Union[TopoDS_Face, TopoDS_Wire]: inner_shape = None if sec_profile.sec.type in SectionCat.tubular: outer_shape = make_wire( [make_circle(placement.origin, placement.zdir, sec_profile.sec.r)]) inner_shape = make_wire([ make_circle(placement.origin, placement.zdir, sec_profile.sec.r - sec_profile.sec.wt) ]) elif sec_profile.sec.type in SectionCat.circular: outer_shape = make_wire( [make_circle(placement.origin, placement.zdir, sec_profile.sec.r)]) elif sec_profile.sec.type in SectionCat.general: radius = np.sqrt(sec_profile.sec.properties.Ax / np.pi) outer_shape = make_wire( [make_circle(placement.origin, placement.zdir, radius)]) else: if sec_profile.disconnected is False: outer_curve = sec_profile.outer_curve inner_curve = sec_profile.inner_curve outer_curve.placement = placement outer_shape = outer_curve.face if inner_curve is not None: inner_curve.placement = placement inner_shape = inner_curve.wire else: outer_shape = [] for curve in sec_profile.outer_curve_disconnected: curve.placement = placement outer_shape.append(curve.wire) if inner_shape is not None and solid_repre is True: try: face = make_face(outer_shape) if type( outer_shape) is not TopoDS_Face else outer_shape shape = make_face_w_cutout(face, inner_shape) except TypeError as e: raise TypeError(e) except AssertionError as e: raise AssertionError(e) else: shape = outer_shape if shape is None: raise ValueError("Shape cannot be None") return shape
def make_shape(self): # 1 - retrieve the data from the UIUC airfoil data page foil_dat_url = 'http://m-selig.ae.illinois.edu/ads/coord_seligFmt/%s.dat' % self.profile # explicitly tell to not use ssl verification ssl._create_default_https_context = ssl._create_unverified_context print("Connecting to m-selig, retrieving foil data") f = urllib2.urlopen(foil_dat_url) print("Building foil geometry") plan = gp_Pln(gp_Pnt(0., 0., 0.), gp_Dir(0., 0., 1.)) # Z=0 plan / XY plan section_pts_2d = [] for line in f.readlines()[1:]: # The first line contains info only # 2 - do some cleanup on the data (mostly dealing with spaces) data = line.split() # 3 - create an array of points if len(data) == 2: # two coordinates for each point section_pts_2d.append( gp_Pnt2d( float(data[0]) * self.chord, float(data[1]) * self.chord)) # 4 - use the array to create a spline describing the airfoil section spline_2d = Geom2dAPI_PointsToBSpline( point2d_list_to_TColgp_Array1OfPnt2d(section_pts_2d), len(section_pts_2d) - 1, # order min len(section_pts_2d)) # order max spline = geomapi.To3d(spline_2d.Curve(), plan) # 5 - figure out if the trailing edge has a thickness or not, # and create a Face try: #first and last point of spline -> trailing edge trailing_edge = make_edge( gp_Pnt(section_pts_2d[0].X(), section_pts_2d[0].Y(), 0.0), gp_Pnt(section_pts_2d[-1].X(), section_pts_2d[-1].Y(), 0.0)) face = BRepBuilderAPI_MakeFace( make_wire([make_edge(spline), trailing_edge])) except AssertionError: # the trailing edge segment could not be created, probably because # the points are too close # No need to build a trailing edge face = BRepBuilderAPI_MakeFace(make_wire(make_edge(spline))) # 6 - extrude the Face to create a Solid return BRepPrimAPI_MakePrism( face.Face(), gp_Vec(gp_Pnt(0., 0., 0.), gp_Pnt(0., 0., self.span))).Shape()
def MakePentagonFace(self, Diameter: float, Radius: float) -> TopoDS_Face: tubeRadius = Diameter / 2.0 upX = tubeRadius * math.cos( 18 * math.pi / 180. ) upY = tubeRadius * math.sin( 18 * math.pi / 180. ) downX = tubeRadius * math.sin( 36 * math.pi / 180. ) downY = tubeRadius * math.cos( 36 * math.pi / 180. ) p1 = gp_Pnt( 0., tubeRadius, 0. ) p2 = gp_Pnt( upX, upY, 0. ) p3 = gp_Pnt( downX, -downY, 0. ) p4 = gp_Pnt( -downX, -downY, 0. ) p5 = gp_Pnt( -upX, upY, 0. ) ed1 = make_edge( p1, p2 ) ed2 = make_edge( p2, p3 ) ed3 = make_edge( p3, p4 ) ed4 = make_edge( p4, p5 ) ed5 = make_edge( p5, p1 ) pln = gp_Pln( gp_Pnt( 0., 0., 0. ), gp_Dir( 0., 0., 1. ) ) cur1 = self.__MakeFillet( ed1, ed2, pln, Radius ) cur2 = self.__MakeFillet( ed2, ed3, pln, Radius ) cur3 = self.__MakeFillet( ed3, ed4, pln, Radius ) cur4 = self.__MakeFillet( ed4, ed5, pln, Radius ) cur5 = self.__MakeFillet( ed5, ed1, pln, Radius ) edgeList = [ed1, cur1, ed2, cur2, ed3, cur3, ed4, cur4, ed5, cur5] wire = make_wire( edgeList ) return make_face( wire )
def MakeSquareFace(self, Width: float, High: float, Radius: float) -> TopoDS_Face: xDis = Width / 2.0 yDis = High / 2.0 p1 = gp_Pnt( xDis, yDis, 0. ) p2 = gp_Pnt( xDis, -yDis, 0. ) p3 = gp_Pnt( -xDis, -yDis, 0. ) p4 = gp_Pnt( -xDis, yDis, 0. ) ed1 = make_edge( p1, p2 ) ed2 = make_edge( p2, p3 ) ed3 = make_edge( p3, p4 ) ed4 = make_edge( p4, p1 ) pln = gp_Pln( gp_Pnt( 0., 0., 0. ), gp_Dir( 0., 0., 1. ) ) cur1 = self.__MakeFillet( ed1, ed2, pln, Radius ) cur2 = self.__MakeFillet( ed2, ed3, pln, Radius ) cur3 = self.__MakeFillet( ed3, ed4, pln, Radius ) cur4 = self.__MakeFillet( ed4, ed1, pln, Radius ) edgeList = [ed1, cur1, ed2, cur2, ed3, cur3, ed4, cur4] wire = make_wire( edgeList ) return make_face( wire )
def MakeTriangleFace(self, Diameter: float, Radius: float) -> TopoDS_Face: tubeRadius = Diameter / 2.0 degree = 30 * math.pi / 180. sindis = tubeRadius * math.sin( degree ) cosdis = tubeRadius * math.cos( degree ) p1 = gp_Pnt( 0., tubeRadius, 0. ) p2 = gp_Pnt( -cosdis, -sindis, 0. ) p3 = gp_Pnt( cosdis, -sindis, 0. ) ed1 = make_edge( p1, p2 ) ed2 = make_edge( p2, p3 ) ed3 = make_edge( p3, p1 ) pln = gp_Pln( gp_Pnt( 0., 0., 0. ), gp_Dir( 0., 0., 1. ) ) cur1 = self.__MakeFillet( ed1, ed2, pln, Radius ) cur2 = self.__MakeFillet( ed2, ed3, pln, Radius ) cur3 = self.__MakeFillet( ed3, ed1, pln, Radius ) edgeList = [ed1, cur1, ed2, cur2, ed3, cur3] wire = make_wire( edgeList ) return make_face( wire )
def MakeHexagonFace(self, Diameter: float, Radius: float) -> TopoDS_Face: tubeRadius = Diameter / 2.0 degree = 60 * math.pi / 180. sindis = tubeRadius * math.sin( degree ) cosdis = tubeRadius * math.cos( degree ) p1 = gp_Pnt( cosdis, sindis, 0. ) p2 = gp_Pnt( tubeRadius, 0., 0. ) p3 = gp_Pnt( cosdis, -sindis, 0. ) p4 = gp_Pnt( -cosdis, -sindis, 0. ) p5 = gp_Pnt( -tubeRadius, 0., 0. ) p6 = gp_Pnt( -cosdis, sindis, 0. ) ed1 = make_edge( p1, p2 ) ed2 = make_edge( p2, p3 ) ed3 = make_edge( p3, p4 ) ed4 = make_edge( p4, p5 ) ed5 = make_edge( p5, p6 ) ed6 = make_edge( p6, p1 ) pln = gp_Pln( gp_Pnt( 0., 0., 0. ), gp_Dir( 0., 0., 1. ) ) cur1 = self.__MakeFillet( ed1, ed2, pln, Radius ) cur2 = self.__MakeFillet( ed2, ed3, pln, Radius ) cur3 = self.__MakeFillet( ed3, ed4, pln, Radius ) cur4 = self.__MakeFillet( ed4, ed5, pln, Radius ) cur5 = self.__MakeFillet( ed5, ed6, pln, Radius ) cur6 = self.__MakeFillet( ed6, ed1, pln, Radius ) edgeList = [ed1, cur1, ed2, cur2, ed3, cur3, ed4, cur4, ed5, cur5, ed6, cur6] wire = make_wire( edgeList ) return make_face( wire )
def make_wire_from_points(points): if type(points[0]) in (list, tuple): p1 = list(points[0]) p2 = list(points[1]) else: p1 = points[0].tolist() p2 = points[1].tolist() if len(p1) == 2: p1 += [0] p2 += [0] return make_wire( [BRepBuilderAPI_MakeEdge(gp_Pnt(*p1), gp_Pnt(*p2)).Edge()])
def get_wire(self): if (self.wire == None): occ_edges = [] for i, e in enumerate(self.edges): o = "Element %i/%i: " % (i, len(self.edges)) if (isinstance(e, Line3)): occ_edges.append(e.to_edge()) elif (isinstance(e, Fillet2)): if ((len(self.edges)) <= (i + 1)): error("Not enough elements for fillet") exit(0) else: occ_edges.append( e.to_edge(self.edges[i - 1], self.edges[i + 1])) o += repr(e) debug(o) if occ_edges == []: return None self.wire = make_wire(occ_edges) trsf_wire = BRepBuilderAPI_Transform(self.wire, self.trsf) trsf_shape = trsf_wire.Shape() self.wire = topods.Wire(trsf_shape) self.face = None return self.wire
from OCC.Core.gp import gp_Pnt, gp_Pln from OCC.Core.ChFi2d import ChFi2d_AnaFilletAlgo from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge from OCC.Extend.ShapeFactory import make_wire from OCC.Display.SimpleGui import init_display display, start_display, add_menu, add_functionto_menu = init_display() # Defining the points p1 = gp_Pnt(0, 0, 0) p2 = gp_Pnt(5, 5, 0) p3 = gp_Pnt(-5, 5, 0) # Making the edges ed1 = BRepBuilderAPI_MakeEdge(p3, p2).Edge() ed2 = BRepBuilderAPI_MakeEdge(p2, p1).Edge() # Making the 2dFillet f = ChFi2d_AnaFilletAlgo() f.Init(ed1, ed2, gp_Pln()) radius = 1.0 f.Perform(radius) fillet2d = f.Result(ed1, ed2) # Create and display a wire w = make_wire([ed1, fillet2d, ed2]) display.DisplayShape(w) start_display()
def MakeEllipsFace(self, Major: float, Minor: float) -> TopoDS_Face: elip = gp_Elips( gp_XOY(), Major, Minor ) ed = make_edge( elip ) wire = make_wire( ed ) return make_face( wire )
def MakeCircleFace(self, Radius: float) -> TopoDS_Face: circle = Geom_Circle( gp_XOY(), Radius ) ed = make_edge( circle ) wire = make_wire( ed ) return make_face( wire )