import Numeric import math import random # add inundation dir to your pythonpath from pmesh.mesh import Mesh from coordinate_transforms.geo_reference import Geo_reference WidtH = 200 # width of boudary in metres #random.uniform(0,1) #proper implemantation of random generator def create_mesh(maximum_triangle_area, depth, mesh_file=None, triangles_in_name = False): """ triangles_in_name, if True is used to append the number of triangles in the mesh to the mesh file name. """ WidtH = 200 # width of boudary in metres breadth = depth print "building footprint" print depth * breadth , "m^2" block = 625 BL = block**0.5 porosity = breadth/BL print porosity, " Building porosity" # create a mesh instance of class Mesh m = Mesh() # Boundary of problem outer_polygon = [[0,0],[5*WidtH,0],[5*WidtH,WidtH],[0,WidtH]] m.add_region_from_polygon(outer_polygon, tags={'wall':[0,2], 'wave':[3], 'back':[1]}) # inner polygons => building boundaries whs = depth/2 lhs = breadth/2 Th = (45 *(3.142/180)) # sets an initial rotation #Th = 0 ForDep = (0.2*WidtH) + (BL-whs) RearDep = 1.2*WidtH Breadths = Numeric.arrayrange( -(BL/2), WidtH+(BL/2), (BL)) #Breadths = Numeric.arrayrange( (BL/2), WidtH-(BL/2), (BL)) # For ortho-offset print Breadths, "Breadths" Depths = Numeric.arrayrange( ForDep, RearDep, BL ) print Depths, "Depths" for i,D in enumerate(Depths): #Breadths = Breadths + ((-1)**i)*(BL/2) #Used to offset buildings for B in Breadths: wh1 = (-whs) * math.cos(Th) + (-lhs) * math.sin(Th) lh1 = (-lhs) * math.cos(Th) - (-whs) * math.sin(Th) wh2 = (+whs) * math.cos(Th) + (-lhs) * math.sin(Th) lh2 = (-lhs) * math.cos(Th) - (+whs) * math.sin(Th) wh3 = (+whs) * math.cos(Th) + (+lhs) * math.sin(Th) lh3 = (+lhs) * math.cos(Th) - (+whs) * math.sin(Th) wh4 = (-whs) * math.cos(Th) + (+lhs) * math.sin(Th) lh4 = (+lhs) * math.cos(Th) - (-whs) * math.sin(Th) polygon = [[D+wh1,B+lh1],[D+wh2,B+lh2],[D+wh3,B+lh3],[D+wh4,B+lh4]] m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]}) #Th = Th + (90 *(3.14159/180)) # keeps rotating individual buildings. m.generate_mesh(maximum_triangle_area=maximum_triangle_area) triangle_count = m.get_triangle_count() if mesh_file is None: return m, triangle_count else: if triangles_in_name is True: mesh_file = mesh_file[:-4] + '_Orth(45)_D=' + str(depth) + '_' + str(triangle_count) \ + mesh_file[-4:] m.export_mesh_file(mesh_file) return mesh_file, triangle_count #------------------------------------------------------------- if __name__ == "__main__": _, triangle_count = create_mesh(100,15,mesh_file="test.tsh") print "triangle_count",triangle_count