- Timestamp:
- Apr 1, 2017, 5:50:24 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r1473 r1482 60 60 # color_deg: Function to generate a degradation of colors in rgb base 61 61 # contflow: Function to bring back the increment in j,i grid points according to a trip: (inflow directions) 62 # crossingpoint_2Dlines: Function to determinant the crossing point between two lines in a plane 62 63 # curvelocalize_2D: Function to provide the localization a curve in a 2D field of positions via the equivalent 63 64 # i,j-quads within which the curve lays (-1, no value for the given quad [2x2 points around]) and provide … … 103 104 # period_information_360d: Function to provide the information of a given period idate, edate (dates in 104 105 # [YYYY][MM][DD][HH][MI][SS] format) in a 360 years calendar 106 # points_2Dline: Function to define a line from a pair of points on a plane 107 # PolyArea: Function to compute the area of the polygon following 'Shoelace formula' 105 108 # pretty_int: Function to plot nice intervals 106 109 # prime_decomposition: Function to decompose a given number with its multiple prime numbers 107 110 # prime_numbers: Function to find all the prime numbers up to a given value above 17 108 111 # printing_dictionary: Function to print the content of a dictionary 109 # PolyArea: Function to compute the area of the polygon following 'Shoelace formula'110 112 # radius_angle: Function to generate a matrix with the angle at a given point 111 113 # radius_dist: Function to generate a matrix with the distance at a given point … … 11456 11458 return gribcode 11457 11459 11460 def crossingpoint_2Dlines(line1, line2): 11461 """ Function to determinant the crossing point between two lines in a plane 11462 line1= [a,b,c] terms of the polynomial representation of line1 ax+by+d 11463 line2= [a,b,c] terms of the polynomial representation of line2 ax+by+d 11464 >>> crossingpoint_2Dlines(np.array([1,-1,0]), np.array([1,1,-3])) 11465 [[ 1.5 1.5]] 11466 """ 11467 fname = 'crossingpoint_2lines' 11468 11469 if len(line1.shape) != len(line2.shape): 11470 print errormsg 11471 print ' ' + fname + ': rank difference between lines !!' 11472 print ' shape line1:', line1.shape, 'line2:', line2.shape 11473 quit(-1) 11474 11475 #determinant 11476 matA = np.array([line1[0:2], line2[0:2]]) 11477 detA = np.linalg.det(matA) 11478 11479 # x-det 11480 matX = np.array([[-line1[2],-line1[1]], [line2[2],line2[1]]]) 11481 detX = np.linalg.det(matX) 11482 11483 # y-det 11484 matY = np.array([[line1[0],line1[2]], [-line2[0],-line2[2]]]) 11485 detY = np.linalg.det(matY) 11486 11487 #print 'mat A:' 11488 #print matA 11489 #print 'mat X:' 11490 #print matX 11491 #print 'mat Y:' 11492 #print matY 11493 11494 #print 'det A:', detA, 'X:', detX, 'Y:', detY 11495 11496 x = detX / detA 11497 y = detY / detA 11498 11499 return np.array([[x, y]]) 11500 11501 #print crossingpoint_2Dlines(np.array([1,-1,0]), np.array([1,1,-3])) 11502 11503 def points_2Dline(pt1, pt2): 11504 """ Function to define a line from a pair of points on a plane 11505 it returns the terms of the polynomial description of the line ax+by+c=0 [a,b,c] 11506 pt1= first point [x,y] 11507 pt2= second point [x,y] 11508 >>> points_2Dline(np.array([1,1]), np.array([2,2])) 11509 [1 -1 0] 11510 points_2Dline(np.array([1,2]), np.array([2,1])) 11511 [1 1 -3] 11512 """ 11513 fname = 'points_2Dline' 11514 11515 # minus 11516 minuseq = pt1 - pt2 11517 b = -minuseq[0]/minuseq[1] 11518 11519 # plus 11520 pluseq = pt1 + pt2 11521 subsb = pluseq[1]*b 11522 11523 subsa = pluseq[0] + subsb 11524 11525 c = -subsa/2 11526 11527 return np.array([1, b, c]) 11528 11529 line1 = points_2Dline(np.array([1,1]), np.array([2,2])) 11530 line2 = points_2Dline(np.array([1,2]), np.array([2,1])) 11531 11532 print crossingpoint_2Dlines(np.array([1,-1,0]), np.array([1,1,-3])) 11533 11458 11534 #quit()
Note: See TracChangeset
for help on using the changeset viewer.