]> SALOME platform Git repositories - modules/geom.git/blob - doc/salome/examples/center_of_mass.py
Salome HOME
bos #29468: Advanced geometry features: distance Edge-Edge & Face-Face
[modules/geom.git] / doc / salome / examples / center_of_mass.py
1 # Center of masses
2
3 import salome
4 salome.salome_init_without_session()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New()
8 import math
9
10 # create a box
11 box = geompy.MakeBoxDXDYDZ(100,30,100)
12 cm = geompy.MakeCDG(box)
13 if cm is None:
14     raise RuntimeError("MakeCDG(box) failed")
15 else:
16     print("\nCentre of gravity of box has been successfully obtained:")
17     coords = geompy.PointCoordinates(cm)
18     print("(", coords[0], ", ", coords[1], ", ", coords[2], ")")
19     dx = math.sqrt((coords[0] - 50)*(coords[0] - 50))
20     dy = math.sqrt((coords[1] - 15)*(coords[1] - 15))
21     dz = math.sqrt((coords[2] - 50)*(coords[2] - 50))
22     if dx > 1e-7 or dy > 1e-7 or dz > 1e-7:
23         print("But must be (50, 15, 50)")