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 edgeFromTwoPoints(p1, p2): "make a linear edge from two 2d points. p1 and p2 are simple (x,y) tuples " builder = BRepBuilderAPI.BRepBuilderAPI_MakeEdge2d(tP(p1[0], p1[1]), tP(p2[0], p2[1])) builder.Build() if builder.IsDone(): return builder.Edge() else: print "error making edge" return None
def displayCurve(curve): """ Displays a curve. kind of a pain, since curves must be converted to edges first """ edge = BRepBuilderAPI.BRepBuilderAPI_MakeEdge2d(curve).Edge() display.DisplayShape(edge, update=False)