Exemplo n.º 1
0
def intersect_shape_by_line(topods_shape,
                            line,
                            low_parameter=0.0,
                            hi_parameter=float("+inf")):
    """
    finds the intersection of a shape and a line
    :param shape: any TopoDS_*
    :param line: gp_Lin
    :param low_parameter:
    :param hi_parameter:
    :return: a list with a number of tuples that corresponds to the number
    of intersections found
    the tuple contains ( gp_Pnt, TopoDS_Face, u,v,w ), respectively the
    intersection point, the intersecting face
    and the <u,v,w parameters of the intersection point
    :raise:
    """
    from OCC.Core.IntCurvesFace import IntCurvesFace_ShapeIntersector
    shape_inter = IntCurvesFace_ShapeIntersector()
    shape_inter.Load(topods_shape, TOLERANCE)
    #shape_inter.PerformNearest(line, low_parameter, hi_parameter)

    with assert_isdone(shape_inter,
                       "failed to computer shape / line intersection"):
        return (shape_inter.Pnt(1), shape_inter.Face(1),
                shape_inter.UParameter(1), shape_inter.VParameter(1),
                shape_inter.WParameter(1))
 def get_shape_line_intersections(cls, shape, line):
     """
     Seems to return the intersection for the first face the line runs into
     """
     shape_inter = IntCurvesFace_ShapeIntersector()
     shape_inter.Load(shape, 1e-3)
     shape_inter.PerformNearest(line, float("-inf"), float("+inf"))
     with assert_isdone(shape_inter,
                        "failed to computer shape / line intersection"):
         intersections = [(shape_inter.Pnt(i), shape_inter.Face(i), line)
                          for i in range(1,
                                         shape_inter.NbPnt() + 1)
                          ]  # Indices start at 1 :(
         return intersections
Exemplo n.º 3
0
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