def _intersect_shape_by_line(topods_shape, line, low_parameter=0.0, hi_parameter=float("+inf")): r"""Finds the intersection of a shape and a line Parameters ---------- topods_shape : any TopoDS_* line : gp_Lin low_parameter : float, optional (the default value is 0.0) hi_parameter : float, optional (the default value is infinity) Returns ------- a list of gp_Pnt """ shape_inter = IntCurvesFace_ShapeIntersector() shape_inter.Load(topods_shape, OCCUTILS_DEFAULT_TOLERANCE) # shape_inter.PerformNearest(line, low_parameter, hi_parameter) shape_inter.Perform(line, low_parameter, hi_parameter) with AssertIsDone(shape_inter, "failed to computer shape / line " "intersection"): points = list() # Bug correction (some intersection points were missed) # for i in range(1, shape_inter.NbPnt()): for i in range(1, shape_inter.NbPnt() + 1): points.append(shape_inter.Pnt(i)) return points
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 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