Changeset 2455 in lmdz_wrf
- Timestamp:
- Apr 22, 2019, 12:12:03 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2454 r2455 15 15 import matplotlib.pyplot as plt 16 16 import os 17 import generic_tools as gen 17 18 18 19 errormsg = 'ERROR -- error -- ERROR -- error' … … 47 48 # p_triangle: Function to provide the polygon of a triangle from its 3 vertices 48 49 # surface_sphere: Function to provide an sphere as matrix of x,y,z coordinates 50 # zsailing_boat: Function to define an schematic sailing boat from the z-plane with sails 51 # z_boat: Function to define an schematic boat from the z-plane 49 52 50 53 ## Plotting … … 622 625 623 626 # FROM: http://www.photographers1.com/Sailing/NauticalTerms&Nomenclature.html 624 def z sailing_boat(length=10., beam=1., lbeam=0.4, sternbp=0.5):627 def zboat(length=10., beam=1., lbeam=0.4, sternbp=0.5): 625 628 """ Function to define an schematic boat from the z-plane 626 629 length: length of the boat (without stern, default 10) … … 629 632 sternbp: beam at stern (as percentage of beam, default 0.5) 630 633 """ 631 fname = 'z sailing_boat'634 fname = 'zboat' 632 635 633 636 bow = np.array([length, 0.]) … … 671 674 672 675 return boat 676 677 def zsailing_boat(length=10., beam=1., lbeam=0.4, sternbp=0.5, lmast=0.6, wmast=0.1, \ 678 sd=0., lheads=0.38, lmains=0.55): 679 """ Function to define an schematic sailing boat from the z-plane with sails 680 length: length of the boat (without stern, default 10) 681 beam: beam of the boat (default 1) 682 lbeam: length at beam (as percentage of length, default 0.4) 683 sternbp: beam at stern (as percentage of beam, default 0.5) 684 lmast: position of the mast (as percentage of length, default 0.6) 685 wmast: width of the mast (default 0.1) 686 sd: sails direction respect to center line (default 0.) 687 lheads: length of head sail (as percentage of legnth, defaul 0.38) 688 lmains: length of main sail (as percentage of legnth, defaul 0.55) 689 """ 690 import numpy.ma as ma 691 fname = 'zsailing_boat' 692 693 bow = np.array([length, 0.]) 694 maxportside = np.array([length*lbeam, -beam]) 695 maxstarboardside = np.array([length*lbeam, beam]) 696 portside = np.array([0., -beam*sternbp]) 697 starboardside = np.array([0., beam*sternbp]) 698 699 # forward section 700 fportsaid = circ_sec(bow,maxportside, length*2) 701 fstarboardsaid = circ_sec(maxstarboardside, bow, length*2) 702 dpts = fportsaid.shape[0] 703 704 # aft section 705 aportsaid = circ_sec(maxportside, portside, length*2) 706 astarboardsaid = circ_sec(starboardside, maxstarboardside, length*2) 707 # stern 708 stern = circ_sec(portside, starboardside, length*2) 709 # mast 710 mast = p_circle(wmast,N=dpts) 711 mast = mast + [length*lmast, 0.] 712 # head sails 713 lsail = lheads*length 714 sailsa = np.pi/2. + sd*(1.+0.05)*180./np.pi 715 endsail = np.array([lsail*np.sin(sailsa), lsail*np.cos(sailsa)]) 716 endsail[0] = length - endsail[0] 717 hsail = circ_sec(bow, endsail, lsail*1.15) 718 # main sails 719 lsail = lmains*length 720 endsail = np.array([lsail*np.sin(sailsa), lsail*np.cos(sailsa)]) 721 endsail[0] = length*lmast - endsail[0] 722 msail = circ_sec(np.array([length*lmast,0.]), endsail, lsail*1.15) 723 724 sailingboat = np.zeros((dpts*8+3,2), dtype=np.float) 725 726 sailingboat[0:dpts,:] = fportsaid 727 sailingboat[dpts:2*dpts,:] = aportsaid 728 sailingboat[2*dpts:3*dpts,:] = stern 729 sailingboat[3*dpts:4*dpts,:] = astarboardsaid 730 sailingboat[4*dpts:5*dpts,:] = fstarboardsaid 731 sailingboat[5*dpts,:] = [gen.fillValueF, gen.fillValueF] 732 sailingboat[5*dpts+1:6*dpts+1,:] = mast 733 sailingboat[6*dpts+1,:] = [gen.fillValueF, gen.fillValueF] 734 sailingboat[6*dpts+2:7*dpts+2,:] = hsail 735 sailingboat[7*dpts+2,:] = [gen.fillValueF, gen.fillValueF] 736 sailingboat[7*dpts+2:8*dpts+2,:] = msail 737 738 sailingboat = ma.masked_equal(sailingboat, gen.fillValueF) 739 740 fname = 'sailboat_L' + str(int(length*100.)) + '_B' + str(int(beam*100.)) + \ 741 '_lb' + str(int(lbeam*100.)) + '_sb' + str(int(sternbp*100.)) + \ 742 '_lm' + str(int(lmast*100.)) + '_wm' + str(int(wmast)) + \ 743 '_sd' + str(int(sd)) + '_hs' + str(int(lheads*100.)) + \ 744 '_ms' + str(int(lheads*100.)) + '.dat' 745 if not os.path.isfile(fname): 746 print infmsg 747 print ' ' + fname + ": writting boat coordinates file '" + fname + "' !!" 748 of = open(fname, 'w') 749 of.write('# boat file with Length: ' + str(length) +' max_beam: '+str(beam)+ \ 750 'length_at_max_beam:' + str(lbeam) + '% beam at stern: ' + str(sternbp)+ \ 751 ' % mast position: '+ str(lmast) + ' % mast width: ' + str(wmast) + ' ' + \ 752 ' sails direction:' + str(sd) + ' head sail length: ' + str(lheads) + ' %'+\ 753 ' main sail length' + str(lmains) + '\n') 754 for ip in range(dpts*5): 755 of.write(str(sailingboat[ip,0]) + ' ' + str(sailingboat[ip,1]) + '\n') 756 757 of.close() 758 print fname + ": Successfull written '" + fname + "' !!" 759 760 return sailingboat 673 761 674 762 def write_join_poly(polys, flname='join_polygons.dat'):
Note: See TracChangeset
for help on using the changeset viewer.