PolyClipper
PolyClipper copied to clipboard
Wrong computation of first (centroid) moment of Polyhedron
For the following Polyhedron, the centroid is at (1.5, 1.5, 1.5) but instead PolyClipper gives (1.500000, 1.125000, 1.125000):
import PolyClipper as pc
dummy_vertex_list = [[0.0, 0.0, 0.0], [3.0, 0.0, 0.0], [0.0, 3.0, 0.0], [3.0, 3.0, 0.0], [0.0, 0.0, 3.0], [3.0, 0.0, 3.0], [0.0, 3.0, 3.0], [3.0, 3.0, 3.0]]
dummy_all_vertex_neighbor_list = [[1, 2, 4], [0, 3, 5], [0, 3, 6], [1, 2, 7], [0, 5, 6], [1, 4, 7], [2, 4, 7], [3, 5, 6]]
polyhedron_vertices = [pc.Vector3d(*coords) for coords in dummy_vertex_list]
poly = pc.Polyhedron()
pc.initializePolyhedron(poly, polyhedron_vertices, dummy_all_vertex_neighbor_list)
print("poly:", poly)
print("moments: ", pc.moments(poly))
The output obtained is:
('poly:', Polyhedron[Vertex3d[ ( 0 0 0) [1 2 4 ] 1 -1], Vertex3d[ ( 3 0 0) [0 3 5 ] 1 -1], Vertex3d[ ( 0 3 0) [0 3 6 ] 1 -1], Vertex3d[ ( 3 3 0) [1 2 7 ] 1 -1], Vertex3d[ ( 0 0 3) [0 5 6 ] 1 -1], Vertex3d[ ( 3 0 3) [1 4 7 ] 1 -1], Vertex3d[ ( 0 3 3) [2 4 7 ] 1 -1], Vertex3d[ ( 3 3 3) [3 5 6 ] 1 -1]])
('moments: ', (9.0, (1.500000, 1.125000, 1.125000)))
Where am I going wrong? Please help!!
The centroid operation is not correct yet, that needs to be fixed in a future update. This is mentioned in the documentation:
https://polyclipper.readthedocs.io/en/latest/polygon_methods.html
This has been considered low-priority as we have mostly been interested the clipping operations, though it is something to be fixed.