get centroids in python script

This is whu quickly answering these questions is a mistake, and why answering these questions is so important :slight_smile:

The script should be as below, but the answer it gives has me scratching my head:
[0.3333333333333333, 0.3333333333333333, 0.0]

#!/usr/bin/env python
import vtk

tet = vtk.vtkTetra()

pts = tet.GetPoints()
pts.InsertPoint(0, 0,0,0)
pts.InsertPoint(1, 1,0,0)
pts.InsertPoint(2, 0,1,0)
pts.InsertPoint(3, 0,0,1)

ptIds = tet.GetPointIds()
ptIds.InsertId(0,0)
ptIds.InsertId(1,1)
ptIds.InsertId(2,2)
ptIds.InsertId(3,3)

centroid = [0,0,0]
tet.GetCentroid(centroid)

print(centroid)

1 Like