Changeset 2572 in lmdz_wrf


Ignore:
Timestamp:
May 31, 2019, 5:18:18 AM (5 years ago)
Author:
lfita
Message:

Adding:

  • `p_cross_width': Function to draw a cross with arms with a given width and an angle
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/geometry_tools.py

    r2570 r2572  
    5757# p_doubleArrow: Function to provide an arrow with double lines
    5858# p_circle: Function to get a polygon of a circle
     59# p_cross_width: Function to draw a cross with arms with a given width and an angle
    5960# p_prism: Function to get a polygon prism
    6061# p_reg_polygon: Function to provide a regular polygon of Nv vertices
     
    14141415
    14151416    return triangle
     1417
     1418def p_cross_width(larm=5., width=1., Narms=4, N=200):
     1419    """ Function to draw a cross with arms with a given width and an angle
     1420      larm: legnth of the arms (5., default)
     1421      width: width of the arms (1., default)
     1422      Narms: Number of arms (4, default)
     1423      N: number of points to us (200, default)
     1424    """
     1425    fname = 'p_cross_width'
     1426
     1427    Narm = int((N-Narms)/Narms)
     1428
     1429    larm2 = larm/2.
     1430    width2 = width/2.
     1431
     1432    cross = np.ones((N,2), dtype=np.float)*gen.fillValueF
     1433    da = np.pi/Narms
     1434
     1435    N1 = int(Narm*3./8.)
     1436    N2 = int((Narm - 2*N1)/2.)
     1437    N21 = Narm - 2*N1 - N2
     1438
     1439    if N2 < 3:
     1440        print errormsg
     1441        print '  ' + fname + ": too few points for ", Narms, " arms !!"
     1442        print "    increase number 'N' at least up to '", 25*Narms
     1443        quit(-1)
     1444
     1445    crosssecs = []
     1446    crossdic = {}
     1447    Npot = int(np.log10(Narms))+1
     1448
     1449    iip = 0
     1450    for iarm in range(Narms-1):
     1451
     1452        a = da*iarm
     1453        iip0 = iip
     1454
     1455        # bottom coordinate
     1456        bx = larm*np.cos(a+np.pi)
     1457        by = larm*np.sin(a+np.pi)
     1458
     1459        # upper coordinate
     1460        ux = larm*np.cos(a)
     1461        uy = larm*np.sin(a)
     1462
     1463        rela = a+np.pi*3./2.
     1464        # SW-NW
     1465        ix = bx + width2*np.cos(rela)
     1466        iy = by + width2*np.sin(rela)
     1467        ex = ux + width2*np.cos(rela)
     1468        ey = uy + width2*np.sin(rela)
     1469        dx = (ex-ix)/(N1-1)
     1470        dy = (ey-iy)/(N1-1)
     1471        for ip in range(N1):
     1472            cross[iip+ip,:] = [iy+dy*ip,ix+dx*ip]
     1473        iip = iip + N1
     1474
     1475        # NW-NE
     1476        ix = ex + 0.
     1477        iy = ey + 0.
     1478        ex = ux - width2*np.cos(rela)
     1479        ey = uy - width2*np.sin(rela)
     1480        dx = (ex-ix)/(N2-1)
     1481        dy = (ey-iy)/(N2-1)
     1482        for ip in range(N2):
     1483            cross[iip+ip,:] = [iy+dy*ip,ix+dx*ip]
     1484        iip = iip + N2
     1485
     1486        # NW-SW
     1487        ix = ex + 0.
     1488        iy = ey + 0.
     1489        ex = bx - width2*np.cos(rela)
     1490        ey = by - width2*np.sin(rela)
     1491        dx = (ex-ix)/(N1-1)
     1492        dy = (ey-iy)/(N1-1)
     1493        for ip in range(N1):
     1494            cross[iip+ip,:] = [iy+dy*ip,ix+dx*ip]
     1495        iip = iip + N1
     1496
     1497        # SW-SE
     1498        ix = ex + 0.
     1499        iy = ey + 0.
     1500        ex = bx + width2*np.cos(rela)
     1501        ey = by + width2*np.sin(rela)
     1502        dx = (ex-ix)/(N21-1)
     1503        dy = (ey-iy)/(N21-1)
     1504        for ip in range(N21):
     1505            cross[iip+ip,:] = [iy+dy*ip,ix+dx*ip]
     1506        iip = iip + N21 + 1
     1507
     1508        iarmS = str(iarm).zfill(Npot)
     1509        crosssecs.append(iarmS)
     1510        crossdic[iarmS] = [cross[iip0:iip0+iip-1], '-', 'k', '1.']
     1511
     1512    iip0 = iip
     1513
     1514    Narm = N - Narm*(Narms-1) - Narms
     1515
     1516    N1 = int(Narm*3./8.)
     1517    N2 = int((Narm - 2*N1)/2.)
     1518    N21 = Narm - 2*N1 - N2
     1519
     1520    iarm = Narms-1
     1521    a = da*iarm
     1522
     1523    # bottom coordinate
     1524    bx = larm*np.cos(a+np.pi)
     1525    by = larm*np.sin(a+np.pi)
     1526
     1527    # upper coordinate
     1528    ux = larm*np.cos(a)
     1529    uy = larm*np.sin(a)
     1530
     1531    rela = a+np.pi*3./2.
     1532    # SW-NW
     1533    ix = bx + width2*np.cos(rela)
     1534    iy = by + width2*np.sin(rela)
     1535    ex = ux + width2*np.cos(rela)
     1536    ey = uy + width2*np.sin(rela)
     1537    dx = (ex-ix)/(N1-1)
     1538    dy = (ey-iy)/(N1-1)
     1539    for ip in range(N1):
     1540      cross[iip+ip,:] = [iy+dy*ip,ix+dx*ip]
     1541    iip = iip + N1
     1542
     1543    # NW-NE
     1544    ix = ex + 0.
     1545    iy = ey + 0.
     1546    ex = ux - width2*np.cos(rela)
     1547    ey = uy - width2*np.sin(rela)
     1548    dx = (ex-ix)/(N2-1)
     1549    dy = (ey-iy)/(N2-1)
     1550    for ip in range(N2):
     1551      cross[iip+ip,:] = [iy+dy*ip,ix+dx*ip]
     1552    iip = iip + N2
     1553
     1554    # NW-SW
     1555    ix = ex + 0.
     1556    iy = ey + 0.
     1557    ex = bx - width2*np.cos(rela)
     1558    ey = by - width2*np.sin(rela)
     1559    dx = (ex-ix)/(N1-1)
     1560    dy = (ey-iy)/(N1-1)
     1561    for ip in range(N1):
     1562      cross[iip+ip,:] = [iy+dy*ip,ix+dx*ip]
     1563    iip = iip + N1
     1564
     1565    # SW-SE
     1566    ix = ex + 0.
     1567    iy = ey + 0.
     1568    ex = bx + width2*np.cos(rela)
     1569    ey = by + width2*np.sin(rela)
     1570    dx = (ex-ix)/(N21-1)
     1571    dy = (ey-iy)/(N21-1)
     1572    for ip in range(N21):
     1573      cross[iip+ip,:] = [iy+dy*ip,ix+dx*ip]
     1574    iip = iip + N21
     1575
     1576    iarmS = str(iarm).zfill(Npot)
     1577    crosssecs.append(iarmS)
     1578    crossdic[iarmS] = [cross[iip0:iip0+iip-1], '-', 'k', '1.']
     1579
     1580    cross = ma.masked_equal(cross, gen.fillValueF)
     1581
     1582    return cross, crosssecs, crossdic
    14161583
    14171584# Combined objects
Note: See TracChangeset for help on using the changeset viewer.