Changeset 5086 for anuga_core/source/anuga/utilities/polygon.py
 Timestamp:
 Feb 28, 2008, 10:43:58 AM (16 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

anuga_core/source/anuga/utilities/polygon.py
r4882 r5086 5 5 6 6 7 try: 8 from scipy import Float, Int, zeros, ones, array, concatenate, reshape, dot 9 except: 10 #print 'Could not find scipy  using Numeric' 11 from Numeric import Float, Int, zeros, ones, array, concatenate, reshape, dot 7 #try: 8 # from scipy import Float, Int, zeros, ones, array, concatenate, reshape, dot 9 #except: 10 # #print 'Could not find scipy  using Numeric' 11 12 from Numeric import Float, Int, zeros, ones, array, concatenate, reshape, dot 12 13 13 14 … … 337 338 338 339 def plot_polygons(polygons_points, style=None, 339 340 figname=None, label=None, verbose=False): 340 341 341 342 """ Take list of polygons and plot. … … 572 573 573 574 575 def write_polygon(polygon, filename=None): 576 """Write polygon to csv file. 577 There will be exactly two numbers, easting and northing, 578 in each line separated by a comma. 579 580 No header. 581 """ 582 583 fid = open(filename, 'w') 584 for point in polygon: 585 fid.write('%f, %f\n' %point) 586 fid.close() 587 588 574 589 def populate_polygon(polygon, number_of_points, seed=None, exclude=None): 575 590 """Populate given polygon with uniformly distributed points. … … 595 610 points = [] 596 611 597 # Find outer extent of polygon612 # Find outer extent of polygon 598 613 max_x = min_x = polygon[0][0] 599 614 max_y = min_y = polygon[0][1] … … 722 737 723 738 739 def decimate_polygon(polygon, factor=10): 740 """Reduce number of points in polygon by the specified 741 factor (default=10, hence the name of the function) such that 742 the extrema in both axes are preserved. 743 744 Return reduced polygon 745 """ 746 747 # FIXME(Ole): This doesn't work at present, 748 # but it isn't critical either 749 750 # Find outer extent of polygon 751 num_polygon = ensure_numeric(polygon) 752 max_x = max(num_polygon[:,0]) 753 max_y = max(num_polygon[:,1]) 754 min_x = min(num_polygon[:,0]) 755 min_y = min(num_polygon[:,1]) 756 757 # Keep only some points making sure extrema are kept 758 reduced_polygon = [] 759 for i, point in enumerate(polygon): 760 x = point[0] 761 y = point[1] 762 if x in [min_x, max_x] and y in [min_y, max_y]: 763 # Keep 764 reduced_polygon.append(point) 765 else: 766 if len(reduced_polygon)*factor < i: 767 reduced_polygon.append(point) 768 769 return reduced_polygon 770 724 771 ############################################## 725 772 #Initialise module
Note: See TracChangeset
for help on using the changeset viewer.