Changeset 2449 in lmdz_wrf for trunk/tools/geometry_tools.py
- Timestamp:
- Apr 19, 2019, 5:06:16 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2438 r2449 26 26 # position_sphere: Function to tranform fom a point in lon, lat deg coordinates to 27 27 # cartesian coordinates over an sphere 28 # p_circle: Function to get a polygon of a circle 29 # p_square: Function to get a polygon square 30 # read_join_poly: Function to read an ASCII file with the combination of polygons 28 31 # rotate_2D: Function to rotate a vector by a certain angle in the plain 29 32 # rotate_line2D: Function to rotate a line given by 2 pairs of x,y coordinates by a … … 33 36 # spheric_line: Function to transform a series of locations in lon, lat coordinates 34 37 # to x,y,z over an 3D spaceFunction to provide coordinates of a line on a 3D space 38 # write_join_poly: Function to write an ASCII file with the combination of polygons 35 39 36 40 ## Shapes/objects 37 41 # ellipse_polar: Function to determine an ellipse from its center and polar coordinates 38 42 # surface_sphere: Function to provide an sphere as matrix of x,y,z coordinates 43 39 44 40 45 ## Plotting … … 384 389 return circ_sec 385 390 391 def p_square(face, N=5): 392 """ Function to get a polygon square 393 face: length of the face of the square 394 N: number of points of the polygon 395 """ 396 fname = 'p_square' 397 398 square = np.zeros((N,2), dtype=np.float) 399 400 f2 = face/2. 401 N4 = N/4 402 df = face/(N4) 403 # SW-NW 404 for ip in range(N4): 405 square[ip,:] = [-f2+ip*df,-f2] 406 # NW-NE 407 for ip in range(N4): 408 square[ip+N4,:] = [f2,-f2+ip*df] 409 # NE-SE 410 for ip in range(N4): 411 square[ip+2*N4,:] = [f2-ip*df,f2] 412 N42 = N-3*N4-1 413 df = face/(N42) 414 # SE-SW 415 for ip in range(N42): 416 square[ip+3*N4,:] = [-f2,f2-ip*df] 417 square[N-1,:] = [-f2,-f2] 418 419 return square 420 421 def p_circle(radii, N=50): 422 """ Function to get a polygon of a circle 423 radii: length of the radii of the circle 424 N: number of points of the polygon 425 """ 426 fname = 'p_circle' 427 428 circle = np.zeros((N,2), dtype=np.float) 429 430 dangle = 2.*np.pi/(N-1) 431 432 for ia in range(N): 433 circle[ia,:] = [radii*np.sin(ia*dangle), radii*np.cos(ia*dangle)] 434 435 circle[N-1,:] = [0., radii] 436 437 return circle 438 439 # Combined objects 440 ## 441 386 442 # FROM: http://www.photographers1.com/Sailing/NauticalTerms&Nomenclature.html 387 443 def zsailing_boat(length=10., beam=1., lbeam=0.4, sternbp=0.5): … … 434 490 435 491 return boat 492 493 def write_join_poly(polys, flname='join_polygons.dat'): 494 """ Function to write an ASCII file with the combination of polygons 495 polys: dictionary with the names of the different polygons 496 flname: name of the ASCII file 497 """ 498 fname = 'write_join_poly' 499 500 of = open(flname, 'w') 501 502 for polyn in polys.keys(): 503 vertices = polys[polyn] 504 Npts = vertices.shape[0] 505 for ip in range(Npts): 506 of.write(polyn+' '+str(vertices[ip,1]) + ' ' + str(vertices[ip,0]) + '\n') 507 508 of.close() 509 510 return 511 512 def read_join_poly(flname='join_polygons.dat'): 513 """ Function to read an ASCII file with the combination of polygons 514 flname: name of the ASCII file 515 """ 516 fname = 'read_join_poly' 517 518 of = open(flname, 'r') 519 520 polys = {} 521 polyn = '' 522 poly = [] 523 for line in of: 524 if len(line) > 1: 525 linevals = line.replace('\n','').split(' ') 526 if polyn != linevals[0]: 527 if len(poly) > 1: 528 polys[polyn] = np.array(poly) 529 polyn = linevals[0] 530 poly = [] 531 poly.append([np.float(linevals[2]), np.float(linevals[1])]) 532 else: 533 poly.append([np.float(linevals[2]), np.float(linevals[1])]) 534 535 of.close() 536 polys[polyn] = np.array(poly) 537 538 return polys 436 539 437 540 ####### ####### ##### #### ### ## # … … 599 702 600 703 return fig, ax 601
Note: See TracChangeset
for help on using the changeset viewer.