def intersect_shape_by_half_line(topods_shape, x, y, z, vx, vy, vz): r"""Intersect shape by half line starting at (x, y, z) in the direction (vx, vy, vz) This function tries to have a more intuitive interface than intersect_shape_by_line() Parameters ---------- topods_shape x : float Starting point x y : float Starting point y z : float Starting point z vx : float Direction vector x component vy : float Direction vector y component vz : float Direction vector z component Returns ------- a list of gp_Pnt, ordered in natural order going from the point where the half line starts and following the direction """ return _intersect_shape_by_line(topods_shape, gp_Lin(gp_Pnt(x, y, z), gp_Dir(vx, vy, vz)), 0, float("+inf"))
def create_shape(self): d = self.declaration if len(d.points) == 2: args = (gp_Pnt(*d.points[0]), gp_Pnt(*d.points[1])) else: args = (gp_Lin(coerce_axis(d.axis)), ) self.make_edge(*args)
def update_shape(self, change): d = self.declaration if len(d.children) == 2: points = [c.shape for c in self.children()] shape = gce_MakeLin(points[0], points[1]).Value() else: shape = gp_Lin(d.axis) self.make_edge(shape)
def update_shape(self,change): d = self.declaration if len(d.children)==2: points = [c.shape for c in self.children()] shape = gce_MakeLin(points[0],points[1]).Value() else: shape = gp_Lin(d.axis) self.make_edge(shape)
def reflect(p0, v0, ax): ray = gp_Lin(p0, vec_to_dir(v0)) intersection = IntAna_IntConicQuad(ray, gp_Pln(ax), precision_Angular(), precision_Confusion()) p1 = intersection.Point(1) vx, vy = gp_Vec(1, 0, 0), gp_Vec(0, 1, 0) handle = Geom_Plane(ax) handle.D1(0.5, 0.5, gp_Pnt(), vx, vy) vz = vx.Crossed(vy) v1 = v0.Mirrored(gp_Ax2(p1, vec_to_dir(vz))) return p1, v1
def edge(event=None): # The blud edge BlueEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80, -50, -20), gp_Pnt(-30, -60, -60)) V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20, 10, -30)) V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 7, -25)) YellowEdge = BRepBuilderAPI_MakeEdge(V1.Vertex(), V2.Vertex()) #The white edge line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0))) WhiteEdge = BRepBuilderAPI_MakeEdge(line, -20, 10) #The red edge Elips = gp_Elips(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 1, 1)), 60, 30) RedEdge = BRepBuilderAPI_MakeEdge(Elips, 0, math.pi / 2) # The green edge and the both extreme vertex P1 = gp_Pnt(-15, 200, 10) P2 = gp_Pnt(5, 204, 0) P3 = gp_Pnt(15, 200, 0) P4 = gp_Pnt(-15, 20, 15) P5 = gp_Pnt(-5, 20, 0) P6 = gp_Pnt(15, 20, 0) P7 = gp_Pnt(24, 120, 0) P8 = gp_Pnt(-24, 120, 12.5) array = TColgp_Array1OfPnt(1, 8) array.SetValue(1, P1) array.SetValue(2, P2) array.SetValue(3, P3) array.SetValue(4, P4) array.SetValue(5, P5) array.SetValue(6, P6) array.SetValue(7, P7) array.SetValue(8, P8) curve = Geom_BezierCurve(array) ME = BRepBuilderAPI_MakeEdge(curve.GetHandle()) GreenEdge = ME V3 = ME.Vertex1() V4 = ME.Vertex2() display.DisplayColoredShape(BlueEdge.Edge(), 'BLUE') display.DisplayShape(V1.Vertex()) display.DisplayShape(V2.Vertex()) display.DisplayColoredShape(WhiteEdge.Edge(), 'WHITE') display.DisplayColoredShape(YellowEdge.Edge(), 'YELLOW') display.DisplayColoredShape(RedEdge.Edge(), 'RED') display.DisplayColoredShape(GreenEdge.Edge(), 'GREEN') display.DisplayShape(V3) display.DisplayShape(V4, update=True)
def edge(event=None): # The blud edge BlueEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80, -50, -20), gp_Pnt(-30, -60, -60)) V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20, 10, -30)) V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 7, -25)) YellowEdge = BRepBuilderAPI_MakeEdge(V1.Vertex(), V2.Vertex()) #The white edge line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0))) WhiteEdge = BRepBuilderAPI_MakeEdge(line, -20, 10) #The red edge Elips = gp_Elips(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 1, 1)), 60, 30) RedEdge = BRepBuilderAPI_MakeEdge(Elips, 0, math.pi/2) # The green edge and the both extreme vertex P1 = gp_Pnt(-15, 200, 10) P2 = gp_Pnt(5, 204, 0) P3 = gp_Pnt(15, 200, 0) P4 = gp_Pnt(-15, 20, 15) P5 = gp_Pnt(-5, 20, 0) P6 = gp_Pnt(15, 20, 0) P7 = gp_Pnt(24, 120, 0) P8 = gp_Pnt(-24, 120, 12.5) array = TColgp_Array1OfPnt(1, 8) array.SetValue(1, P1) array.SetValue(2, P2) array.SetValue(3, P3) array.SetValue(4, P4) array.SetValue(5, P5) array.SetValue(6, P6) array.SetValue(7, P7) array.SetValue(8, P8) curve = Geom_BezierCurve(array) ME = BRepBuilderAPI_MakeEdge(curve.GetHandle()) GreenEdge = ME V3 = ME.Vertex1() V4 = ME.Vertex2() display.DisplayColoredShape(BlueEdge.Edge(), 'BLUE') display.DisplayShape(V1.Vertex()) display.DisplayShape(V2.Vertex()) display.DisplayColoredShape(WhiteEdge.Edge(), 'WHITE') display.DisplayColoredShape(YellowEdge.Edge(), 'YELLOW') display.DisplayColoredShape(RedEdge.Edge(), 'RED') display.DisplayColoredShape(GreenEdge.Edge(), 'GREEN') display.DisplayShape(V3) display.DisplayShape(V4, update=True)
def edge(event=None): # The blud edge blue_edge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80, -50, -20), gp_Pnt(-30, -60, -60)) v1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20, 10, -30)) v2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 7, -25)) yellow_edge = BRepBuilderAPI_MakeEdge(v1.Vertex(), v2.Vertex()) # The white edge line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0))) white_edge = BRepBuilderAPI_MakeEdge(line, -20, 10) # The red edge elips = gp_Elips(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 1, 1)), 60, 30) red_edge = BRepBuilderAPI_MakeEdge(elips, 0, math.pi / 2) # The green edge and the both extreme vertex p1 = gp_Pnt(-15, 200, 10) p2 = gp_Pnt(5, 204, 0) p3 = gp_Pnt(15, 200, 0) p4 = gp_Pnt(-15, 20, 15) p5 = gp_Pnt(-5, 20, 0) p6 = gp_Pnt(15, 20, 0) p7 = gp_Pnt(24, 120, 0) p8 = gp_Pnt(-24, 120, 12.5) array = TColgp_Array1OfPnt(1, 8) array.SetValue(1, p1) array.SetValue(2, p2) array.SetValue(3, p3) array.SetValue(4, p4) array.SetValue(5, p5) array.SetValue(6, p6) array.SetValue(7, p7) array.SetValue(8, p8) curve = Geom_BezierCurve(array) make_edge = BRepBuilderAPI_MakeEdge(curve.GetHandle()) green_edge = make_edge v3 = make_edge.Vertex1() v4 = make_edge.Vertex2() display.DisplayColoredShape(blue_edge.Edge(), 'BLUE') display.DisplayShape(v1.Vertex()) display.DisplayShape(v2.Vertex()) display.DisplayColoredShape(white_edge.Edge(), 'WHITE') display.DisplayColoredShape(yellow_edge.Edge(), 'YELLOW') display.DisplayColoredShape(red_edge.Edge(), 'RED') display.DisplayColoredShape(green_edge.Edge(), 'GREEN') display.DisplayShape(v3) display.DisplayShape(v4, update=True)
def intersect_shape_with_ptdir(occ_shape, pypt, pydir): occ_line = gp_Lin( gp_Ax1(gp_Pnt(pypt[0], pypt[1], pypt[2]), gp_Dir(pydir[0], pydir[1], pydir[2]))) shape_inter = IntCurvesFace_ShapeIntersector() shape_inter.Load(occ_shape, 1e-6) shape_inter.PerformNearest(occ_line, 0.0, float("+inf")) if shape_inter.IsDone(): npts = shape_inter.NbPnt() if npts != 0: return shape_inter.Pnt(1), shape_inter.Face(1) else: return None, None else: return None, None
def test_hash_eq_operator(self): ''' test that the == wrapper is ok ''' # test Standard h1 = Handle_Standard_Transient() s = Standard_Transient() h2 = s.GetHandle() self.assertTrue(h1 == h1) self.assertFalse(h1 == h2) self.assertFalse(h1 == 10) self.assertTrue(h2 == s) # test list.index, that uses __eq__ method p1 = gp_Pnt(0., 0., 0.) line = gp_Lin(p1, gp_Dir(1., 0., 0.)) items = [p1, line] res = items.index(line) self.assertEqual(res, 1.)
def calc_intersection(terrain_intersection_curves, edges_coords, edges_dir): """ This script calculates the intersection of the building edges to the terrain, :param terrain_intersection_curves: :param edges_coords: :param edges_dir: :return: intersecting points, intersecting faces """ building_line = gp_Lin(gp_Ax1(gp_Pnt(edges_coords[0], edges_coords[1], edges_coords[2]), gp_Dir(edges_dir[0], edges_dir[1], edges_dir[2]))) terrain_intersection_curves.PerformNearest(building_line, 0.0, float("+inf")) if terrain_intersection_curves.IsDone(): npts = terrain_intersection_curves.NbPnt() if npts != 0: return terrain_intersection_curves.Pnt(1), terrain_intersection_curves.Face(1) else: return None, None else: return None, None
def reflect_axs2(beam, surf, axs=gp_Ax3(), indx=1): p0, v0 = beam.Location(), dir_to_vec(beam.Direction()) h_surf = BRep_Tool.Surface(surf) ray = Geom_Line(gp_Lin(p0, vec_to_dir(v0))) if GeomAPI_IntCS(ray.GetHandle(), h_surf).NbPoints() == 0: return beam, beam, None elif GeomAPI_IntCS(ray.GetHandle(), h_surf).NbPoints() == 1: return beam, beam, None GeomAPI_IntCS(ray.GetHandle(), h_surf).IsDone() u, v, w = GeomAPI_IntCS(ray.GetHandle(), h_surf).Parameters(indx) p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec() GeomLProp_SurfaceTool.D1(h_surf, u, v, p1, vx, vy) vz = vx.Crossed(vy) vx.Normalize() vy.Normalize() vz.Normalize() v1 = v0.Mirrored(gp_Ax2(p1, vec_to_dir(vz), vec_to_dir(vx))) norm_ax = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx)) beam_ax = gp_Ax3(p1, vec_to_dir(v1), beam.XDirection().Reversed()) return beam_ax, norm_ax, 1
def intersect_shape_with_ptdir(occtopology, pypt, pydir): """ This function projects a point in a direction and calculates the at which point does the point intersects the OCCtopology. Parameters ---------- occtopology : OCCtopology The OCCtopology to be projected on. OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex pypt : tuple of floats The point to be projected. A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z) pydir : tuple of floats The direction of the point to be projected. A pydir is a tuple that documents the xyz vector of a dir e.g. (x,y,z) Returns ------- intersection point : pypt The point in which the projected point intersect the OCCtopology. If None means there is no intersection. intersection face : OCCface The OCCface in which the projected point hits. If None means there is no intersection. """ occ_line = gp_Lin( gp_Ax1(gp_Pnt(pypt[0], pypt[1], pypt[2]), gp_Dir(pydir[0], pydir[1], pydir[2]))) shape_inter = IntCurvesFace_ShapeIntersector() shape_inter.Load(occtopology, 1e-6) shape_inter.PerformNearest(occ_line, 0.0, float("+inf")) if shape_inter.IsDone(): npts = shape_inter.NbPnt() if npts != 0: return modify.occpt_2_pypt(shape_inter.Pnt(1)), shape_inter.Face(1) else: return None, None else: return None, None
def intersect_shape_with_ptdir(occtopology, pypt, pydir): """ This function projects a point in a direction and calculates the at which point does the point intersects the OCCtopology. Parameters ---------- occtopology : OCCtopology The OCCtopology to be projected on. OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex pypt : tuple of floats The point to be projected. A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z) pydir : tuple of floats The direction of the point to be projected. A pydir is a tuple that documents the xyz vector of a dir e.g. (x,y,z) Returns ------- intersection point : pypt The point in which the projected point intersect the OCCtopology. If None means there is no intersection. intersection face : OCCface The OCCface in which the projected point hits. If None means there is no intersection. """ occ_line = gp_Lin(gp_Ax1(gp_Pnt(pypt[0], pypt[1], pypt[2]), gp_Dir(pydir[0], pydir[1], pydir[2]))) shape_inter = IntCurvesFace_ShapeIntersector() shape_inter.Load(occtopology, 1e-6) shape_inter.PerformNearest(occ_line, 0.0, float("+inf")) if shape_inter.IsDone(): npts = shape_inter.NbPnt() if npts !=0: return modify.occpt_2_pypt(shape_inter.Pnt(1)), shape_inter.Face(1) else: return None, None else: return None, None
def make_line(pypt, pydir): occ_line = gp_Lin( gp_Ax1(gp_Pnt(pypt[0], pypt[1], pypt[2]), gp_Dir(pydir[0], pydir[1], pydir[2]))) return occ_line