Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 679 Bytes
aa651cf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# -*- coding: utf-8 -*-
"""
Calculate moments of inertia for a disc from STL file.
"""
import numpy as np
import trimesh
import sys
import os
path = os.path.dirname(os.path.realpath(__file__))
# attach to logger so trimesh messages will be printed to console
#trimesh.util.attach_to_log()
name = sys.argv[-1]
m = trimesh.load(os.path.join(path, 'discs', name + '.stl'))
trimesh.repair.fix_inversion(m)
trimesh.repair.fix_normals(m)
trimesh.repair.fix_winding(m)
if m.is_watertight and m.is_winding_consistent and m.is_volume:
V = m.volume
J = m.principal_inertia_components/V
print('Volume: ', V)
print('J_xy: %4.3e' % J[0])
print('J_z: %4.3e' % J[2])
|