Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Center of masses
1 # Center of masses
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
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)"

Download this script