Changeset 2451 in lmdz_wrf for trunk/tools/geometry_tools.py
- Timestamp:
- Apr 21, 2019, 9:43:59 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2450 r2451 41 41 # p_circle: Function to get a polygon of a circle 42 42 # p_square: Function to get a polygon square 43 # p_spiral: Function to provide a polygon of an Archimedean spiral 44 # p_triangle: Function to provide the polygon of a triangle from its 3 vertices 43 45 # surface_sphere: Function to provide an sphere as matrix of x,y,z coordinates 44 46 … … 436 438 437 439 return circle 440 441 def p_triangle(p1, p2, p3, N=4): 442 """ Function to provide the polygon of a triangle from its 3 vertices 443 p1: vertex 1 [y,x] 444 p2: vertex 2 [y,x] 445 p3: vertex 3 [y,x] 446 N: number of vertices of the triangle 447 """ 448 fname = 'p_triangle' 449 450 triangle = np.zeros((N,2), dtype=np.float) 451 452 N3 = N / 3 453 # 1-2 454 dx = (p2[1]-p1[1])/N3 455 dy = (p2[0]-p1[0])/N3 456 for ip in range(N3): 457 triangle[ip,:] = [p1[0]+ip*dy,p1[1]+ip*dx] 458 # 2-3 459 dx = (p3[1]-p2[1])/N3 460 dy = (p3[0]-p2[0])/N3 461 for ip in range(N3): 462 triangle[ip+N3,:] = [p2[0]+ip*dy,p2[1]+ip*dx] 463 # 3-1 464 N32 = N - 2*N/3 465 dx = (p1[1]-p3[1])/N32 466 dy = (p1[0]-p3[0])/N32 467 for ip in range(N32): 468 triangle[ip+2*N3,:] = [p3[0]+ip*dy,p3[1]+ip*dx] 469 470 triangle[N-1,:] = p1 471 472 return triangle 473 474 def p_spiral(loops, eradii, N=1000): 475 """ Function to provide a polygon of an Archimedean spiral 476 FROM: https://en.wikipedia.org/wiki/Spiral 477 loops: number of loops of the spiral 478 eradii: length of the radii of the final spiral 479 N: number of points of the polygon 480 """ 481 fname = 'p_spiral' 482 483 spiral = np.zeros((N,2), dtype=np.float) 484 485 dangle = 2.*np.pi*loops/(N-1) 486 dr = eradii/(N-1) 487 488 for ia in range(N): 489 radii = dr*ia 490 spiral[ia,:] = [radii*np.sin(ia*dangle), radii*np.cos(ia*dangle)] 491 492 return spiral 438 493 439 494 # Combined objects
Note: See TracChangeset
for help on using the changeset viewer.