You code is not reproducible, so it really doesn't help much.
However it seems that your mechanics calculation is the actual
integral over the shape of the beam.
This is not what polygonCentroid do. For this function there is only
vertices (mass points at the nodes if you want).
So if you beam if deformed and the polygon representing it is not very
fine (lots of vertices) it is expected that the two calculations will
Most functions on polygons treat them as naturally discrete objects
with all the info given by the vertices. Any calculation that uses
path information will give different results whenever the path is not
a straight segment connecting the vertices, or when functions along
the path depend on the path coordinates.