Finding centroid of wavy enclosed curved pieces

Hi. It is possible to adapt this scripts to work with shapes that have other orientation in space than the XY one? Best regards.

There it is a solution: