geom/doc/salome/examples/center_of_mass.py

24 lines
715 B
Python
Raw Normal View History

2013-02-12 17:35:16 +06:00
# Center of masses
import salome
salome.salome_init()
import GEOM
from salome.geom import geomBuilder
2017-06-13 14:57:14 +05:00
geompy = geomBuilder.New()
2013-02-12 17:35:16 +06:00
import math
# create a box
box = geompy.MakeBoxDXDYDZ(100,30,100)
cm = geompy.MakeCDG(box)
if cm is None:
2017-02-10 21:07:24 +05:00
raise RuntimeError("MakeCDG(box) failed")
2013-02-12 17:35:16 +06:00
else:
2017-02-10 21:07:24 +05:00
print("\nCentre of gravity of box has been successfully obtained:")
2013-02-12 17:35:16 +06:00
coords = geompy.PointCoordinates(cm)
2017-02-10 21:07:24 +05:00
print("(", coords[0], ", ", coords[1], ", ", coords[2], ")")
2013-02-12 17:35:16 +06:00
dx = math.sqrt((coords[0] - 50)*(coords[0] - 50))
dy = math.sqrt((coords[1] - 15)*(coords[1] - 15))
dz = math.sqrt((coords[2] - 50)*(coords[2] - 50))
if dx > 1e-7 or dy > 1e-7 or dz > 1e-7:
2017-02-10 21:07:24 +05:00
print("But must be (50, 15, 50)")