How to Calculate Centroid

后端 未结 4 1502
长情又很酷
长情又很酷 2021-02-06 03:15

I am working with geospatial shapes and looking at the centroid algorithm here,

http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon

I have implemented the

4条回答
  •  孤城傲影
    2021-02-06 03:49

    For 3d Points, I created a method in C # I hope I can help you:

    public static double[] GetCentroid(List listOfPoints)
        {
            // centroid[0] = X
            // centroid[1] = Y
            // centroid[2] = Z
            double[] centroid = new double[3];
    
            // List iteration
            // Link reference:
            // https://en.wikipedia.org/wiki/Centroid
            foreach (double[] point in listOfPoints)
            {
                centroid[0] += point[0];
                centroid[1] += point[1];
                centroid[2] += point[2];
            }
    
            centroid[0] /= listOfPoints.Count;
            centroid[1] /= listOfPoints.Count;
            centroid[2] /= listOfPoints.Count;
    
            return centroid;
        }
    

提交回复
热议问题