#NEWLINE# def line_intersect_grid( ptsin , xedge , yedge , returnvertices = False ) : #NEWLINE# #INDENT# '\n    Intersect a list of polyline vertices with a rectilinear MODFLOW\n    grid. Vertices at the intersection of the polyline with the grid\n    cell edges is returned. Optionally the original polyline vertices\n    are returned.\n\n    Parameters\n    ----------\n    ptsin : list\n        A list of x, y points defining the vertices of a polyline that will be\n        intersected with the rectilinear MODFLOW grid\n    xedge : numpy.ndarray\n        x-coordinate of the edge of each MODFLOW column. xedge is dimensioned\n        to NCOL + 1. If xedge is not a numpy.ndarray it is converted to a\n        numpy.ndarray.\n    yedge : numpy.ndarray\n        y-coordinate of the edge of each MODFLOW row. yedge is dimensioned\n        to NROW + 1. If yedge is not a numpy.ndarray it is converted to a\n        numpy.ndarray.\n    returnvertices: bool\n        Return the original polyline vertices in the list of numpy.ndarray\n        containing vertices resulting from intersection of the provided\n        polygon and the MODFLOW model grid if returnvertices=True.\n        (default is False).\n\n    Returns\n    -------\n    (x, y, dlen) : numpy.ndarray of tuples\n        numpy.ndarray of tuples containing the x, y, and segment length of the\n        intersection of the provided polyline with the rectilinear MODFLOW\n        grid.\n\n    Examples\n    --------\n    >>> import flopy\n    >>> ptsout = flopy.plotutil.line_intersect_grid(ptsin, xedge, yedge)\n\n    ' #NEWLINE# small_value = 0.1 #NEWLINE# if ( not isinstance ( xedge , np . ndarray ) ) : #NEWLINE# #INDENT# xedge = np . array ( xedge ) #NEWLINE# #UNINDENT# if ( not isinstance ( yedge , np . ndarray ) ) : #NEWLINE# #INDENT# yedge = np . array ( yedge ) #NEWLINE# #UNINDENT# pts = [ ] #NEWLINE# npts = len ( ptsin ) #NEWLINE# dlen = 0.0 #NEWLINE# for idx in range ( 1 , npts ) : #NEWLINE# #INDENT# x0 = ptsin [ ( idx - 1 ) ] [ 0 ] #NEWLINE# x1 = ptsin [ idx ] [ 0 ] #NEWLINE# y0 = ptsin [ ( idx - 1 ) ] [ 1 ] #NEWLINE# y1 = ptsin [ idx ] [ 1 ] #NEWLINE# a = ( x1 - x0 ) #NEWLINE# b = ( y1 - y0 ) #NEWLINE# c = math . sqrt ( ( math . pow ( a , 2.0 ) + math . pow ( b , 2.0 ) ) ) #NEWLINE# ( irow0 , jcol0 ) = findrowcolumn ( ( x0 , y0 ) , xedge , yedge ) #NEWLINE# ( irow1 , jcol1 ) = findrowcolumn ( ( x1 , y1 ) , xedge , yedge ) #NEWLINE# jx = 0 #NEWLINE# incx = abs ( ( ( small_value * a ) / c ) ) #NEWLINE# iy = 0 #NEWLINE# incy = ( - abs ( ( ( small_value * b ) / c ) ) ) #NEWLINE# if ( a == 0.0 ) : #NEWLINE# #INDENT# incx = 0.0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( a > 0.0 ) : #NEWLINE# #INDENT# jx = 1 #NEWLINE# incx *= ( - 1.0 ) #NEWLINE# #UNINDENT# #UNINDENT# if ( b == 0.0 ) : #NEWLINE# #INDENT# incy = 0.0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( b < 0.0 ) : #NEWLINE# #INDENT# iy = 1 #NEWLINE# incy *= ( - 1.0 ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( irow0 >= 0 ) and ( jcol0 >= 0 ) ) : #NEWLINE# #INDENT# iadd = True #NEWLINE# if ( ( idx > 1 ) and returnvertices ) : #NEWLINE# #INDENT# iadd = False #NEWLINE# #UNINDENT# if iadd : #NEWLINE# #INDENT# pts . append ( ( x0 , y0 , dlen ) ) #NEWLINE# #UNINDENT# #UNINDENT# icnt = 0 #NEWLINE# while True : #NEWLINE# #INDENT# icnt += 1 #NEWLINE# dx = ( xedge [ ( jcol0 + jx ) ] - x0 ) #NEWLINE# dlx = 0.0 #NEWLINE# if ( a != 0.0 ) : #NEWLINE# #INDENT# dlx = ( ( c * dx ) / a ) #NEWLINE# #UNINDENT# dy = ( yedge [ ( irow0 + iy ) ] - y0 ) #NEWLINE# dly = 0.0 #NEWLINE# if ( b != 0.0 ) : #NEWLINE# #INDENT# dly = ( ( c * dy ) / b ) #NEWLINE# #UNINDENT# if ( ( dlx != 0.0 ) and ( dly != 0.0 ) ) : #NEWLINE# #INDENT# if ( abs ( dlx ) < abs ( dly ) ) : #NEWLINE# #INDENT# dy = ( ( dx * b ) / a ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# dx = ( ( dy * a ) / b ) #NEWLINE# #UNINDENT# #UNINDENT# xt = ( ( x0 + dx ) + incx ) #NEWLINE# yt = ( ( y0 + dy ) + incy ) #NEWLINE# dl = math . sqrt ( ( math . pow ( ( xt - x0 ) , 2.0 ) + math . pow ( ( yt - y0 ) , 2.0 ) ) ) #NEWLINE# dlen += dl #NEWLINE# if ( not returnvertices ) : #NEWLINE# #INDENT# pts . append ( ( xt , yt , dlen ) ) #NEWLINE# #UNINDENT# ( x0 , y0 ) = ( xt , yt ) #NEWLINE# xt = ( x0 - ( 2.0 * incx ) ) #NEWLINE# yt = ( y0 - ( 2.0 * incy ) ) #NEWLINE# dl = math . sqrt ( ( math . pow ( ( xt - x0 ) , 2.0 ) + math . pow ( ( yt - y0 ) , 2.0 ) ) ) #NEWLINE# dlen += dl #NEWLINE# ( x0 , y0 ) = ( xt , yt ) #NEWLINE# ( irow0 , jcol0 ) = findrowcolumn ( ( x0 , y0 ) , xedge , yedge ) #NEWLINE# if ( ( irow0 >= 0 ) and ( jcol0 >= 0 ) ) : #NEWLINE# #INDENT# if ( not returnvertices ) : #NEWLINE# #INDENT# pts . append ( ( xt , yt , dlen ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( irow1 < 0 ) or ( jcol1 < 0 ) ) : #NEWLINE# #INDENT# dl = math . sqrt ( ( math . pow ( ( x1 - x0 ) , 2.0 ) + math . pow ( ( y1 - y0 ) , 2.0 ) ) ) #NEWLINE# dlen += dl #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# if ( ( irow0 == irow1 ) and ( jcol0 == jcol1 ) ) : #NEWLINE# #INDENT# dl = math . sqrt ( ( math . pow ( ( x1 - x0 ) , 2.0 ) + math . pow ( ( y1 - y0 ) , 2.0 ) ) ) #NEWLINE# dlen += dl #NEWLINE# pts . append ( ( x1 , y1 , dlen ) ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return np . array ( pts )