Changeset 2435 in lmdz_wrf for trunk


Ignore:
Timestamp:
Apr 14, 2019, 10:35:05 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `max_coords_poly': Function to provide the extremes of the coordinates of a polygon
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/geometry_tools.py

    r2434 r2435  
    2020# deg_deci: Function to pass from degrees [deg, minute, sec] to decimal angles [rad]
    2121# dist_points: Function to provide the distance between two points
     22# max_coords_poly: Function to provide the extremes of the coordinates of a polygon
    2223# rotate_polygon_2D: Function to rotate 2D plain the vertices of a polygon
    2324# position_sphere: Function to tranform fom a point in lon, lat deg coordinates to
     
    218219    return dist
    219220
     221def max_coords_poly(polygon):
     222    """ Function to provide the extremes of the coordinates of a polygon
     223      polygon: coordinates [Nvertexs, 2] of a polygon
     224    >>> square = np.zeros((4,2), dtype=np.float)
     225    >>> square[0,:] = [-0.5,-0.5]
     226    >>> square[1,:] = [0.5,-0.5]
     227    >>> square[2,:] = [0.5,0.5]
     228    >>> square[3,:] = [-0.5,0.5]
     229    >>> max_coords_poly(square)
     230    [-0.5, 0.5], [-0.5, 0.5], [0.5, 0.5]
     231    """
     232    fname = 'max_coords_poly'
     233
     234    nx = np.min(polygon[:,1])
     235    xx = np.max(polygon[:,1])
     236    ny = np.min(polygon[:,0])
     237    xy = np.max(polygon[:,0])
     238
     239    axx = np.max(np.abs(polygon[:,1]))
     240    ayx = np.max(np.abs(polygon[:,0]))
     241
     242    return [nx, xx], [ny, xy], [axx, ayx]
     243
    220244####### ###### ##### #### ### ## #
    221245# Shapes/objects
     
    352376
    353377# FROM: http://www.photographers1.com/Sailing/NauticalTerms&Nomenclature.html
    354 def zsailing_boat(length=10., beam=3., sternbp=0.5):
     378def zsailing_boat(length=10., beam=1., lbeam=0.5, sternbp=0.5):
    355379    """ Function to define an schematic boat from the z-plane
    356       length: length of the boat
    357       beam: beam of the boat
    358       sternbp: beam at stern as percentage of beam
     380      length: length of the boat (without stern, default 10)
     381      beam: beam of the boat (default 1)
     382      lbeam: length at beam (as percentage of length, default 0.5)
     383      sternbp: beam at stern (as percentage of beam, default 0.5)
    359384    """
    360385    fname = 'zsailing_boat'
    361386
    362    
     387    bow = np.array([length, 0.])
     388    maxportside = np.array([length*lbeam, -beam])
     389    maxstarboardside = np.array([length*lbeam, beam])
     390    portside = np.array([0., -beam*sternbp])
     391    starboardside = np.array([0., beam*sternbp])
     392
     393    # forward section
     394    fportsaid = circ_sec(bow,maxportside, length*2)
     395    fstarboardsaid = circ_sec(maxstarboardside, bow, length*2)
     396    # aft section
     397    aportsaid = circ_sec(maxportside, portside, length*2)
     398    astarboardsaid = circ_sec(starboardside, maxstarboardside, length*2)
     399    # stern
     400    stern = circ_sec(portside, starboardside, length*2)
     401
     402    dpts = stern.shape[0]
     403    boat = np.zeros((dpts*5,2), dtype=np.float)
     404
     405    boat[0:dpts,:] = fportsaid
     406    boat[dpts:2*dpts,:] = aportsaid
     407    boat[2*dpts:3*dpts,:] = stern
     408    boat[3*dpts:4*dpts,:] = astarboardsaid
     409    boat[4*dpts:5*dpts,:] = fstarboardsaid
    363410
    364411    return boat
Note: See TracChangeset for help on using the changeset viewer.