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