source: development/momentum_sink/scripts/create_buildings.py @ 3322

Last change on this file since 3322 was 2927, checked in by nicholas, 19 years ago

final update of all relavent data

File size: 3.3 KB
RevLine 
[2927]1
2import Numeric
3import math
4import random
5import polygon
6import array
7# add inundation dir to your pythonpath
8from pmesh.mesh import Mesh
9from coordinate_transforms.geo_reference import Geo_reference
10
11WidtH = 200 # width of boudary in metres
12
13#random.uniform(0,1) #proper implemantation of random generator
14
15def create_mesh(maximum_triangle_area, depth,
16                mesh_file=None,
17                triangles_in_name = False):
18    """
19    triangles_in_name, if True is used to append the number of
20    triangles in the mesh to the mesh file name.
21    """
22
23    WidtH = 200 # width of boudary in metres
24    breadth = depth
25
26    print "building footprint"
27    print depth * breadth , "m^2"
28    block = 625
29    BL = block**0.5
30
31    porosity = breadth/BL                               
32    print porosity, " Building porosity"
33    # create a mesh instance of class Mesh
34    m = Mesh()
35
36    # Boundary of problem
37    outer_polygon = [[0,-0.2],[5*WidtH,-0.2],[5*WidtH,WidtH+0.2],[0,WidtH+0.2]]# rotated
38    #outer_polygon = [[0,0],[5*WidtH,0],[5*WidtH,WidtH],[0,WidtH]]# normal
39    m.add_region_from_polygon(outer_polygon, tags={'wall':[0,2], 'wave':[3], 'back':[1]})
40
41    # inner polygons => building boundaries
42   
43    dhs = depth/2.0 
44    bhs = breadth/2.0 
45    #Th = (45 *(3.14159/180)) # sets an initial rotation     
46    Th = 0
47    ForDep = (0.2*WidtH) + (BL-dhs)
48    RearDep = 1.2*WidtH
49       
50    Breadths = Numeric.arrayrange( -(BL/2), WidtH+(BL/2), (BL))
51    #Breadths = Numeric.arrayrange( 0, WidtH, (BL))
52    #Breadths = Numeric.arrayrange( (BL/2), 5*WidtH-(BL/2), (BL)) # For ortho-offset
53    print Breadths, "Breadths"
54    Depths = Numeric.arrayrange( ForDep, RearDep, BL )
55    print Depths, "Depths"
56
57    for i,D in enumerate(Depths):
58        Breadths = Breadths + ((-1)**i)*(1.0*BL/2) #Used to offset buildings
59        for B in Breadths:
60            dh1 = (-dhs) * math.cos(Th) + (-bhs) * math.sin(Th)
61            bh1 = (-bhs) * math.cos(Th) - (-dhs) * math.sin(Th)
62            dh2 = (+dhs) * math.cos(Th) + (-bhs) * math.sin(Th)
63            bh2 = (-bhs) * math.cos(Th) - (+dhs) * math.sin(Th)
64            dh3 = (+dhs) * math.cos(Th) + (+bhs) * math.sin(Th)
65            bh3 = (+bhs) * math.cos(Th) - (+dhs) * math.sin(Th)
66            dh4 = (-dhs) * math.cos(Th) + (+bhs) * math.sin(Th)
67            bh4 = (+bhs) * math.cos(Th) - (-dhs) * math.sin(Th)
68            house = [[D+dh1,B+bh1],[D+dh2,B+bh2],[D+dh3,B+bh3],[D+dh4,B+bh4]]
69            walls = list(range(len(house)))
70            m.add_hole_from_polygon(house, tags={'wall':walls})       
71            #print "*********hole added*************"
72            # Th = Th + (37.3 *(3.14159/180)) # keeps rotating individual buildings.
73   
74    m.generate_mesh(maximum_triangle_area=maximum_triangle_area)
75    triangle_count = m.get_triangle_count()
76    print 'mesh_file', mesh_file
77    if mesh_file is None:   
78        return m, triangle_count
79    else:
80        if triangles_in_name is True:
81            mesh_file = mesh_file[:-4] + 'testdob' + str(depth) + '_' + str(triangle_count) \
82                        + mesh_file[-4:]
83        m.export_mesh_file(mesh_file)
84        return mesh_file, triangle_count
85
86#-------------------------------------------------------------
87if __name__ == "__main__":
88    _, triangle_count = create_mesh(100,15,mesh_file="test.tsh")
89    print "triangle_count",triangle_count
Note: See TracBrowser for help on using the repository browser.