Changeset 2452 in lmdz_wrf


Ignore:
Timestamp:
Apr 21, 2019, 9:55:18 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `mirror_polygon': Function to reflex a polygon for a given axis
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/geometry_tools.py

    r2451 r2452  
    2323# dist_points: Function to provide the distance between two points
    2424# max_coords_poly: Function to provide the extremes of the coordinates of a polygon
    25 # rotate_polygon_2D: Function to rotate 2D plain the vertices of a polygon
     25# mirror_polygon: Function to reflex a polygon for a given axis
    2626# position_sphere: Function to tranform fom a point in lon, lat deg coordinates to
    2727#   cartesian coordinates over an sphere
    2828# read_join_poly: Function to read an ASCII file with the combination of polygons
    2929# rotate_2D: Function to rotate a vector by a certain angle in the plain
     30# rotate_polygon_2D: Function to rotate 2D plain the vertices of a polygon
    3031# rotate_line2D: Function to rotate a line given by 2 pairs of x,y coordinates by a
    3132#   certain angle in the plain
     
    257258
    258259    return [nx, xx], [ny, xy], [ayx, axx], xyx
     260
     261def mirror_polygon(polygon,axis):
     262    """ Function to reflex a polygon for a given axis
     263      polygon: polygon to mirror
     264      axis: axis at which mirror is located ('x' or 'y')
     265    """
     266    fname = 'mirror_polygon'
     267
     268    reflex = np.zeros(polygon.shape, dtype=np.float)
     269
     270    N = polygon.shape[0]
     271    if axis == 'x':
     272        for iv in range(N):
     273            reflex[iv,:] = [-polygon[iv,1], polygon[iv,0]]
     274    elif axis == 'y':
     275        for iv in range(N):
     276            reflex[iv,:] = [polygon[iv,1], -polygon[iv,0]]
     277
     278    return reflex
    259279
    260280####### ###### ##### #### ### ## #
     
    484504
    485505    dangle = 2.*np.pi*loops/(N-1)
    486     dr = eradii/(N-1)
     506    dr = eradii*1./(N-1)
    487507
    488508    for ia in range(N):
Note: See TracChangeset for help on using the changeset viewer.