Add matrix of inertia (#1460)

* add matrix of inertia + test

* ran black and revert changes made by isort

* add test to cover NotImplementedError for Vertex
This commit is contained in:
Kevin Marchais
2024-01-02 14:16:56 +01:00
committed by GitHub
parent 5de4d9f1c3
commit d1a3a921e9
2 changed files with 37 additions and 0 deletions

View File

@ -238,6 +238,27 @@ class TestCadObjects(BaseTest):
self.assertTupleAlmostEquals((0.0, 0.0, 1.0), mplane.normalAt().toTuple(), 3)
def testMatrixOfInertia(self):
"""
Tests the calculation of the matrix of inertia for a solid
"""
radius = 1.0
height = 2.0
cylinder = Solid.makeCylinder(radius=radius, height=height)
moi = Shape.matrixOfInertia(cylinder)
two_pi = 2 * math.pi
true_moi = (
two_pi * (radius ** 2 / 4 + height ** 2 / 12),
two_pi * (radius ** 2 / 4 + height ** 2 / 12),
two_pi * radius ** 2 / 2,
)
self.assertTupleAlmostEquals((moi[0][0], moi[1][1], moi[2][2]), true_moi, 3)
def testVertexMatrixOfInertiaNotImplemented(self):
with self.assertRaises(NotImplementedError):
vertex = Vertex.makeVertex(1, 1, 1)
Shape.matrixOfInertia(vertex)
def testCenterOfBoundBox(self):
pass