# source:development/momentum_sink/rotate_buildings.py@2379

Last change on this file since 2379 was 2379, checked in by nicholas, 18 years ago
File size: 2.8 KB
Line
1
2import Numeric
3import math
5from pmesh.mesh import Mesh
6from coordinate_transforms.geo_reference import Geo_reference
7
8
9def create_mesh(maximum_triangle_area,
10                mesh_file=None,
11                triangles_in_name = False):
12    """
13    triangles_in_name, if True is used to append the number of
14    triangles in the mesh to the mesh file name.
15    """
16    # create a mesh instance of class Mesh
17    m = Mesh()
18
19    # Boundary of problem
20    WidtH = 100 # width of boudary in metres
21    #W = WidtH/8
22    #L = W
23    outer_polygon = [[0,0],[1.5*WidtH,0],[1.5*WidtH,WidtH],[0,WidtH]]
24    print outer_polygon
26
27    # inner polygons => building boundaries
28    depth = 15 # depth of building side to oncoming wave
29    whs = depth/2
32
33    # Sample rotation Matrix
34    Thd = 30 # Degrees
35    Th = Thd * 3.14259/180 # Deg to Rad.
36
37    wh1 = (-whs) * math.cos(Th) + (-lhs) * math.sin(Th)
38    lh1 = (-lhs) * math.cos(Th) - (-whs) * math.sin(Th)
39
40    wh2 = (+whs) * math.cos(Th) + (-lhs) * math.sin(Th)
41    lh2 = (-lhs) * math.cos(Th) - (+whs) * math.sin(Th)
42
43    wh3 = (+whs) * math.cos(Th) + (+lhs) * math.sin(Th)
44    lh3 = (+lhs) * math.cos(Th) - (+whs) * math.sin(Th)
45
46    wh4 = (-whs) * math.cos(Th) + (+lhs) * math.sin(Th)
47    lh4 = (+lhs) * math.cos(Th) - (-whs) * math.sin(Th)
48
49    print "building footprint"
50    print depth * breadth , "m^2"
51    block = 625
52    BL = block**0.5
53    ForDep = (0.2*WidtH) + (BL/2)
54    RearDep = 1.2*WidtH
56    print porosity, " Building porosity"
57
58    Breadths = Numeric.arrayrange( (BL/2), WidtH, (BL))
60    Depths = Numeric.arrayrange( ForDep, RearDep, BL )
61    print Depths, "Depths"
62
63    for D in Depths:
66            polygon = [[D+wh1,B+lh1],[D+wh2,B+lh2],[D+wh3,B+lh3],[D+wh4,B+lh4]]
68
69
70            #print polygon
71    m.generate_mesh(maximum_triangle_area=maximum_triangle_area)
72    triangle_count = m.get_triangle_count()
73
74    if mesh_file is None:
75        return m, triangle_count
76    else:
77        if triangles_in_name is True:
78            mesh_file = mesh_file[:-4] + '_' + str(triangle_count) \
79                        + mesh_file[-4:]
80        m.export_mesh_file(mesh_file)
81        return mesh_file, triangle_count
82
83#-------------------------------------------------------------
84if __name__ == "__main__":
85    _, triangle_count = create_mesh(10,mesh_file="test.tsh")
86    print "triangle_count",triangle_count
Note: See TracBrowser for help on using the repository browser.