How to find the centroid of a list of nodes?

This is probably a naive question. I was a bit confused about this link to find the centroid of a triangle: https://www.geeksforgeeks.org/program-to-find-the-centroid-of-the-triangle/
I was reading a piece of code to calculate the centroid of a list of nodes, where each node is a latitude, longitude, altitude coordinate point in the space. In this code, people simply use the average of each coordinate component as the corresponding coordinate component of the centroid. Any comments are greatly appreciated.

If nodes do not have weight attached to them it is simply mean of the each coordinate component. Otherwise, multiply the node’s coordinates with weight and divide by total weight.

1 Like

In the code you linked, Cartesian coordinates are used instead of geographic, so it is not clear to me what you are trying to do. If you have geographic coordinates, you would need to convert, or find a formula in that representation.

Also, on that page, in the formulas the denominator is 2, while it should be 3 (in the code it is).

2 Likes

Oh sorry! I did say about Cartesian coordinates. I am not sure about polar or spherical coordinates.