def curves2d_from_offset(event=None): ''' @param display: ''' pnt2d_array = TColgp_Array1OfPnt2d(1, 5) pnt2d_array.SetValue(1, gp_Pnt2d(-4, 0)) pnt2d_array.SetValue(2, gp_Pnt2d(-7, 2)) pnt2d_array.SetValue(3, gp_Pnt2d(-6, 3)) pnt2d_array.SetValue(4, gp_Pnt2d(-4, 3)) pnt2d_array.SetValue(5, gp_Pnt2d(-3, 5)) spline_1 = Geom2dAPI_PointsToBSpline(pnt2d_array).Curve() dist = 1 offset_curve1 = Geom2d_OffsetCurve(spline_1, dist) result = offset_curve1.IsCN(2) print("Offset curve yellow is C2: %r" % result) dist2 = 1.5 offset_curve2 = Geom2d_OffsetCurve(spline_1, dist2) result2 = offset_curve2.IsCN(2) result = offset_curve1.IsCN(2) print("Offset curve blue is C2: %r" % result2) display.DisplayShape(spline_1) display.DisplayShape(offset_curve1, color='YELLOW') display.DisplayShape(offset_curve2, color='BLUE', update=True)
def curves2d_from_offset(event=None): r""" @param display: """ pnt2d_array = TColgp_Array1OfPnt2d(1, 5) pnt2d_array.SetValue(1, gp_Pnt2d(-4, 0)) pnt2d_array.SetValue(2, gp_Pnt2d(-7, 2)) pnt2d_array.SetValue(3, gp_Pnt2d(-6, 3)) pnt2d_array.SetValue(4, gp_Pnt2d(-4, 3)) pnt2d_array.SetValue(5, gp_Pnt2d(-3, 5)) spline_1 = Geom2dAPI_PointsToBSpline(pnt2d_array).Curve() dist = 1 offset_curve1 = Geom2d_OffsetCurve(spline_1, dist) result = offset_curve1.IsCN(2) print("Offset curve yellow is C2: %r" % result) dist2 = 1.5 offset_curve2 = Geom2d_OffsetCurve(spline_1, dist2) result2 = offset_curve2.IsCN(2) print("Offset curve blue is C2: %r" % result2) display.DisplayShape(spline_1) display.DisplayShape(offset_curve1, color='YELLOW') display.DisplayShape(offset_curve2, color='BLUE', update=True)
def extrusion(event=None): # Make a box Box = BRepPrimAPI_MakeBox(400., 250., 300.) S = Box.Shape() # Choose the first Face of the box F = next(Topo(S).faces()) surf = BRep_Tool_Surface(F) # Make a plane from this face Pl = Handle_Geom_Plane_DownCast(surf) Pln = Pl.GetObject() # Get the normal of this plane. This will be the direction of extrusion. D = Pln.Axis().Direction() # Inverse normal #D.Reverse() # Create the 2D planar sketch MW = BRepBuilderAPI_MakeWire() p1 = gp_Pnt2d(200., -100.) p2 = gp_Pnt2d(100., -100.) aline = GCE2d_MakeLine(p1, p2).Value() Edge1 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge1.Edge()) p1 = p2 p2 = gp_Pnt2d(100., -200.) aline = GCE2d_MakeLine(p1, p2).Value() Edge2 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge2.Edge()) p1 = p2 p2 = gp_Pnt2d(200., -200.) aline = GCE2d_MakeLine(p1, p2).Value() Edge3 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge3.Edge()) p1 = p2 p2 = gp_Pnt2d(200., -100.) aline = GCE2d_MakeLine(p1, p2).Value() Edge4 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge4.Edge()) # Build Face from Wire. NB: a face is required to generate a solid. MKF = BRepBuilderAPI_MakeFace() MKF.Init(surf, False, 1e-6) MKF.Add(MW.Wire()) FP = MKF.Face() breplib_BuildCurves3d(FP) MKP = BRepFeat_MakePrism(S, FP, F, D, False, True) MKP.Perform(200.) # TODO MKP completes, seeing a split operation but no extrusion assert MKP.IsDone() res1 = MKP.Shape() display.EraseAll() display.DisplayColoredShape(res1, 'BLUE') display.DisplayColoredShape(FP, 'YELLOW') display.FitAll()
def extrusion(event=None): # Make a box Box = BRepPrimAPI_MakeBox(400., 250., 300.) S = Box.Shape() # Choose the first Face of the box F = next(Topo(S).faces()) surf = BRep_Tool_Surface(F) # Make a plane from this face Pl = Handle_Geom_Plane_DownCast(surf) Pln = Pl.GetObject() # Get the normal of this plane. This will be the direction of extrusion. D = Pln.Axis().Direction() # Inverse normal D.Reverse() # Create the 2D planar sketch MW = BRepBuilderAPI_MakeWire() p1 = gp_Pnt2d(200., -100.) p2 = gp_Pnt2d(100., -100.) aline = GCE2d_MakeLine(p1, p2).Value() Edge1 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge1.Edge()) p1 = p2 p2 = gp_Pnt2d(100., -200.) aline = GCE2d_MakeLine(p1, p2).Value() Edge2 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge2.Edge()) p1 = p2 p2 = gp_Pnt2d(200., -200.) aline = GCE2d_MakeLine(p1, p2).Value() Edge3 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge3.Edge()) p1 = p2 p2 = gp_Pnt2d(200., -100.) aline = GCE2d_MakeLine(p1, p2).Value() Edge4 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge4.Edge()) # Build Face from Wire. NB: a face is required to generate a solid. MKF = BRepBuilderAPI_MakeFace() MKF.Init(surf, False, 1e-6) MKF.Add(MW.Wire()) FP = MKF.Face() breplib_BuildCurves3d(FP) MKP = BRepFeat_MakePrism(S, FP, F, D, False, True) MKP.Perform(200.) # TODO MKP completes, seeing a split operation but no extrusion assert MKP.IsDone() res1 = MKP.Shape() display.EraseAll() display.DisplayColoredShape(res1, 'BLUE') display.FitAll()
def testAutoImportOfDependentModules(self): """ Test: automatic import of dependent modules """ returned_object = GCE2d_MakeSegment(gp_Pnt2d(1, 1), gp_Pnt2d(3, 4)).Value() # for this unittest, don't use the issinstance() function, # since the OCC.Geom2d module # is *not* manually imported returned_object_type = '%s' % type(returned_object) self.assertEqual(returned_object_type, "<class 'OCC.Geom2d.Handle_Geom2d_TrimmedCurve'>")
def bisect_pnt(event=None): display.EraseAll() p1 = gp_Pnt2d(1, 0.5) p2 = gp_Pnt2d(0, 1e5) bi = GccAna_Pnt2dBisec(p1, p2) bisec = bi.ThisSolution() # enum GccInt_Lin, GccInt_Cir, GccInt_Ell, GccInt_Par, GccInt_Hpr, GccInt_Pnt p1_ = make_vertex(gp_Pnt(p1.X(), p1.Y(), 0)) p2_ = make_vertex(gp_Pnt(p2.X(), p2.Y(), 0)) display.DisplayShape([p1_, p2_]) display.DisplayColoredShape(make_edge2d(bisec), 'BLUE') display.FitAll()
def testAutoImportOfDependentModules(self): ''' when a module returns an object defined in another module, this module should be automatically imported in scope ''' print 'Test: automatic import of dependent modules' from OCC.GCE2d import GCE2d_MakeSegment from OCC.gp import gp_Pnt2d returned_object = GCE2d_MakeSegment(gp_Pnt2d(1,1),gp_Pnt2d(3,4)).Value() # for this unittest, don't use the issinstance() function, since the OCC.Geom2d module # is *not* manually imported returned_object_type = '%s'%type(returned_object) self.assertEqual(returned_object_type,"<class 'OCC.Geom2d.Handle_Geom2d_TrimmedCurve'>")
def faircurve(event=None): pt1 = gp_Pnt2d(0.0, 0.0) pt2 = gp_Pnt2d(0.0, 120.0) height = 100.0 pl = Geom_Plane(gp_Pln()) for i in range(0, 40): # TODO: the parameter slope needs to be visualized slope = i / 100.0 bc = batten_curve(pt1, pt2, height, slope, math.radians(i), math.radians(-i)) display.EraseAll() edge = BRepBuilderAPI_MakeEdge(bc, pl.GetHandle()).Edge() display.DisplayShape(edge, update=True) time.sleep(0.21)
def faircurve(event=None): pt1 = gp_Pnt2d(0., 0.) pt2 = gp_Pnt2d(0., 120.) height = 100. slope = 0.3 pl = Geom_Plane(gp_Pln()) for i in range(0, 40): # TODO: the parameter slope needs to be visualized bc = batten_curve(pt1, pt2, height, i/100., math.radians(i), math.radians(-i)) display.EraseAll() display.DisplayShape(make_edge(bc, pl.GetHandle()), update=True) time.sleep(0.21)
def bisect_lineline(event=None): display.EraseAll() li1 = gp_Lin2d(gp_Pnt2d(), gp_Dir2d(1, 0)) li2 = gp_Lin2d(gp_Pnt2d(), gp_Dir2d(0, 1)) bi = GccAna_Lin2dBisec(li1, li2) bi_li1 = bi.ThisSolution(1) bi_li2 = bi.ThisSolution(2) for i in [li1, li2]: display.DisplayShape(make_edge2d(i)) for i in [bi_li1, bi_li2]: display.DisplayColoredShape(make_edge2d(i), 'BLUE') display.FitAll()
def testAutoImportOfDependentModules(self): ''' when a module returns an object defined in another module, this module should be automatically imported in scope ''' print 'Test: automatic import of dependent modules' from OCC.GCE2d import GCE2d_MakeSegment from OCC.gp import gp_Pnt2d returned_object = GCE2d_MakeSegment(gp_Pnt2d(1, 1), gp_Pnt2d(3, 4)).Value() # for this unittest, don't use the issinstance() function, since the OCC.Geom2d module # is *not* manually imported returned_object_type = '%s' % type(returned_object) self.assertEqual(returned_object_type, "<class 'OCC.Geom2d.Handle_Geom2d_TrimmedCurve'>")
def faircurve(event=None): pt1 = gp_Pnt2d(0., 0.) pt2 = gp_Pnt2d(0., 120.) height = 100. pl = Geom_Plane(gp_Pln()) for i in range(0, 40): # TODO: the parameter slope needs to be visualized slope = i / 100. bc = batten_curve(pt1, pt2, height, slope, math.radians(i), math.radians(-i)) display.EraseAll() edge = BRepBuilderAPI_MakeEdge(bc, pl.GetHandle()).Edge() display.DisplayShape(edge, update=True) time.sleep(0.21)
def points_from_curve(event=None): radius = 5. abscissa = 3. circle = Geom2d_Circle(gp_OX2d(), radius, True) gac = Geom2dAdaptor_Curve(circle.GetHandle()) ua = GCPnts_UniformAbscissa(gac, abscissa) aSequence = [] if ua.IsDone(): n = ua.NbPoints() for count in range(1, n + 1): p = gp_Pnt2d() circle.D0(ua.Parameter(count), p) aSequence.append(p) # convert analytic to bspline display.DisplayShape(circle, update=True) i = 0 for p in aSequence: i = i + 1 pstring = 'P%i : parameter %f' % (i, ua.Parameter(i)) pnt = gp_Pnt(p.X(), p.Y(), 0) # display points display.DisplayShape(pnt, update=True) display.DisplayMessage(pnt, pstring)
def testProjectingPointInaccurately(): """ test projecting a point onto a curve """ h = makeHeartWire() #convert to twod curves curves = [] for e in Wrappers.Wire(h).edges2(): curves.append(get2dCurveFrom3dEdge(e)) #project a point onto the wire. we want to see if slight inaccurcies will project. #this simulates trying to find points on a curve that were put there via pixels display.DisplayShape(h) DISTANCE = 0.004 p = gp.gp_Pnt2d(2.0 + DISTANCE, 2.0 - DISTANCE) display.DisplayShape(Wrappers.make_vertex(gp.gp_Pnt(p.X(), p.Y(), 0))) for c in curves: r = projectPointOnCurve2d(c, p, 0.005) if r is not None: (param, pnt) = r print "found point: parmater-%0.3f, point-(%0.3f,%0.3f)" % ( param, pnt.X(), pnt.Y()) display.DisplayShape( Wrappers.make_vertex(gp.gp_Pnt(pnt.X(), pnt.Y(), 0)))
def makeHelix(cls, pitch, height, radius, center=Vector(0, 0, 0), dir=Vector(0, 0, 1), angle=360.0, lefthand=False): """ Make a helix with a given pitch, height and radius By default a cylindrical surface is used to create the helix. If the fourth parameter is set (the apex given in degree) a conical surface is used instead' """ # 1. build underlying cylindrical/conical surface if angle == 360.: geom_surf = Geom_CylindricalSurface( gp_Ax3(center.toPnt(), dir.toDir()), radius) else: geom_surf = Geom_ConicalSurface( gp_Ax3(center.toPnt(), dir.toDir()), angle * DEG2RAD, # TODO why no orientation? radius) # 2. construct an semgent in the u,v domain if lefthand: geom_line = Geom2d_Line(gp_Pnt2d(0.0, 0.0), gp_Dir2d(-2 * pi, pitch)) else: geom_line = Geom2d_Line(gp_Pnt2d(0.0, 0.0), gp_Dir2d(2 * pi, pitch)) # 3. put it together into a wire n_turns = height / pitch u_start = geom_line.Value(0.) u_stop = geom_line.Value(sqrt(n_turns * ((2 * pi)**2 + pitch**2))) geom_seg = GCE2d_MakeSegment(u_start, u_stop).Value() e = BRepBuilderAPI_MakeEdge(geom_seg, geom_surf.GetHandle()).Edge() # 4. Convert to wire and fix building 3d geom from 2d geom w = BRepBuilderAPI_MakeWire(e).Wire() breplib_BuildCurves3d(w) return cls(w)
def bisect_crvcrv(event=None): display.EraseAll() ax = gp_Ax22d(gp_Pnt2d(), gp_Dir2d(1, 0), gp_Dir2d(0, -1)) circ = gp_Circ2d(ax, 5) crv1 = GCE2d_MakeCircle(circ).Value() edg1 = make_edge2d(crv1, -1.0, 1.0) display.DisplayColoredShape(edg1, 'BLUE') p1 = gp_Pnt2d(-10, 0) p2 = gp_Pnt2d(-10, 10) crv2 = GCE2d_MakeLine(p1, p2).Value() edg2 = make_edge2d(crv2, -10.0, 10.0) display.DisplayColoredShape(edg2, 'GREEN') bi = Bisector_BisecCC(crv1, crv2, 50, -5, gp_Pnt2d(0, 0)) crv_bi = bi.Curve(1) edg3 = make_edge2d(crv_bi, -1.0, 1.0) display.DisplayColoredShape(edg3, 'RED') display.FitAll()
def on_trimmed(self, u, v): '''tests whether the surface at the u,v parameter has been trimmed ''' if self._classify_uv is None: self._classify_uv = BRepTopAdaptor_FClass2d(self, 1e-9) ##1e-9 uv = gp_Pnt2d(u, v) if self._classify_uv.Perform(uv) == TopAbs_IN: #IN return True else: return False
def on_trimmed(self, u, v): '''tests whether the surface at the u,v parameter has been trimmed ''' if self._classify_uv is None: self._classify_uv = BRepTopAdaptor_FClass2d(self, 1e-9) uv = gp_Pnt2d(u, v) if self._classify_uv.Perform(uv) == TopAbs_IN: return True else: return False
def testPointInFacePerformance(face): """ tests how quickly we can dtermine if a point is on a face """ pnt = gp.gp_Pnt2d(0.5,2.0); TOLERANCE = 0.001; q = time.clock() for i in range(1000): bf = BRepClass.BRepClass_FaceExplorer(face) result = bf.Reject(pnt) print ("Computed point in face 100 times in %0.3f" % ( time.clock() - q ) )
def bisect_linecircle(event=None): display.EraseAll() ci1 = gp_Circ2d(gp_Ax22d(), 10000) li1 = gp_Lin2d(gp_Pnt2d(2000000, 20), gp_Dir2d(0, 1)) bi = GccAna_CircLin2dBisec(ci1, li1) assert bi.IsDone() bisec = bi.ThisSolution(1).GetObject() pb = bisec.Parabola() display.DisplayShape([make_edge2d(ci1), make_edge2d(li1)]) display.DisplayColoredShape(make_edge2d(pb), 'BLUE') display.FitAll()
def testPointInFacePerformance(face): """ tests how quickly we can dtermine if a point is on a face """ pnt = gp.gp_Pnt2d(0.5, 2.0) TOLERANCE = 0.001 q = time.clock() for i in range(1000): bf = BRepClass.BRepClass_FaceExplorer(face) result = bf.Reject(pnt) print("Computed point in face 100 times in %0.3f" % (time.clock() - q))
def findIntersectionsUsingCurves(wire, lines): points = [] count = 0 w = Wrappers.Wire(wire) for boundaryEdge in w.edges2(): # get the curve from the 2d edge hCurve = get2dCurveFrom3dEdge(boundaryEdge) curve = hCurve.GetObject() a = gp.gp_Pnt2d() b = gp.gp_Pnt2d() for l in lines: # the line is already a geom-curve lc = l.GetObject() count += 1 isector = Geom2dAPI.Geom2dAPI_ExtremaCurveCurve( hCurve, l, curve.FirstParameter(), curve.LastParameter(), lc.FirstParameter(), lc.LastParameter() ) if isector.NbExtrema() > 0: isector.NearestPoints(a, b) points.append(a) return (count, points)
def findIntersectionsUsingCurves(wire, lines): points = [] count = 0 w = Wrappers.Wire(wire) for boundaryEdge in w.edges2(): #get the curve from the 2d edge hCurve = get2dCurveFrom3dEdge(boundaryEdge) curve = hCurve.GetObject() a = gp.gp_Pnt2d() b = gp.gp_Pnt2d() for l in lines: #the line is already a geom-curve lc = l.GetObject() count += 1 isector = Geom2dAPI.Geom2dAPI_ExtremaCurveCurve( hCurve, l, curve.FirstParameter(), curve.LastParameter(), lc.FirstParameter(), lc.LastParameter()) if isector.NbExtrema() > 0: isector.NearestPoints(a, b) points.append(a) return (count, points)
def make_shape(self): # 1 - retrieve the data from the UIUC airfoil data page foil_dat_url = 'http://www.ae.illinois.edu/m-selig/ads/coord_seligFmt/%s.dat' % self.profile if py2: f = urllib2.urlopen(foil_dat_url) else: http = urllib3.PoolManager() f = http.urlopen('GET', foil_dat_url).data.decode() f = io.StringIO(f) 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) line = line.lstrip().rstrip().replace(' ', ' ').replace( ' ', ' ').replace(' ', ' ') data = line.split(' ') # data[0] = x coord. data[1] = y coord. # 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 brep_feat_local_revolution(event=None): S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape() faces = list(Topo(S).faces()) F1 = faces[2] surf = BRep_Tool_Surface(F1) D = gp_OX() MW1 = BRepBuilderAPI_MakeWire() p1 = gp_Pnt2d(100., 100.) p2 = gp_Pnt2d(200., 100.) aline = GCE2d_MakeLine(p1, p2).Value() MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge()) p1 = gp_Pnt2d(200., 100.) p2 = gp_Pnt2d(150., 200.) aline = GCE2d_MakeLine(p1, p2).Value() MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge()) p1 = gp_Pnt2d(150., 200.) p2 = gp_Pnt2d(100., 100.) aline = GCE2d_MakeLine(p1, p2).Value() MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge()) MKF1 = BRepBuilderAPI_MakeFace() MKF1.Init(surf, False, 1e-6) MKF1.Add(MW1.Wire()) FP = MKF1.Face() breplib_BuildCurves3d(FP) MKrev = BRepFeat_MakeRevol(S, FP, F1, D, 1, True) F2 = faces[4] MKrev.Perform(F2) display.EraseAll() display.DisplayShape(MKrev.Shape()) display.FitAll()
def parabola(event=None): # P is the vertex point # P and D give the axis of symmetry # 6 is the focal length of the parabola a_pnt = gp_Pnt2d(2, 3) a_dir = gp_Dir2d(4, 5) an_ax = gp_Ax22d(a_pnt, a_dir, True) para = gp_Parab2d(an_ax, 6) display.DisplayShape(a_pnt) display.DisplayMessage(a_pnt, "P") aParabola = GCE2d_MakeParabola(para) gParabola = aParabola.Value() aTrimmedCurve = Geom2d_TrimmedCurve(gParabola, -100, 100, True) display.DisplayShape(aTrimmedCurve, update=True)
def NumPyArrayToPythonOCCArray(numpy_array): """ transform array from nparray (NumPy) to TColgp_Array1OfPnt2d (pythonOCC) format INPUT parameter: numpy_array : array containing points in rows and coordinates in columns (Nx2-nparray, NumPy) OUTPUT: pythonOCC_array: array containing points in rows and coordinates in columns (TColgp_Array1OfPnt2d, pythonOCC) """ # create arrays of points holding coordinates pythonOCC_array = TColgp_Array1OfPnt2d(1, size(numpy_array, 0)) # set entries for index in range(0, size(numpy_array, 0)): pythonOCC_array.SetValue(index + 1, gp_Pnt2d(numpy_array[index, 0], numpy_array[index, 1])) return pythonOCC_array
def _makeUnique(self, coords): """ Remove redundant entries from coordinate array INPUT parameter: coords : list of 2d-coordinate points (TColgp_Array1OfPnt2d, pythonOCC) OUTPUT: unique_coords : list of unique coordinates (TColgp_Array1OfPnt2d, pythonOCC) """ # tolerance for comparisons tol = self._tol_default * self.data.get('m_n') # upper and lower index of point-array upper_index = coords.Upper() lower_index = coords.Lower() # remove redundant entries uniques = list() for index in range(lower_index, upper_index + 1): unique = True for unique_point in uniques: if abs(coords.Value(index).X() - unique_point[0]) < tol and \ abs(coords.Value(index).Y() - unique_point[1]) < tol: unique = False if unique: uniques.append([coords.Value(index).X(), coords.Value(index).Y()]) # copy list entries into coordinate array length_uniques = len(uniques) unique_coords = TColgp_Array1OfPnt2d(lower_index, lower_index + length_uniques - 1) for index in range(lower_index, lower_index + length_uniques): if abs(uniques[index - 1][0]) > tol: unique_x = uniques[index - 1][0] else: unique_x = 0.0 if abs(uniques[index - 1][1]) > tol: unique_y = uniques[index - 1][1] else: unique_y = 0.0 unique_coords.SetValue(index, gp_Pnt2d(unique_x, unique_y)) return unique_coords
def make_shape(self): # 1 - retrieve the data from the UIUC airfoil data page foil_dat_url = 'http://www.ae.illinois.edu/m-selig/ads/coord_seligFmt/%s.dat' % self.profile f = urllib2.urlopen(foil_dat_url) 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) line = line.lstrip().rstrip().replace(' ',' ').replace(' ',' ').replace(' ',' ') data = line.split(' ') # data[0] = x coord. data[1] = y coord. # 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 brepfeat_prism(event=None): box = BRepPrimAPI_MakeBox(400, 250, 300).Shape() faces = Topo(box).faces() for i in range(3): face = next(faces) srf = BRep_Tool_Surface(face) c = gp_Circ2d(gp_Ax2d(gp_Pnt2d(200, 130), gp_Dir2d(1, 0)), 75) circle = Geom2d_Circle(c).GetHandle() wire = BRepBuilderAPI_MakeWire() wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, 0., pi).Edge()) wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, pi, 2. * pi).Edge()) wire.Build() display.DisplayShape(wire.Wire()) mkf = BRepBuilderAPI_MakeFace() mkf.Init(srf, False, 1e-6) mkf.Add(wire.Wire()) mkf.Build() new_face = mkf.Face() breplib_BuildCurves3d(new_face) display.DisplayColoredShape(box, 'GREEN') display.DisplayShape(new_face) """ prism = BRepFeat_MakeDPrism(box, mkf.Face(), face, 100, True, True) prism.Perform(400) assert prism.IsDone() display.EraseAll() display.DisplayShape(prism.Shape()) """ #display.DisplayColoredShape(wire.Wire(), 'RED') display.FitAll()
def brepfeat_prism(event=None): box = BRepPrimAPI_MakeBox(400, 250, 300).Shape() faces = Topo(box).faces() for i in range(5): face = next(faces) srf = BRep_Tool_Surface(face) c = gp_Circ2d(gp_Ax2d(gp_Pnt2d(200, 130), gp_Dir2d(1, 0)), 75) circle = Geom2d_Circle(c).GetHandle() wire = BRepBuilderAPI_MakeWire() wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, 0., pi).Edge()) wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, pi, 2. * pi).Edge()) wire.Build() display.DisplayShape(wire.Wire()) mkf = BRepBuilderAPI_MakeFace() mkf.Init(srf, False, 1e-6) mkf.Add(wire.Wire()) mkf.Build() new_face = mkf.Face() breplib_BuildCurves3d(new_face) display.DisplayShape(new_face) prism = BRepFeat_MakeDPrism(box, mkf.Face(), face, 100, True, True) prism.Perform(400) assert prism.IsDone() display.EraseAll() display.DisplayShape(prism.Shape()) display.DisplayColoredShape(wire.Wire(), 'RED') display.FitAll()
def testProjectingPointInaccurately(): """ test projecting a point onto a curve """ h = makeHeartWire() # convert to twod curves curves = [] for e in Wrappers.Wire(h).edges2(): curves.append(get2dCurveFrom3dEdge(e)) # project a point onto the wire. we want to see if slight inaccurcies will project. # this simulates trying to find points on a curve that were put there via pixels display.DisplayShape(h) DISTANCE = 0.004 p = gp.gp_Pnt2d(2.0 + DISTANCE, 2.0 - DISTANCE) display.DisplayShape(Wrappers.make_vertex(gp.gp_Pnt(p.X(), p.Y(), 0))) for c in curves: r = projectPointOnCurve2d(c, p, 0.005) if r is not None: (param, pnt) = r print "found point: parmater-%0.3f, point-(%0.3f,%0.3f)" % (param, pnt.X(), pnt.Y()) display.DisplayShape(Wrappers.make_vertex(gp.gp_Pnt(pnt.X(), pnt.Y(), 0)))
def points_from_curve(): radius = 5. abscissa = 3. circle = Geom2d_Circle(gp_OX2d(), radius, True) gac = Geom2dAdaptor_Curve(circle.GetHandle()) ua = GCPnts_UniformAbscissa(gac, abscissa) a_sequence = [] if ua.IsDone(): n = ua.NbPoints() for count in range(1, n + 1): p = gp_Pnt2d() circle.D0(ua.Parameter(count), p) a_sequence.append(p) # convert analytic to bspline display.DisplayShape(circle, update=True) i = 0 for p in a_sequence: i += 1 pstring = 'P%i : parameter %f' % (i, ua.Parameter(i)) pnt = gp_Pnt(p.X(), p.Y(), 0) # display points display.DisplayShape(pnt, update=True) display.DisplayMessage(pnt, pstring)
def makePeriodic(self, center, positive=1.0): """ center is the center of the first hex, as an (x,y,z) tuple. positive is 1 for the upper portion, -1 for the lower portion makes the upper part of a periodic hex pattern. Note that the upper and lower flats are adjusted for line width, so that they can be stacked and allow double-drawing of the horizontal flats. this offset is controlled by the linewidth parameter. the points are numbered below (2) (3) /-----\ ____/ + \_____ (0) (1) (4) (5) """ cX = center[0] cY = center[1] (XA, YA) = self.lineWidthAdjust() baselineY = (cY) + (YA * positive) topY = cY + ((self.width / 2.0 - YA) * positive) p0 = gp.gp_Pnt2d(cX - self.cartesianSpacing()[0], baselineY) p1 = gp.gp_Pnt2d(cX - self.centerToCorner() + XA, baselineY) p2 = gp.gp_Pnt2d(cX - self.halfAflat() - XA, topY) p3 = gp.gp_Pnt2d(cX + self.halfAflat() + XA, topY) p4 = gp.gp_Pnt2d(cX + self.centerToCorner() - XA, baselineY) p5 = gp.gp_Pnt2d(cX + self.cartesianSpacing()[0], baselineY) #make the edges edges = [] edges.append(GCE2d.GCE2d_MakeSegment(p0, p1).Value()) edges.append(GCE2d.GCE2d_MakeSegment(p1, p2).Value()) edges.append(GCE2d.GCE2d_MakeSegment(p2, p3).Value()) edges.append(GCE2d.GCE2d_MakeSegment(p3, p4).Value()) edges.append(GCE2d.GCE2d_MakeSegment(p4, p5).Value()) return edges
aFaceExplorer.Next() facesToRemove = TopTools_ListOfShape() facesToRemove.Append(faceToRemove) myBody = BRepOffsetAPI_MakeThickSolid(myBody.Shape(), facesToRemove, -thickness / 50.0, 0.001) # Set up our surfaces for the threading on the neck neckAx2_Ax3 = gp_Ax3(neckLocation, gp_DZ()) aCyl1 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 0.99) aCyl2 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 1.05) # Set up the curves for the threads on the bottle's neck aPnt = gp_Pnt2d(2.0 * math.pi, myNeckHeight / 2.0) aDir = gp_Dir2d(2.0 * math.pi, myNeckHeight / 4.0) anAx2d = gp_Ax2d(aPnt, aDir) aMajor = 2.0 * math.pi aMinor = myNeckHeight / 10.0 anEllipse1 = Geom2d_Ellipse(anAx2d, aMajor, aMinor) anEllipse2 = Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4.0) anArc1 = Geom2d_TrimmedCurve(Handle_Geom2d_Ellipse(anEllipse1), 0, math.pi) anArc2 = Geom2d_TrimmedCurve(Handle_Geom2d_Ellipse(anEllipse2), 0, math.pi) anEllipsePnt1 = anEllipse1.Value(0) anEllipsePnt2 = anEllipse1.Value(math.pi)
def variable_filleting(event=None): display.EraseAll() # Create Box Box = BRepPrimAPI_MakeBox(200, 200, 200).Shape() # Fillet Rake = BRepFilletAPI_MakeFillet(Box) ex = Topo(Box).edges() next(ex) next(ex) next(ex) Rake.Add(8, 50, next(ex)) Rake.Build() if Rake.IsDone(): evolvedBox = Rake.Shape() display.DisplayShape(evolvedBox) else: print("Rake not done.") # Create Cylinder Cylinder = BRepPrimAPI_MakeCylinder( gp_Ax2(gp_Pnt(-300, 0, 0), gp_Dir(0, 0, 1)), 100, 200).Shape() fillet = BRepFilletAPI_MakeFillet(Cylinder) TabPoint2 = TColgp_Array1OfPnt2d(0, 20) for i in range(0, 20): Point2d = gp_Pnt2d(i * 2 * pi / 19, 60 * cos(i * pi / 19 - pi / 2) + 10) TabPoint2.SetValue(i, Point2d) exp2 = Topo(Cylinder).edges() fillet.Add(TabPoint2, next(exp2)) fillet.Build() if fillet.IsDone(): LawEvolvedCylinder = fillet.Shape() display.DisplayShape(LawEvolvedCylinder) else: print("fillet not done.") ## TODO : fillet not done P = gp_Pnt(350, 0, 0) Box2 = BRepPrimAPI_MakeBox(P, 200, 200, 200).Shape() afillet = BRepFilletAPI_MakeFillet(Box2) TabPoint = TColgp_Array1OfPnt2d(1, 6) P1 = gp_Pnt2d(0., 8.) P2 = gp_Pnt2d(0.2, 16.) P3 = gp_Pnt2d(0.4, 25.) P4 = gp_Pnt2d(0.6, 55.) P5 = gp_Pnt2d(0.8, 28.) P6 = gp_Pnt2d(1., 20.) TabPoint.SetValue(1, P1) TabPoint.SetValue(2, P2) TabPoint.SetValue(3, P3) TabPoint.SetValue(4, P4) TabPoint.SetValue(5, P5) TabPoint.SetValue(6, P6) exp = Topo(Box2).edges() next(exp) next(exp) next(exp) afillet.Add(TabPoint, next(exp)) afillet.Build() if afillet.IsDone(): LawEvolvedBox = afillet.Shape() else: print("aFillet not done.") display.DisplayShape(LawEvolvedBox) display.FitAll()
faceToRemove = aFace aFaceExplorer.Next() facesToRemove = TopTools_ListOfShape() facesToRemove.Append(faceToRemove) myBody = BRepOffsetAPI_MakeThickSolid(myBody.Shape(), facesToRemove, -thickness / 50.0, 0.001) # Set up our surfaces for the threading on the neck neckAx2_Ax3 = gp_Ax3(neckLocation, gp_DZ()) aCyl1 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 0.99) aCyl2 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 1.05) # Set up the curves for the threads on the bottle's neck aPnt = gp_Pnt2d(2.0 * math.pi, myNeckHeight / 2.0) aDir = gp_Dir2d(2.0 * math.pi, myNeckHeight / 4.0) anAx2d = gp_Ax2d(aPnt, aDir) aMajor = 2.0 * math.pi aMinor = myNeckHeight / 10.0 anEllipse1 = Geom2d_Ellipse(anAx2d, aMajor, aMinor) anEllipse2 = Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4.0) anArc1 = Geom2d_TrimmedCurve(Handle_Geom2d_Ellipse(anEllipse1), 0, math.pi) anArc2 = Geom2d_TrimmedCurve(Handle_Geom2d_Ellipse(anEllipse2), 0, math.pi) anEllipsePnt1 = anEllipse1.Value(0) anEllipsePnt2 = anEllipse1.Value(math.pi)
def tP(x, y): "convert x-y tuple to a gp pnt" return gp.gp_Pnt2d(x, y)
def as_2d(self): '''returns a gp_Pnt2d version of self''' return gp_Pnt2d(*self._pnt.Coord()[:2])
def build_tooth(): base_center = gp_Pnt2d( pitch_circle_radius + (tooth_radius - roller_radius), 0) base_circle = gp_Circ2d(gp_Ax2d(base_center, gp_Dir2d()), tooth_radius) trimmed_base = GCE2d_MakeArcOfCircle(base_circle, M_PI - (roller_contact_angle / 2.), M_PI).Value() Proxy(trimmed_base).Reverse() # just a trick p0 = Proxy(trimmed_base).StartPoint() p1 = Proxy(trimmed_base).EndPoint() # Determine the center of the profile circle x_distance = cos( roller_contact_angle / 2.) * (profile_radius + tooth_radius) y_distance = sin( roller_contact_angle / 2.) * (profile_radius + tooth_radius) profile_center = gp_Pnt2d(pitch_circle_radius - x_distance, y_distance) # Construct the profile circle gp_Circ2d profile_circle = gp_Circ2d(gp_Ax2d(profile_center, gp_Dir2d()), profile_center.Distance(p1)) geom_profile_circle = GCE2d_MakeCircle(profile_circle).Value() # Construct the outer circle gp_Circ2d outer_circle = gp_Circ2d(gp_Ax2d(gp_Pnt2d(0, 0), gp_Dir2d()), top_radius) geom_outer_circle = GCE2d_MakeCircle(outer_circle).Value() inter = Geom2dAPI_InterCurveCurve(geom_profile_circle, geom_outer_circle) num_points = inter.NbPoints() assert isinstance(p1, gp_Pnt2d) if num_points == 2: if p1.Distance(inter.Point(1)) < p1.Distance(inter.Point(2)): p2 = inter.Point(1) else: p2 = inter.Point(2) elif num_points == 1: p2 = inter.Point(1) else: exit(-1) # Trim the profile circle and mirror trimmed_profile = GCE2d_MakeArcOfCircle(profile_circle, p1, p2).Value() # Calculate the outermost point p3 = gp_Pnt2d( cos(tooth_angle / 2.) * top_radius, sin(tooth_angle / 2.) * top_radius) # and use it to create the third arc trimmed_outer = GCE2d_MakeArcOfCircle(outer_circle, p2, p3).Value() # Mirror and reverse the three arcs mirror_axis = gp_Ax2d(gp_Origin2d(), gp_DX2d().Rotated(tooth_angle / 2.)) mirror_base = Handle_Geom2d_TrimmedCurve.DownCast( Proxy(trimmed_base).Copy()) mirror_profile = Handle_Geom2d_TrimmedCurve.DownCast( Proxy(trimmed_profile).Copy()) mirror_outer = Handle_Geom2d_TrimmedCurve.DownCast( Proxy(trimmed_outer).Copy()) Proxy(mirror_base).Mirror(mirror_axis) Proxy(mirror_profile).Mirror(mirror_axis) Proxy(mirror_outer).Mirror(mirror_axis) Proxy(mirror_base).Reverse() Proxy(mirror_profile).Reverse() Proxy(mirror_outer).Reverse() # Replace the two outer arcs with a single one outer_start = Proxy(trimmed_outer).StartPoint() outer_mid = Proxy(trimmed_outer).EndPoint() outer_end = Proxy(mirror_outer).EndPoint() outer_arc = GCE2d_MakeArcOfCircle(outer_start, outer_mid, outer_end).Value() # Create an arc for the inside of the wedge inner_circle = gp_Circ2d(gp_Ax2d(gp_Pnt2d(0, 0), gp_Dir2d()), top_radius - roller_diameter) inner_start = gp_Pnt2d(top_radius - roller_diameter, 0) inner_arc = GCE2d_MakeArcOfCircle(inner_circle, inner_start, tooth_angle).Value() Proxy(inner_arc).Reverse() # Convert the 2D arcs and two extra lines to 3D edges plane = gp_Pln(gp_Origin(), gp_DZ()) arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_base, plane)).Edge() arc2 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_profile, plane)).Edge() arc3 = BRepBuilderAPI_MakeEdge(geomapi_To3d(outer_arc, plane)).Edge() arc4 = BRepBuilderAPI_MakeEdge(geomapi_To3d(mirror_profile, plane)).Edge() arc5 = BRepBuilderAPI_MakeEdge(geomapi_To3d(mirror_base, plane)).Edge() p4 = Proxy(mirror_base).EndPoint() p5 = Proxy(inner_arc).StartPoint() lin1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4.X(), p4.Y(), 0), gp_Pnt(p5.X(), p5.Y(), 0)).Edge() arc6 = BRepBuilderAPI_MakeEdge(geomapi_To3d(inner_arc, plane)).Edge() p6 = Proxy(inner_arc).EndPoint() lin2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p6.X(), p6.Y(), 0), gp_Pnt(p0.X(), p0.Y(), 0)).Edge() wire = BRepBuilderAPI_MakeWire(arc1) wire.Add(arc2) wire.Add(arc3) wire.Add(arc4) wire.Add(arc5) wire.Add(lin1) wire.Add(arc6) wire.Add(lin2) face = BRepBuilderAPI_MakeFace(wire.Wire()) wedge = BRepPrimAPI_MakePrism(face.Shape(), gp_Vec(0.0, 0.0, thickness)) return wedge.Shape()
def bspline(): # the first bspline array = TColgp_Array1OfPnt2d(1, 5) array.SetValue(1, gp_Pnt2d(0, 0)) array.SetValue(2, gp_Pnt2d(1, 2)) array.SetValue(3, gp_Pnt2d(2, 3)) array.SetValue(4, gp_Pnt2d(4, 3)) array.SetValue(5, gp_Pnt2d(5, 5)) bspline_1 = Geom2dAPI_PointsToBSpline(array).Curve() # the second one harray = TColgp_HArray1OfPnt2d(1, 5) harray.SetValue(1, gp_Pnt2d(0, 0)) harray.SetValue(2, gp_Pnt2d(1, 2)) harray.SetValue(3, gp_Pnt2d(2, 3)) harray.SetValue(4, gp_Pnt2d(4, 3)) harray.SetValue(5, gp_Pnt2d(5, 5)) anInterpolation = Geom2dAPI_Interpolate(harray.GetHandle(), False, 0.01) anInterpolation.Perform() bspline_2 = anInterpolation.Curve() harray2 = TColgp_HArray1OfPnt2d(1, 5) harray2.SetValue(1, gp_Pnt2d(11, 0)) harray2.SetValue(2, gp_Pnt2d(12, 2)) harray2.SetValue(3, gp_Pnt2d(13, 3)) harray2.SetValue(4, gp_Pnt2d(15, 3)) harray2.SetValue(5, gp_Pnt2d(16, 5)) anInterpolation2 = Geom2dAPI_Interpolate(harray.GetHandle(), True, 0.01) anInterpolation2.Perform() bspline_3 = anInterpolation2.Curve() for j in range(array.Lower(), array.Upper()+1): p = array.Value(j) display.DisplayShape(p, update=False) for j in range(harray.Lower(), harray.Upper()+1): p = harray.Value(j) display.DisplayShape(p, update=False) display.DisplayShape(bspline_1, update=False) display.DisplayShape(bspline_2, update=False, color='GREEN') display.DisplayShape(bspline_3, update=True, color='BLUE')
def face(): p1 = gp_Pnt() p2 = gp_Pnt() p3 = gp_Pnt() p4 = gp_Pnt() p5 = gp_Pnt() p6 = gp_Pnt() # The white Face sphere = gp_Sphere(gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 150) green_face = BRepBuilderAPI_MakeFace(sphere, 0.1, 0.7, 0.2, 0.9) # The red face p1.SetCoord(-15, 200, 10) p2.SetCoord(5, 204, 0) p3.SetCoord(15, 200, 0) p4.SetCoord(-15, 20, 15) p5.SetCoord(-5, 20, 0) p6.SetCoord(15, 20, 35) array = TColgp_Array2OfPnt(1, 3, 1, 2) array.SetValue(1, 1, p1) array.SetValue(2, 1, p2) array.SetValue(3, 1, p3) array.SetValue(1, 2, p4) array.SetValue(2, 2, p5) array.SetValue(3, 2, p6) curve = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2, 0.001).Surface() red_face = BRepBuilderAPI_MakeFace(curve, 1e-6) #The brown face circle = gp_Circ(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 80) Edge1 = BRepBuilderAPI_MakeEdge(circle, 0, math.pi) Edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, -80), gp_Pnt(0, -10, 40)) Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, -10, 40), gp_Pnt(0, 0, 80)) ##TopoDS_Wire YellowWire MW1 = BRepBuilderAPI_MakeWire(Edge1.Edge(), Edge2.Edge(), Edge3.Edge()) if MW1.IsDone(): yellow_wire = MW1.Wire() brown_face = BRepBuilderAPI_MakeFace(yellow_wire) #The pink face p1.SetCoord(35, -200, 40) p2.SetCoord(50, -204, 30) p3.SetCoord(65, -200, 30) p4.SetCoord(35, -20, 45) p5.SetCoord(45, -20, 30) p6.SetCoord(65, -20, 65) array2 = TColgp_Array2OfPnt(1, 3, 1, 2) array2.SetValue(1, 1, p1) array2.SetValue(2, 1, p2) array2.SetValue(3, 1, p3) array2.SetValue(1, 2, p4) array2.SetValue(2, 2, p5) array2.SetValue(3, 2, p6) BSplineSurf = GeomAPI_PointsToBSplineSurface(array2, 3, 8, GeomAbs_C2, 0.001) aFace = BRepBuilderAPI_MakeFace(BSplineSurf.Surface(), 1e-6).Face() ## ##//2d lines P12d = gp_Pnt2d(0.9, 0.1) P22d = gp_Pnt2d(0.2, 0.7) P32d = gp_Pnt2d(0.02, 0.1) ## line1 = Geom2d_Line(P12d, gp_Dir2d((0.2-0.9), (0.7-0.1))) line2 = Geom2d_Line(P22d, gp_Dir2d((0.02-0.2), (0.1-0.7))) line3 = Geom2d_Line(P32d, gp_Dir2d((0.9-0.02), (0.1-0.1))) ## ##//Edges are on the BSpline surface Edge1 = BRepBuilderAPI_MakeEdge(line1.GetHandle(), BSplineSurf.Surface(), 0, P12d.Distance(P22d)).Edge() Edge2 = BRepBuilderAPI_MakeEdge(line2.GetHandle(), BSplineSurf.Surface(), 0, P22d.Distance(P32d)).Edge() Edge3 = BRepBuilderAPI_MakeEdge(line3.GetHandle(), BSplineSurf.Surface(), 0, P32d.Distance(P12d)).Edge() ## Wire1 = BRepBuilderAPI_MakeWire(Edge1, Edge2, Edge3).Wire() Wire1.Reverse() pink_face = BRepBuilderAPI_MakeFace(aFace, Wire1).Face() breplib_BuildCurves3d(pink_face) display.DisplayColoredShape(green_face.Face(), 'GREEN') display.DisplayColoredShape(red_face.Face(), 'RED') display.DisplayColoredShape(pink_face, Quantity_Color(Quantity_NOC_PINK)) display.DisplayColoredShape(brown_face.Face(), 'BLUE') display.DisplayColoredShape(yellow_wire, 'YELLOW', update=True)
def variable_filleting(event=None): # Create Box Box = BRepPrimAPI_MakeBox(200, 200, 200).Shape() # Fillet Rake = BRepFilletAPI_MakeFillet(Box) ex = Topo(Box).edges() next(ex) next(ex) next(ex) Rake.Add(8, 50, next(ex)) Rake.Build() if Rake.IsDone(): evolvedBox = Rake.Shape() # Create Cylinder Cylinder = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(-300, 0, 0), gp_Dir(0, 0, 1)), 100, 200).Shape() fillet = BRepFilletAPI_MakeFillet(Cylinder) TabPoint2 = TColgp_Array1OfPnt2d(0, 20) for i in range(0, 20): Point2d = gp_Pnt2d(i * 2 * pi / 19, 60 * cos(i * pi / 19 - pi / 2) + 10) TabPoint2.SetValue(i, Point2d) exp2 = Topo(Cylinder).edges() fillet.Add(TabPoint2, next(exp2)) fillet.Build() if fillet.IsDone(): LawEvolvedCylinder = fillet.Shape() display.DisplayShape(LawEvolvedCylinder) P = gp_Pnt(350, 0, 0) Box2 = BRepPrimAPI_MakeBox(P, 200, 200, 200).Shape() afillet = BRepFilletAPI_MakeFillet(Box2) TabPoint = TColgp_Array1OfPnt2d(1, 6) P1 = gp_Pnt2d(0.0, 8.0) P2 = gp_Pnt2d(0.2, 16.0) P3 = gp_Pnt2d(0.4, 25.0) P4 = gp_Pnt2d(0.6, 55.0) P5 = gp_Pnt2d(0.8, 28.0) P6 = gp_Pnt2d(1.0, 20.0) TabPoint.SetValue(1, P1) TabPoint.SetValue(2, P2) TabPoint.SetValue(3, P3) TabPoint.SetValue(4, P4) TabPoint.SetValue(5, P5) TabPoint.SetValue(6, P6) exp = Topo(Box2).edges() next(exp) next(exp) next(exp) afillet.Add(TabPoint, next(exp)) afillet.Build() if afillet.IsDone(): LawEvolvedBox = afillet.Shape() display.EraseAll() display.DisplayShape(Box) display.EraseAll() display.DisplayShape(evolvedBox) display.DisplayShape(LawEvolvedBox) display.FitAll()
def brep_feat_extrusion_protrusion(event=None): # Extrusion S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape() faces = Topo(S).faces() F = next(faces) surf1 = BRep_Tool_Surface(F) Pl1 = Handle_Geom_Plane_DownCast(surf1).GetObject() D1 = Pl1.Pln().Axis().Direction().Reversed() MW = BRepBuilderAPI_MakeWire() p1, p2 = gp_Pnt2d(200., -100.), gp_Pnt2d(100., -100.) aline = GCE2d_MakeLine(p1, p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(100., -100.), gp_Pnt2d(100., -200.) aline = GCE2d_MakeLine(p1, p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(100., -200.), gp_Pnt2d(200., -200.) aline = GCE2d_MakeLine(p1, p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(200., -200.), gp_Pnt2d(200., -100.) aline = GCE2d_MakeLine(p1, p2).Value() MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge()) MKF = BRepBuilderAPI_MakeFace() MKF.Init(surf1, False, 1e-6) MKF.Add(MW.Wire()) FP = MKF.Face() breplib_BuildCurves3d(FP) display.EraseAll() MKP = BRepFeat_MakePrism(S, FP, F, D1, 0, True) MKP.PerformThruAll() res1 = MKP.Shape() display.DisplayShape(res1) # Protrusion next(faces) F2 = next(faces) surf2 = BRep_Tool_Surface(F2) Pl2 = Handle_Geom_Plane_DownCast(surf2).GetObject() D2 = Pl2.Pln().Axis().Direction().Reversed() MW2 = BRepBuilderAPI_MakeWire() p1, p2 = gp_Pnt2d(100., 100.), gp_Pnt2d(200., 100.) aline = GCE2d_MakeLine(p1, p2).Value() MW2.Add(BRepBuilderAPI_MakeEdge(aline, surf2, 0., p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(200., 100.), gp_Pnt2d(150., 200.) aline = GCE2d_MakeLine(p1, p2).Value() MW2.Add(BRepBuilderAPI_MakeEdge(aline, surf2, 0., p1.Distance(p2)).Edge()) p1, p2 = gp_Pnt2d(150., 200.), gp_Pnt2d(100., 100.) aline = GCE2d_MakeLine(p1, p2).Value() MW2.Add(BRepBuilderAPI_MakeEdge(aline, surf2, 0., p1.Distance(p2)).Edge()) MKF2 = BRepBuilderAPI_MakeFace() MKF2.Init(surf2, False, 1e-6) MKF2.Add(MW2.Wire()) MKF2.Build() FP = MKF2.Face() breplib_BuildCurves3d(FP) MKP2 = BRepFeat_MakePrism(res1, FP, F2, D2, 0, True) MKP2.PerformThruAll() display.EraseAll() trf = gp_Trsf() trf.SetTranslation(gp_Vec(0, 0, 300)) gtrf = gp_GTrsf() gtrf.SetTrsf(trf) tr = BRepBuilderAPI_GTransform(MKP2.Shape(), gtrf, True) fused = BRepAlgoAPI_Fuse(tr.Shape(), MKP2.Shape()) fused.RefineEdges() fused.Build() print('Boolean operation error status:', fused.ErrorStatus()) display.DisplayShape(fused.Shape()) display.FitAll()
def bspline(): # the first bspline array = TColgp_Array1OfPnt2d(1, 5) array.SetValue(1, gp_Pnt2d(0, 0)) array.SetValue(2, gp_Pnt2d(1, 2)) array.SetValue(3, gp_Pnt2d(2, 3)) array.SetValue(4, gp_Pnt2d(4, 3)) array.SetValue(5, gp_Pnt2d(5, 5)) bspline_1 = Geom2dAPI_PointsToBSpline(array).Curve() # the second one harray = TColgp_HArray1OfPnt2d(1, 5) harray.SetValue(1, gp_Pnt2d(0, 0)) harray.SetValue(2, gp_Pnt2d(1, 2)) harray.SetValue(3, gp_Pnt2d(2, 3)) harray.SetValue(4, gp_Pnt2d(4, 3)) harray.SetValue(5, gp_Pnt2d(5, 5)) anInterpolation = Geom2dAPI_Interpolate(harray.GetHandle(), False, 0.01) anInterpolation.Perform() bspline_2 = anInterpolation.Curve() harray2 = TColgp_HArray1OfPnt2d(1, 5) harray2.SetValue(1, gp_Pnt2d(11, 0)) harray2.SetValue(2, gp_Pnt2d(12, 2)) harray2.SetValue(3, gp_Pnt2d(13, 3)) harray2.SetValue(4, gp_Pnt2d(15, 3)) harray2.SetValue(5, gp_Pnt2d(16, 5)) anInterpolation2 = Geom2dAPI_Interpolate(harray.GetHandle(), True, 0.01) anInterpolation2.Perform() bspline_3 = anInterpolation2.Curve() for j in range(array.Lower(), array.Upper() + 1): p = array.Value(j) display.DisplayShape(p, update=False) for j in range(harray.Lower(), harray.Upper() + 1): p = harray.Value(j) display.DisplayShape(p, update=False) display.DisplayShape(bspline_1, update=False) display.DisplayShape(bspline_2, update=False, color='GREEN') display.DisplayShape(bspline_3, update=True, color='BLUE')
def round_tooth(wedge): round_x = 2.6 round_z = 0.06 * pitch round_radius = pitch # Determine where the circle used for rounding has to start and stop p2d_1 = gp_Pnt2d(top_radius - round_x, 0) p2d_2 = gp_Pnt2d(top_radius, round_z) # Construct the rounding circle round_circle = GccAna_Circ2d2TanRad(p2d_1, p2d_2, round_radius, 0.01) if (round_circle.NbSolutions() != 2): exit(-2) round_circle_2d_1 = round_circle.ThisSolution(1) round_circle_2d_2 = round_circle.ThisSolution(2) if (round_circle_2d_1.Position().Location().Coord()[1] >= 0): round_circle_2d = round_circle_2d_1 else: round_circle_2d = round_circle_2d_2 # Remove the arc used for rounding trimmed_circle = GCE2d_MakeArcOfCircle(round_circle_2d, p2d_1, p2d_2).Value() # Calculate extra points used to construct lines p1 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y()) p2 = gp_Pnt(p2d_2.X(), 0, p2d_2.Y()) p3 = gp_Pnt(p2d_2.X() + 1, 0, p2d_2.Y()) p4 = gp_Pnt(p2d_2.X() + 1, 0, p2d_1.Y() - 1) p5 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y() - 1) # Convert the arc and four extra lines into 3D edges plane = gp_Pln(gp_Ax3(gp_Origin(), gp_DY().Reversed(), gp_DX())) arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_circle, plane)).Edge() lin1 = BRepBuilderAPI_MakeEdge(p2, p3).Edge() lin2 = BRepBuilderAPI_MakeEdge(p3, p4).Edge() lin3 = BRepBuilderAPI_MakeEdge(p4, p5).Edge() lin4 = BRepBuilderAPI_MakeEdge(p5, p1).Edge() # Make a wire composed of the edges round_wire = BRepBuilderAPI_MakeWire(arc1) round_wire.Add(lin1) round_wire.Add(lin2) round_wire.Add(lin3) round_wire.Add(lin4) # Turn the wire into a face round_face = BRepBuilderAPI_MakeFace(round_wire.Wire()).Shape() # Revolve the face around the Z axis over the tooth angle rounding_cut_1 = BRepPrimAPI_MakeRevol(round_face, gp_OZ(), tooth_angle).Shape() # Construct a mirrored copy of the first cutting shape mirror = gp_Trsf() mirror.SetMirror(gp_XOY()) mirrored_cut_1 = BRepBuilderAPI_Transform(rounding_cut_1, mirror, True).Shape() # and translate it so that it ends up on the other side of the wedge translate = gp_Trsf() translate.SetTranslation(gp_Vec(0, 0, thickness)) rounding_cut_2 = BRepBuilderAPI_Transform(mirrored_cut_1, translate, False).Shape() # Cut the wedge using the first and second cutting shape cut_1 = BRepAlgoAPI_Cut(wedge, rounding_cut_1).Shape() cut_2 = BRepAlgoAPI_Cut(cut_1, rounding_cut_2).Shape() return cut_2
def addPoint(self,x,y): p = gp.gp_Pnt2d(x,y); self.points.append( p );
def addPoint(self, x, y): p = gp.gp_Pnt2d(x, y) self.points.append(p)