Changeset 775 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
May 25, 2016, 5:09:32 PM (9 years ago)
Author:
lfita
Message:

Adding `PolyArea?' Function to compute the area of the polygon following 'Shoelace formula'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r762 r775  
    1717fillValueF64 = 1.e20
    1818fillValueI32 = -99999
     19
     20####### Content
     21# PolyArea: Function to compute the area of the polygon following 'Shoelace formula'
    1922
    2023def values_line(line, splitv, chars):
     
    62296232
    62306233    return ilatlon, mindiffLl
     6234
     6235def PolyArea(x,y):
     6236    """ Function to compute the area of the polygon following 'Shoelace formula'
     6237      from: http://stackoverflow.com/questions/24467972/calculate-area-of-polygon-given-x-y-coordinates
     6238      x: x-values of the vertexs of the polygon
     6239      y: y-values of the vertexs of the polygon
     6240    >>> x = np.array([-0.5,0.5,0.5,-0.5])
     6241    >>> y = np.array([0.5,0.5,-0.5,-0.5])
     6242    >>> PolyArea(x,y)
     6243    1.0
     6244    """
     6245    return 0.5*np.abs(np.dot(x,np.roll(y,1))-np.dot(y,np.roll(x,1)))
     6246
Note: See TracChangeset for help on using the changeset viewer.