Salome HOME
Merge from V6_main 28/02/2013
[modules/smesh.git] / doc / salome / examples / modifying_meshes_ex10.py
1 # Add Polyhedron
2
3 import salome
4 import smesh
5 import math
6
7 # create an empty mesh structure
8 mesh = smesh.Mesh()  
9
10 # Create nodes for 12-hedron with pentagonal faces
11 al = 2 * math.pi / 5.0
12 cosal = math.cos(al)
13 aa = 13
14 rr = aa / (2.0 * math.sin(al/2.0))
15 dr = 2.0 * rr * cosal
16 r1 = rr + dr
17 dh = rr * math.sqrt(2.0 * (1.0 - cosal * (1.0 + 2.0 * cosal)))
18 hh = 2.0 * dh - dr * (rr*(cosal - 1) + (rr + dr)*(math.cos(al/2) - 1)) / dh
19
20 dd = [] # top
21 cc = [] # below top
22 bb = [] # above bottom
23 aa = [] # bottom
24
25 for i in range(5):
26     cos_bot = math.cos(i*al)
27     sin_bot = math.sin(i*al)
28
29     cos_top = math.cos(i*al + al/2.0)
30     sin_top = math.sin(i*al + al/2.0)
31
32     nd = mesh.AddNode(rr * cos_top, rr * sin_top, hh     ) # top
33     nc = mesh.AddNode(r1 * cos_top, r1 * sin_top, hh - dh) # below top
34     nb = mesh.AddNode(r1 * cos_bot, r1 * sin_bot,      dh) # above bottom
35     na = mesh.AddNode(rr * cos_bot, rr * sin_bot,       0) # bottom
36     dd.append(nd) # top
37     cc.append(nc) # below top
38     bb.append(nb) # above bottom
39     aa.append(na) # bottom
40     pass
41
42 # Create a polyhedral volume (12-hedron with pentagonal faces)
43 mesh.GetMeshEditor().AddPolyhedralVolume([dd[0], dd[1], dd[2], dd[3], dd[4],  # top
44                                           dd[0], cc[0], bb[1], cc[1], dd[1],  # -
45                                           dd[1], cc[1], bb[2], cc[2], dd[2],  # -
46                                           dd[2], cc[2], bb[3], cc[3], dd[3],  # - below top
47                                           dd[3], cc[3], bb[4], cc[4], dd[4],  # -
48                                           dd[4], cc[4], bb[0], cc[0], dd[0],  # -
49                                           aa[4], bb[4], cc[4], bb[0], aa[0],  # .
50                                           aa[3], bb[3], cc[3], bb[4], aa[4],  # .
51                                           aa[2], bb[2], cc[2], bb[3], aa[3],  # . above bottom
52                                           aa[1], bb[1], cc[1], bb[2], aa[2],  # .
53                                           aa[0], bb[0], cc[0], bb[1], aa[1],  # .
54                                           aa[0], aa[1], aa[2], aa[3], aa[4]], # bottom
55                                          [5,5,5,5,5,5,5,5,5,5,5,5])
56
57 salome.sg.updateObjBrowser(1)