Changeset 2567 in lmdz_wrf


Ignore:
Timestamp:
May 29, 2019, 10:31:52 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `p_prism': Function to get a polygon prism
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/geometry_tools.py

    r2566 r2567  
    5454# p_doubleArrow: Function to provide an arrow with double lines
    5555# p_circle: Function to get a polygon of a circle
     56# p_prism: Function to get a polygon prism
    5657# p_reg_polygon: Function to provide a regular polygon of Nv vertices
    5758# p_reg_star: Function to provide a regular star of Nv vertices
     
    10621063
    10631064    return square
     1065
     1066
     1067def p_prism(base, height, N=5):
     1068    """ Function to get a polygon prism
     1069      base: length of the base of the prism
     1070      height: length of the height of the prism
     1071      N: number of points of the polygon
     1072    """
     1073    fname = 'p_prism'
     1074
     1075    prism = np.zeros((N,2), dtype=np.float)
     1076
     1077    b2 = base/2.
     1078    h2 = height/2.
     1079    N4 = N/4
     1080    dh = height/(N4)
     1081    db = base/(N4)
     1082
     1083    # SW-NW
     1084    for ip in range(N4):
     1085        prism[ip,:] = [-h2+ip*dh,-b2]
     1086    # NW-NE
     1087    for ip in range(N4):
     1088        prism[ip+N4,:] = [h2,-b2+ip*db]
     1089    # NE-SE
     1090    for ip in range(N4):
     1091        prism[ip+2*N4,:] = [h2-ip*dh,b2]
     1092    N42 = N-3*N4-1
     1093    db = base/(N42)
     1094    # SE-SW
     1095    for ip in range(N42):
     1096        prism[ip+3*N4,:] = [-h2,b2-ip*db]
     1097    prism[N-1,:] = [-h2,-b2]
     1098
     1099    return prism
    10641100
    10651101def p_circle(radii, N=50):
     
    21552191    return buoy, buoysecs, buoydic
    21562192
     2193
     2194def green_buoy1(height=5., width=10., bradii=1.75, bfrac=0.8, hsigns=0.3, N=300):
     2195    """ Function to draw a green mark buoy using buoy1
     2196      height: height of the prism (5., default)
     2197      width: width of the prism (10., default)
     2198      bradii: radii of the ball (1.75, default)
     2199      bfrac: fraction of the ball above the prism (0.8, default)
     2200      hisgns: height of the signs [as reg. triangle] as percentage of the height
     2201        (0.3, default)
     2202      N: total number of points of the buoy (300, default)
     2203    """
     2204    fname = 'green_buoy1'
     2205
     2206    buoy = np.ones((N,2), dtype=np.float)*gen.fillValueF
     2207
     2208    # buoy
     2209    N2 = int(N/2)
     2210    buoy1v, buoy1vsecs, buoy1vdic = buoy1(height=5., width=10., bradii=1.75,         \
     2211      bfrac=0.8, N=N2)
     2212    buoy[0:N2,:] = buoy1v
     2213
     2214    # signs
     2215    N3 = N - N2 - 1
     2216    lsign = height*hsigns*2.
     2217   
     2218    Height = np.max(buoy1v[:,0])
     2219    triu = p_angle_triangle(N=N3)
     2220    sign = triu*lsign
     2221    buoy[N2+1:N2+2+N3,:] = sign + [Height+0.2*lsign,-lsign/2.]
     2222
     2223    # painting it
     2224    buoy = ma.masked_equal(buoy, gen.fillValueF)
     2225
     2226    buoysecs = ['buoy', 'sign', 'quarter1', 'quarter2', 'quarter3', 'quarter4']
     2227    buoydic = {'buoy': [buoy[0:N2,:],'-','r',1.5],                                   \
     2228      'sign': [buoy[N2+1:N2+N3+1,:],'-','r',1.5]}
     2229
     2230    return buoy, buoysecs, buoydic
     2231
    21572232####### ####### ##### #### ### ## #
    21582233# Plotting
Note: See TracChangeset for help on using the changeset viewer.