- Timestamp:
- May 4, 2019, 5:03:44 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2506 r2507 24 24 # dist_points: Function to provide the distance between two points 25 25 # join_circ_sec: Function to join aa series of points by circular segments 26 # join_circ_sec_rand: Function to join aa series of points by circular segments with 27 # random perturbations 26 28 # max_coords_poly: Function to provide the extremes of the coordinates of a polygon 27 29 # mirror_polygon: Function to reflex a polygon for a given axis … … 305 307 Np = int(N/(Npts+1)) 306 308 for ip in range(Npts-1): 307 dps = dist_points(lpoints[ip], lpoints[ip+1]) 308 jcirc_sec[Np*ip:Np*(ip+1),:] = circ_sec(lpoints[ip], lpoints[ip+1], \ 309 dps*radfrac, Np) 309 p1 = lpoints[ip] 310 p2 = lpoints[ip+1] 311 dps = dist_points(p1, p2) 312 jcirc_sec[Np*ip:Np*(ip+1),:] = circ_sec(p1, p2, dps*radfrac, Np) 310 313 311 314 Np2 = N - (Npts-1)*Np 312 dps = dist_points(lpoints[Npts-1], lpoints[0]) 313 jcirc_sec[(Npts-1)*Np:N,:] = circ_sec(lpoints[Npts-1], lpoints[0], dps*3., Np2) 315 p1 = lpoints[Npts-1] 316 p2 = lpoints[0] 317 dps = dist_points(p1, p2) 318 jcirc_sec[(Npts-1)*Np:N,:] = circ_sec(p1, p2, dps*3., Np2) 314 319 315 320 return jcirc_sec 321 322 def join_circ_sec_rand(points, radfrac=3., Lrand=0.1, N=200): 323 """ Function to join aa series of points by circular segments with random 324 perturbations 325 points: main points of the island (clockwise ordered, to be joined by circular 326 segments of radii as the radfrac factor of the distance between 327 consecutive points) 328 radfrac: multiplicative factor of the distance between consecutive points to 329 draw the circular segment (3., default) 330 Lrand: maximum length of the random perturbation to be added perpendicularly to 331 the direction of the union line between points (0.1, default) 332 N: number of points (200, default) 333 """ 334 import random 335 fname = 'join_circ_sec_rand' 336 337 jcirc_sec = np.ones((N,2), dtype=np.float) 338 339 # main points 340 lpoints = list(points) 341 Npts = len(lpoints) 342 Np = int(N/(Npts+1)) 343 for ip in range(Npts-1): 344 p1 = lpoints[ip] 345 p2 = lpoints[ip+1] 346 dps = dist_points(p1, p2) 347 angle = np.arctan2(p2[0]-p1[0], p2[1]-p1[1]) + np.pi/2. 348 jcirc_sec[Np*ip:Np*(ip+1),:] = circ_sec(p1, p2, dps*radfrac, Np) 349 drand = Lrand*np.array([np.sin(angle), np.cos(angle)]) 350 for iip in range(Np*ip,Np*(ip+1)): 351 jcirc_sec[iip,:] = jcirc_sec[iip,:] + drand*random.uniform(-1.,1.) 352 353 Np2 = N - (Npts-1)*Np 354 p1 = lpoints[Npts-1] 355 p2 = lpoints[0] 356 dps = dist_points(p1, p2) 357 angle = np.arctan2(p2[0]-p1[0], p2[1]-p1[1]) + np.pi/2. 358 jcirc_sec[(Npts-1)*Np:N,:] = circ_sec(p1, p2, dps*3., Np2) 359 drand = Lrand*np.array([np.sin(angle), np.cos(angle)]) 360 for iip in range(Np*(Npts-1),N): 361 jcirc_sec[iip,:] = jcirc_sec[iip,:] + drand*random.uniform(-1.,1.) 362 363 return jcirc_sec 364 316 365 317 366 ####### ###### ##### #### ### ## # … … 938 987 939 988 # Coastline 940 941 island1 = join_circ_sec(mainpts, radfrac=3., N=200) 989 island1 = join_circ_sec_rand(mainpts) 942 990 943 991 islandsecs = ['coastline']
Note: See TracChangeset
for help on using the changeset viewer.