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.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))
Exemplo n.º 2
0
def 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 with a number of tuples that corresponds to the
    number of intersections found.
    the tuple contains ( OCC.gp.gp_Pnt, TopoDS_Face, u,v,w ),
    respectively the intersection point, the intersecting face
    and the u,v,w parameters of the intersection point

    """
    shape_inter = IntCurvesFace_ShapeIntersector()
    shape_inter.Load(topods_shape, OCCUTILS_DEFAULT_TOLERANCE)
    shape_inter.PerformNearest(line, low_parameter, hi_parameter)

    with AssertIsDone(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))
Exemplo n.º 3
0
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
Exemplo n.º 4
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
Exemplo n.º 5
0
def intersect_shape_by_line(
        shape: TopoDS_Shape,
        line: gp.gp_Lin,
        low_parameter: Optional[float]=0.0,
        hi_parameter: Optional[float]=float("+inf"),
        tol:Optional[float]=0.001
        ):
    """
    finds the intersection of a shape and a line

    :param shape: any TopoDS_*
    :param line: gp_Lin
    :param low_parameter:
    :param hi_parameter:

    IntCurvesFace_ShapeIntersector

    :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:
    """
    shape_inter = IntCurvesFace_ShapeIntersector()
    shape_inter.Load(shape, tol)
    shape_inter.PerformNearest(line, low_parameter, hi_parameter)

    with assert_isdone(shape_inter, "failed to computer shape / line intersection"):
        try:
            return (shape_inter.Pnt(1),
                    shape_inter.Face(1),
                    shape_inter.UParameter(1),
                    shape_inter.VParameter(1),
                    shape_inter.WParameter(1))
        except:
            return None, None, None, None, None