- Timestamp:
- May 15, 2019, 3:42:57 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2531 r2533 45 45 # circ_sec: Function union of point A and B by a section of a circle 46 46 # ellipse_polar: Function to determine an ellipse from its center and polar coordinates 47 # p_angle_triangle: Function to draw a triangle by an initial point and two 48 # consecutive angles and the first length of face. The third angle and 2 and 3rd 49 # face will be computed accordingly the provided values 47 50 # p_doubleArrow: Function to provide an arrow with double lines 48 51 # p_circle: Function to get a polygon of a circle … … 868 871 869 872 return doubleArrow, doublearrowsecs, doublearrowdic 873 874 def p_angle_triangle(pi=np.array([0.,0.]), angle1=60., length1=1., angle2=60., N=100): 875 """ Function to draw a triangle by an initial point and two consecutive angles 876 and the first length of face. The third angle and 2 and 3rd face will be 877 computed accordingly the provided values: 878 length1 / sin(angle1) = length2 / sin(angle2) = length3 / sin(angle3) 879 angle1 + angle2 + angle3 = 180. 880 pi: initial point ([0., 0.], default) 881 angle1: first angle from pi clockwise (60., default) 882 length1: length of face from pi by angle1 (1., default) 883 angle2: second angle from second point (60., default) 884 length2: length of face from p2 by angle2 (1., default) 885 N: number of points (100, default) 886 """ 887 fname = 'p_angle_triange' 888 889 angle3 = 180. - angle1 - angle2 890 length2 = np.sin(angle2*np.pi/180.)*length1/np.sin(angle1*np.pi/180.) 891 length3 = np.sin(angle3*np.pi/180.)*length1/np.sin(angle1*np.pi/180.) 892 893 print 'lengths', length1, length2, length3 894 895 triangle = np.zeros((N,2), dtype=np.float) 896 897 N3 = int(N/3) 898 # first face 899 ix = pi[1] 900 iy = pi[0] 901 dx = length1*np.cos(angle1*np.pi/180.)/(N3-1) 902 dy = length1*np.sin(angle1*np.pi/180.)/(N3-1) 903 for ip in range(N3): 904 triangle[ip,:] = [iy+dy*ip, ix+dx*ip] 905 906 # second face 907 ia = -90. - (90.-angle1) 908 ix = triangle[N3-1,1] 909 iy = triangle[N3-1,0] 910 dx = length2*np.cos((ia+angle2)*np.pi/180.)/(N3-1) 911 dy = length2*np.sin((ia+angle2)*np.pi/180.)/(N3-1) 912 for ip in range(N3): 913 triangle[N3+ip,:] = [iy+dy*ip, ix+dx*ip] 914 915 # third face 916 N32 = N - 2*N3 917 ia = -180. - (90.-angle2) 918 ix = triangle[2*N3-1,1] 919 iy = triangle[2*N3-1,0] 920 angle3 = np.arctan2(pi[0]-iy, pi[1]-ix) 921 dx = (pi[1]-ix)/(N32-1) 922 dy = (pi[0]-iy)/(N32-1) 923 for ip in range(N32): 924 triangle[2*N3+ip,:] = [iy+dy*ip, ix+dx*ip] 925 926 return triangle 870 927 871 928 # Combined objects … … 1123 1180 bfrac: fraction of the ball above the prism (0.8, default) 1124 1181 N: total number of points of the buoy (200, default) 1125 1126 1182 """ 1127 1183 fname = 'buoy1' … … 1350 1406 return lighthouse, lighthousesecs, lighthousedic 1351 1407 1408 def north_buoy1(height=5., width=10., bradii=1.75, bfrac=0.8, hsings=0.2, N=300): 1409 """ Function to draw a North danger buoy using buoy1 1410 height: height of the prism (5., default) 1411 width: width of the prism (10., default) 1412 bradii: radii of the ball (1.75, default) 1413 bfrac: fraction of the ball above the prism (0.8, default) 1414 hisngs: height of the sings [as reg. triangle] as percentage of the height 1415 (0.2, default) 1416 N: total number of points of the buoy (300, default) 1417 """ 1418 fname = 'north_buoy1' 1419 1420 Nbuoy = np.ones((N,2), dtype=np.float)*gen.fillValueF 1421 1422 # buoy 1423 N2 = int(N/2) 1424 buoy1v = buoy1(height=5., width=10., bradii=1.75, bfrac=0.8, hsings=0.2, N=N2) 1425 Nbuoy[0:N2] = buoy1v 1426 1427 # signs 1428 N3 = N - N2 - 1 1429 1430 lsign = height*hsigns 1431 # First up 1432 N32 = N3 / 2 1433 N323 = N32 / 3 1434 1435 # left up arm 1436 ix = -lsign/2. 1437 iy = height 1438 dx = -lsign/(2.*(N323-1)) 1439 dy = lsign*np.sin(np.pi/3.)/(N323-1) 1440 for ip in range(N323): 1441 Nbuoy[N2+1:N2+N323+1] = [iy + dy*ip, ix + dx*ip] 1442 1443 Nbuoy = ma.masked_equal(Nbuoy, gen.fillValueF) 1444 1445 return Nbuoy, Nbuoysecs, Nbuoydic 1446 1352 1447 ####### ####### ##### #### ### ## # 1353 1448 # Plotting
Note: See TracChangeset
for help on using the changeset viewer.