def makeHeartWire2d(): "make a heart wire in 2d" e1 = edgeFromTwoPoints((0, 0), (4.0, 4.0)) circle = gp.gp_Circ2d(gp.gp_Ax2d(tP(2, 4), gp.gp().DX2d()), 2) e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge2d(circle, tP(4, 4), tP(0, 4)).Edge() circle = gp.gp_Circ2d(gp.gp_Ax2d(tP(-2, 4), gp.gp().DX2d()), 2) e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge2d(circle, tP(0, 4), tP(-4, 4)).Edge() e4 = edgeFromTwoPoints((-4, 4), (0, 0)) return Wrappers.wireFromEdges([e1, e2, e3, e4])
def intersectWiresUsingDistShapeShape(wire, edges): "intersect a wire with a series of edges. naive algorithm without bounding box sorting " ipoints = [] w = Wrappers.Wire(wire) circle = gp.gp_Circ2d(gp.gp_Ax2d(tP(2, 4), gp.gp().DX2d()), 2) e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge2d(circle, tP(4, 4), tP(0, 4)).Edge() TestDisplay.display.showShape(e2) e4 = edgeFromTwoPoints((-4, 4), (0, 0)) TestDisplay.display.showShape(e4) brp = BRepExtrema.BRepExtrema_DistShapeShape(e2, e4) print "runing" brp.Perform() print "done" if brp.Value() < 0.001: print "intersection found!" #TODO need to handle the somewhat unusual cases that the intersection is #on a vertex for k in range(1, brp.NbSolution() + 1): p1 = brp.PointOnShape1(k) ipoints.append(p1.X(), p1.Y()) return (count, ipoints)
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 intersectWiresUsingDistShapeShape(wire, edges): "intersect a wire with a series of edges. naive algorithm without bounding box sorting " ipoints = [] w = Wrappers.Wire(wire) circle = gp.gp_Circ2d(gp.gp_Ax2d(tP(2, 4), gp.gp().DX2d()), 2) e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge2d(circle, tP(4, 4), tP(0, 4)).Edge() TestDisplay.display.showShape(e2) e4 = edgeFromTwoPoints((-4, 4), (0, 0)) TestDisplay.display.showShape(e4) brp = BRepExtrema.BRepExtrema_DistShapeShape(e2, e4) print "runing" brp.Perform() print "done" if brp.Value() < 0.001: print "intersection found!" # TODO need to handle the somewhat unusual cases that the intersection is # on a vertex for k in range(1, brp.NbSolution() + 1): p1 = brp.PointOnShape1(k) ipoints.append(p1.X(), p1.Y()) return (count, ipoints)
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()
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) aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2)
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) aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2)