- Timestamp:
- Mar 24, 2019, 6:55:57 PM (7 years ago)
- File:
-
- 1 edited
-
trunk/tools/geometry_tools.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2412 r2413 15 15 import matplotlib.pyplot as plt 16 16 17 errormsg = 'ERROR -- error -- ERROR -- error' 18 17 19 ####### Contents: 18 20 # deg_deci: Function to pass from degrees [deg, minute, sec] to decimal angles [rad] 21 # dist_points: Function to provide the distance between two points 19 22 # multi_rotate_2D: Function to rotate multiple vectors by a certain angle in the plain 20 23 # position_sphere: Function to tranform fom a point in lon, lat deg coordinates to … … 25 28 # rotate_lines2D: Function to rotate multiple lines given by mulitple pars of x,y 26 29 # coordinates by a certain angle in the plain 27 # surface_sphere: Function to provide an sphere as matrix of x,y,z coordinates28 30 # spheric_line: Function to transform a series of locations in lon, lat coordinates 29 31 # to x,y,z over an 3D spaceFunction to provide coordinates of a line on a 3D space … … 31 33 ## Shapes/objects 32 34 # ellipse_polar: Function to determine an ellipse from its center and polar coordinates 35 # surface_sphere: Function to provide an sphere as matrix of x,y,z coordinates 33 36 34 37 ## Plotting … … 67 70 68 71 return xpt, ypt, zpt 69 70 def surface_sphere(radii,Npts):71 """ Function to provide an sphere as matrix of x,y,z coordinates72 radii: radii of the sphere73 Npts: number of points to discretisize longitues (half for latitudes)74 """75 fname = 'surface_sphere'76 77 sphereup = np.zeros((3,Npts/2,Npts), dtype=np.float)78 spheredown = np.zeros((3,Npts/2,Npts), dtype=np.float)79 for ia in range(Npts):80 alpha = ia*2*np.pi/(Npts-1)81 for ib in range(Npts/2):82 beta = ib*np.pi/(2.*(Npts/2-1))83 sphereup[:,ib,ia] = position_sphere(radii, alpha, beta)84 for ib in range(Npts/2):85 beta = -ib*np.pi/(2.*(Npts/2-1))86 spheredown[:,ib,ia] = position_sphere(radii, alpha, beta)87 88 return sphereup, spheredown89 72 90 73 def spheric_line(radii,lon,lat): … … 225 208 # Shapes/objects 226 209 210 def surface_sphere(radii,Npts): 211 """ Function to provide an sphere as matrix of x,y,z coordinates 212 radii: radii of the sphere 213 Npts: number of points to discretisize longitues (half for latitudes) 214 """ 215 fname = 'surface_sphere' 216 217 sphereup = np.zeros((3,Npts/2,Npts), dtype=np.float) 218 spheredown = np.zeros((3,Npts/2,Npts), dtype=np.float) 219 for ia in range(Npts): 220 alpha = ia*2*np.pi/(Npts-1) 221 for ib in range(Npts/2): 222 beta = ib*np.pi/(2.*(Npts/2-1)) 223 sphereup[:,ib,ia] = position_sphere(radii, alpha, beta) 224 for ib in range(Npts/2): 225 beta = -ib*np.pi/(2.*(Npts/2-1)) 226 spheredown[:,ib,ia] = position_sphere(radii, alpha, beta) 227 228 return sphereup, spheredown 229 227 230 def ellipse_polar(c, a, b, Nang=100): 228 231 """ Function to determine an ellipse from its center and polar coordinates … … 249 252 return ellipse 250 253 254 def hyperbola_polar(a, b, Nang=100): 255 """ Fcuntion to determine an hyperbola in polar coordinates 256 FROM: https://en.wikipedia.org/wiki/Hyperbola#Polar_coordinates 257 x^2/a^2 - y^2/b^2 = 1 258 a= x-parameter 259 y= y-parameter 260 Nang= number of angles to use 261 DOES NOT WORK!!!! 262 """ 263 fname = 'hyperbola_polar' 264 265 dtheta = 2.*np.pi/(Nang-1) 266 267 # Positive branch 268 hyperbola_p = np.zeros((Nang,2), dtype=np.float) 269 for ia in range(Nang): 270 theta = dtheta*ia 271 x = a*np.cosh(theta) 272 y = b*np.sinh(theta) 273 hyperbola_p[ia,:] = [y,x] 274 275 # Negative branch 276 hyperbola_n = np.zeros((Nang,2), dtype=np.float) 277 for ia in range(Nang): 278 theta = dtheta*ia 279 x = -a*np.cosh(theta) 280 y = b*np.sinh(theta) 281 hyperbola_n[ia,:] = [y,x] 282 283 return hyperbola_p, hyperbola_n 284 285 def dist_points(ptA, ptB): 286 """ Function to provide the distance between two points 287 ptA: coordinates of the point A [yA, xA] 288 ptB: coordinates of the point B [yB, xB] 289 >>> dist_points([1.,1.], [-1.,-1.]) 290 2.82842712475 291 """ 292 fname = 'dist_points' 293 294 dist = np.sqrt( (ptA[0]-ptB[0])**2 + (ptA[1]-ptB[1])**2) 295 296 return dist 297 298 def circ_sec(ptA, ptB, radii, Nang=100): 299 """ Function union of point A and B by a section of a circle 300 ptA= coordinates od the point A [yA, xA] 301 ptB= coordinates od the point B [yB, xB] 302 radii= radi of the circle to use to unite the points 303 Nang= amount of angles to use 304 """ 305 fname = 'circ_sec' 306 307 distAB = dist_points(ptA,ptB) 308 309 if distAB > radii: 310 print errormsg 311 print ' ' + fname + ': radii=', radii, " too small for the distance " + \ 312 "between points !!" 313 print ' distance between points:', distAB 314 quit(-1) 315 316 if ptA[0] > ptB[0]: 317 tottheta = np.atan2(ptA[0]-ptB[0],ptA[1]-ptB[1]) 318 yc=ptA[0] 319 if ptA[1] < ptB[0]: 320 sign = -1 321 xc=ptA[1]+radii 322 else: 323 sign = 1 324 xc=ptA[1]-radii 325 else: 326 tottheta = np.atan2(ptB[0]-ptA[0],ptB[1]-ptA[1]) 327 yc=ptA[0] 328 if ptA[1] < ptB[0]: 329 sign = 1 330 xc=ptA[1]+radii 331 else: 332 sign = -1 333 xc=ptA[1]-radii 334 335 dtheta = np.abs(tottheta)/(Nang-1) 336 if sign == 1: 337 dtheta = dtheta*(-1.) 338 339 circ_sec = np.zeros((Nang,2), dtype=np.float) 340 for ia in range(Nang): 341 theta = dtheta*ia 342 x = radii*np.cos(theta) 343 y = radii*np.sin(theta) 344 345 circ_sec[ia,:] = [x+xc,y+yc] 346 347 return circ_sec 348 349 # FROM: http://www.photographers1.com/Sailing/NauticalTerms&Nomenclature.html 350 def zsailing_boat(length=10., beam=3., sternbp=0.5): 351 """ Function to define an schematic boat from the z-plane 352 length: length of the boat 353 beam: beam of the boat 354 sternbp: beam at stern as percentage of beam 355 """ 356 fname = 'zsailing_boat' 357 358 359 360 return boat 251 361 252 362 ####### ####### ##### #### ### ## #
Note: See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/LMDZ_WRF/chrome/site/your_project_logo.png)