Changeset 2434 in lmdz_wrf for trunk/tools
- Timestamp:
- Apr 14, 2019, 10:08:57 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2414 r2434 20 20 # deg_deci: Function to pass from degrees [deg, minute, sec] to decimal angles [rad] 21 21 # 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 plain22 # rotate_polygon_2D: Function to rotate 2D plain the vertices of a polygon 23 23 # position_sphere: Function to tranform fom a point in lon, lat deg coordinates to 24 24 # cartesian coordinates over an sphere … … 122 122 return rotvector 123 123 124 def multi_rotate_2D(vectors, angle):125 """ Function to rotate multiple vectors by a certain angle in the plain124 def rotate_polygon_2D(vectors, angle): 125 """ Function to rotate 2D plain the vertices of a polygon 126 126 line= matrix of vectors to rotate 127 127 angle= angle to rotate [rad] … … 131 131 >>> square[2,:] = [0.5,0.5] 132 132 >>> square[3,:] = [-0.5,0.5] 133 >>> multi_rotate_2D(square, np.pi/4.)133 >>> rotate_polygon_2D(square, np.pi/4.) 134 134 [[-0.70710678 0. ] 135 135 [ 0. -0.70710678] … … 137 137 [ 0. 0.70710678]] 138 138 """ 139 fname = ' multi_rotate_2D'139 fname = 'rotate_polygon_2D' 140 140 141 141 rotvecs = np.zeros(vectors.shape, dtype=np.float) … … 318 318 319 319 # angle of the circular section joining points 320 tottheta = 2.*np.arcsin(distAB/2./radii)320 alpha = 2.*np.arcsin((distAB/2.)/radii) 321 321 322 322 # center along coincident bisection of the union … … 324 324 ycc = 0. 325 325 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) 343 328 circ_sec = np.zeros((Nang,2), dtype=np.float) 344 329 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] 351 335 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 352 351 return circ_sec 353 352
Note: See TracChangeset
for help on using the changeset viewer.