Changeset 2623 in lmdz_wrf for trunk/tools
- Timestamp:
- Jun 22, 2019, 9:03:58 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2622 r2623 24 24 ####### Contents: 25 25 # add_secpolygon_list: Function to add a range of points of a polygon into a list 26 # angle_vectors2D: Angle between two vectors with sign 26 27 # cut_between_[x/y]polygon: Function to cut a polygon between 2 given value of the [x/y]-axis 27 28 # cut_[x/y]polygon: Function to cut a polygon from a given value of the [x/y]-axis … … 277 278 fname = 'mod_vec' 278 279 279 mod = np.sqrt(vec[0]*vec[0] + vec[1]*vec[1]) 280 v = np.array(vec, dtype=np.float) 281 mod = np.sqrt(v[0]*v[0] + v[1]*v[1]) 280 282 281 283 return mod 282 284 283 print mod_vec([1., 1.])284 quit()285 286 285 def angle_vectors2D(veca, vecb): 287 """ Angle between two vectors 286 """ Angle between two vectors with sign 287 FROM: https://stackoverflow.com/questions/5188561/signed-angle-between-two-3d-vectors-with-same-origin-within-the-same-plane 288 288 veca: angle A [ya, xa] 289 289 vecb: angle B [yb, xb] 290 290 NOTE: angle from A to B 291 291 >>> angle_vectors2D([1.,0.], [0.,1.]) 292 292 1.57079632679 293 >>> angle_vectors2D([0.,1.], [1.,0.]) 294 1.57079632679 293 295 """ 294 296 fname = 'angle_vectors2D' 295 297 296 moda = mod_vec(veca) 297 modb = mod_vec(vecb) 298 299 return alpha 298 v1 = np.array(veca, dtype=np.float) 299 v2 = np.array(vecb, dtype=np.float) 300 301 moda = mod_vec(v1) 302 modb = mod_vec(v2) 303 modab = mod_vec(v1*v2) 304 305 vc = np.cross(v1,v2) 306 theta = np.arcsin(vc/(moda*modb)) 307 308 # Without sign 309 #alpha = np.arccos(modab/(moda*modb)) 310 311 return theta 312 313 print angle_vectors2D([1.,0.], [0.,1.]) 314 print angle_vectors2D([0.,1.], [1.,0.]) 315 316 quit() 300 317 301 318 def max_coords_poly(polygon):
Note: See TracChangeset
for help on using the changeset viewer.