Changeset 2434 in lmdz_wrf for trunk/tools


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

Working version of `circ_sec'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/geometry_tools.py

    r2414 r2434  
    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 # multi_rotate_2D: Function to rotate multiple vectors by a certain angle in the plain
     22# rotate_polygon_2D: Function to rotate 2D plain the vertices of a polygon
    2323# position_sphere: Function to tranform fom a point in lon, lat deg coordinates to
    2424#   cartesian coordinates over an sphere
     
    122122    return rotvector
    123123
    124 def multi_rotate_2D(vectors, angle):
    125     """ Function to rotate multiple vectors by a certain angle in the plain
     124def rotate_polygon_2D(vectors, angle):
     125    """ Function to rotate 2D plain the vertices of a polygon
    126126      line= matrix of vectors to rotate
    127127      angle= angle to rotate [rad]
     
    131131    >>> square[2,:] = [0.5,0.5]
    132132    >>> square[3,:] = [-0.5,0.5]
    133     >>> multi_rotate_2D(square, np.pi/4.)
     133    >>> rotate_polygon_2D(square, np.pi/4.)
    134134    [[-0.70710678  0.        ]
    135135     [ 0.         -0.70710678]
     
    137137     [ 0.          0.70710678]]
    138138    """
    139     fname = 'multi_rotate_2D'
     139    fname = 'rotate_polygon_2D'
    140140
    141141    rotvecs = np.zeros(vectors.shape, dtype=np.float)
     
    318318
    319319    # angle of the circular section joining points
    320     tottheta = 2.*np.arcsin(distAB/2./radii)
     320    alpha = 2.*np.arcsin((distAB/2.)/radii)
    321321
    322322    # center along coincident bisection of the union
     
    324324    ycc = 0.
    325325
    326     # Angle of the points
    327     pttheta = np.arctan2(ptB[0]-ptA[0],ptB[1]-ptA[1])
    328 
    329     # rotating the position of the center
    330     rotang = np.pi/2.-pttheta
    331 
    332     newcc = rotate_line2D(np.array([[ycc,xcc], [0.,0.]]), rotang)
    333     print newcc
    334 
    335     quit()
    336 
    337     dtheta = np.abs(tottheta)/(Nang-1)
    338     if sign == 1:
    339         dtheta = dtheta*(-1.)
    340 
    341     print 'Lluis tottheta:', tottheta*180./np.pi, 'dtheta:', dtheta*180./np.pi, 'c:', xc,yc
    342 
     326    # Getting the arc of the circle at the x-axis
     327    dalpha = alpha/(Nang-1)
    343328    circ_sec = np.zeros((Nang,2), dtype=np.float)
    344329    for ia in range(Nang):
    345         theta = dtheta*ia
    346         x = radii*np.cos(theta)
    347         y = radii*np.sin(theta)
    348 
    349         circ_sec[ia,:] = [y+yc,x+xc]
    350         print ia, 'Lluis xy:', x,y, 'circ', circ_sec[ia,:]
     330        alpha = dalpha*ia
     331        x = radii*np.cos(alpha)
     332        y = radii*np.sin(alpha)
     333
     334        circ_sec[ia,:] = [y+ycc,x+xcc]
    351335   
     336    # Angle of the points
     337    theta = np.arctan2(ptB[0]-ptA[0],ptB[1]-ptA[1])
     338
     339    # rotating angle of the circ
     340    rotangle = theta + 3.*np.pi/2. - alpha/2.
     341
     342    #print 'alpha:', alpha*180./np.pi, 'theta:', theta*180./np.pi, 'rotangle:', rotangle*180./np.pi
     343 
     344
     345    # rotating the arc along the x-axis
     346    rotcirc_sec = rotate_polygon_2D(circ_sec, rotangle)
     347
     348    # Moving arc to the ptA
     349    circ_sec = rotcirc_sec + ptA
     350
    352351    return circ_sec
    353352
Note: See TracChangeset for help on using the changeset viewer.