Group Centroid

If you want to do it the way how it is done in Rhino (_AreaCentroid command) what is right way how to do, then you should calculate it as Weighted arithmetic mean. The code in C# component is simple:

    private void RunScript(List<double> Area, List<Point3d> AreaCentroid, ref object AvgCentroid)
    {
        Point3d pointSum = new Point3d();
        double AreaSum = 0;
        for (int i = 0; i < Area.Count; i++)
        {
            pointSum += Area[i] * AreaCentroid[i];
            AreaSum += Area[i];
        }
        AvgCentroid = pointSum / AreaSum;
    }

Here is the ghfile Centroid Group 02.gh (5.3 KB)

and here is link to Wikipedia Weighted arithmetic mean

1 Like