def split_edge_with_face(event=None): display.EraseAll() p0 = gp_Pnt() vnorm = gp_Dir(1, 0, 0) pln = gp_Pln(p0, vnorm) face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face() p1 = gp_Pnt(0, 0, 15) p2 = gp_Pnt(0, 0, -15) edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge() # Initialize splitter splitter = BOPAlgo_Splitter() # Add the edge as an argument and the face as a tool. This will split # the edge with the face. splitter.AddArgument(edge) splitter.AddTool(face) splitter.Perform() edges = [] exp = TopExp_Explorer(splitter.Shape(), TopAbs_EDGE) while exp.More(): edges.append(exp.Current()) exp.Next() print('Number of edges in split shape: ', len(edges)) display.DisplayShape(edges[0], color='red') display.DisplayShape(edges[1], color='green') display.DisplayShape(edges[2], color='yellow') display.FitAll()
def points_from_intersection(): ''' @param display: ''' plane = gp_Pln(gp_Ax3(gp_XOY())) minor_radius, major_radius = 5., 8. ellips = gp_Elips(gp_YOZ(), major_radius, minor_radius) intersection = IntAna_IntConicQuad(ellips, plane, precision_Angular(), precision_Confusion()) a_plane = GC_MakePlane(plane).Value() a_surface = Geom_RectangularTrimmedSurface(a_plane, -8., 8., -12., 12., True, True) display.DisplayShape(a_surface, update=True) anEllips = GC_MakeEllipse(ellips).Value() display.DisplayShape(anEllips) if intersection.IsDone(): nb_results = intersection.NbPoints() if nb_results > 0: for i in range(1, nb_results + 1): P = intersection.Point(i) pstring = "P%i" % i display.DisplayShape(P) display.DisplayMessage(P, pstring)
def make_edge(self, *args): d = self.declaration if d.surface: # Convert the curve to 2d args = list(args) pln = gp_Pln(d.position.proxy, d.direction.proxy) args[0] = GeomAPI.To2d_(args[0], pln) args.insert(1, BRep_Tool.Surface_(d.surface)) return BRepBuilderAPI_MakeEdge(*args).Edge()
def create_shape(self): d = self.declaration pln = gp_Pln(d.position.proxy, d.direction.proxy) curve = self.curve = Geom_Plane(pln) if d.bounds: u, v = d.bounds face = BRepBuilderAPI_MakeFace(pln, u.x, v.x, u.y, v.y) else: face = BRepBuilderAPI_MakeFace(pln) self.shape = face.Face()
def make_plane(center=gp_Pnt(0, 0, 0), vec_normal=gp_Vec(0, 0, 1), extent_x_min=-100., extent_x_max=100., extent_y_min=-100., extent_y_max=100., depth=0.): if depth != 0: center = center.add_vec(gp_Vec(0, 0, depth)) PL = gp_Pln(center, vec_normal.as_dir()) face = make_face(PL, extent_x_min, extent_x_max, extent_y_min, extent_y_max) return face
def update_shape(self, change=None): d = self.declaration if d.surface: surface = d.surface else: child = self.get_first_child() if child: surface = child.shape else: pln = gp_Pln(d.position.proxy, d.direction.proxy) surface = BRepBuilderAPI_MakeFace(pln).Face() half_space = BRepPrimAPI_MakeHalfSpace(surface, d.side.proxy) # Shape doesnt work see https://tracker.dev.opencascade.org/view.php?id=29969 self.shape = half_space.Solid()
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).Edge() display.DisplayShape(edge, update=True) time.sleep(0.21)
def vectorized_slicer(li): # Create Plane defined by a point and the perpendicular direction z_values, shape = li _slices = [] for z in z_values: #print 'slicing index:', z, 'sliced by process:', os.getpid() plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0., 1.)) face = BRepBuilderAPI_MakeFace(plane).Shape() # Computes Shape/Plane intersection section = BRepAlgoAPI_Section(shape, face) section.Build() if section.IsDone(): _slices.append(section.Shape()) return _slices
def draft_angle(event=None): S = BRepPrimAPI_MakeBox(200., 300., 150.).Shape() adraft = BRepOffsetAPI_DraftAngle(S) topExp = TopExp_Explorer() topExp.Init(S, TopAbs_FACE) while topExp.More(): face = topods_Face(topExp.Current()) surf = Geom_Plane.DownCast(BRep_Tool_Surface(face)) dirf = surf.Pln().Axis().Direction() ddd = gp_Dir(0, 0, 1) if dirf.IsNormal(ddd, precision_Angular()): adraft.Add(face, ddd, math.radians(15), gp_Pln(gp_Ax3(gp_XOY()))) topExp.Next() adraft.Build() display.DisplayShape(adraft.Shape(), update=True)
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 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 split_face_with_edge(event=None): display.EraseAll() p0 = gp_Pnt() vnorm = gp_Dir(1, 0, 0) pln = gp_Pln(p0, vnorm) face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face() p1 = gp_Pnt(0, 0, 15) p2 = gp_Pnt(0, 0, -15) edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge() # Initialize splitter splitter = BOPAlgo_Splitter() # Add the face as an argument and the edge as a tool. This will split # the face with the edge. splitter.AddArgument(face) splitter.AddTool(edge) splitter.Perform() display.DisplayShape(splitter.Shape()) display.FitAll()
def split_shape(event=None): S = BRepPrimAPI_MakeBox(gp_Pnt(-100, -60, -80), 150, 200, 170).Shape() asect = BRepAlgoAPI_Section(S, gp_Pln(1, 2, 1, -15), False) asect.ComputePCurveOn1(True) asect.Approximation(True) asect.Build() R = asect.Shape() asplit = BRepFeat_SplitShape(S) for edg in TopologyExplorer(R).edges(): face = TopoDS_Face() if asect.HasAncestorFaceOn1(edg, face): asplit.Add(edg, face) asplit.Build() display.EraseAll() display.DisplayShape(asplit.Shape()) display.FitAll()
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() trimmed_base.Reverse() # just a trick p0 = trimmed_base.StartPoint() p1 = 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: sys.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 = Geom2d_TrimmedCurve.DownCast(trimmed_base.Copy()) mirror_profile = Geom2d_TrimmedCurve.DownCast(trimmed_profile.Copy()) mirror_outer = Geom2d_TrimmedCurve.DownCast(trimmed_outer.Copy()) mirror_base.Mirror(mirror_axis) mirror_profile.Mirror(mirror_axis) mirror_outer.Mirror(mirror_axis) mirror_base.Reverse() mirror_profile.Reverse() mirror_outer.Reverse() # Replace the two outer arcs with a single one outer_start = trimmed_outer.StartPoint() outer_mid = trimmed_outer.EndPoint() outer_end = 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() 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 = mirror_base.EndPoint() p5 = 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 = 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 cut_out(base): outer = gp_Circ2d(gp_OX2d(), top_radius - 1.75 * roller_diameter) inner = gp_Circ2d(gp_OX2d(), center_radius + 0.75 * roller_diameter) geom_outer = GCE2d_MakeCircle(outer).Value() geom_inner = GCE2d_MakeCircle(inner).Value() geom_inner.Reverse() base_angle = (2. * M_PI) / mounting_hole_count hole_angle = atan(hole_radius / mounting_radius) correction_angle = 3 * hole_angle left = gp_Lin2d(gp_Origin2d(), gp_DX2d()) right = gp_Lin2d(gp_Origin2d(), gp_DX2d()) left.Rotate(gp_Origin2d(), correction_angle) right.Rotate(gp_Origin2d(), base_angle - correction_angle) geom_left = GCE2d_MakeLine(left).Value() geom_right = GCE2d_MakeLine(right).Value() inter_1 = Geom2dAPI_InterCurveCurve(geom_outer, geom_left) inter_2 = Geom2dAPI_InterCurveCurve(geom_outer, geom_right) inter_3 = Geom2dAPI_InterCurveCurve(geom_inner, geom_right) inter_4 = Geom2dAPI_InterCurveCurve(geom_inner, geom_left) if inter_1.Point(1).X() > 0: p1 = inter_1.Point(1) else: p1 = inter_1.Point(2) if inter_2.Point(1).X() > 0: p2 = inter_2.Point(1) else: p2 = inter_2.Point(2) if inter_3.Point(1).X() > 0: p3 = inter_3.Point(1) else: p3 = inter_3.Point(2) if inter_4.Point(1).X() > 0: p4 = inter_4.Point(1) else: p4 = inter_4.Point(2) trimmed_outer = GCE2d_MakeArcOfCircle(outer, p1, p2).Value() trimmed_inner = GCE2d_MakeArcOfCircle(inner, p4, p3).Value() plane = gp_Pln(gp_Origin(), gp_DZ()) arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_outer, plane)).Edge() lin1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p2.X(), p2.Y(), 0), gp_Pnt(p3.X(), p3.Y(), 0)).Edge() arc2 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_inner, plane)).Edge() lin2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4.X(), p4.Y(), 0), gp_Pnt(p1.X(), p1.Y(), 0)).Edge() cutout_wire = BRepBuilderAPI_MakeWire(arc1) cutout_wire.Add(lin1) cutout_wire.Add(arc2) cutout_wire.Add(lin2) # Turn the wire into a face cutout_face = BRepBuilderAPI_MakeFace(cutout_wire.Wire()) filleted_face = BRepFilletAPI_MakeFillet2d(cutout_face.Face()) explorer = BRepTools_WireExplorer(cutout_wire.Wire()) while explorer.More(): vertex = explorer.CurrentVertex() filleted_face.AddFillet(vertex, roller_radius) explorer.Next() cutout = BRepPrimAPI_MakePrism(filleted_face.Shape(), gp_Vec(0.0, 0.0, thickness)).Shape() result = base rotate = gp_Trsf() for i in range(0, mounting_hole_count): rotate.SetRotation(gp_OZ(), i * 2. * M_PI / mounting_hole_count) rotated_cutout = BRepBuilderAPI_Transform(cutout, rotate, True) result = BRepAlgoAPI_Cut(result, rotated_cutout.Shape()).Shape() return result
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): sys.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
from OCCT.gp import gp_Pnt, gp_Pln from OCCT.ChFi2d import ChFi2d_AnaFilletAlgo from OCCT.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()