# How to find the centroid of a list of nodes?

**URL:** <https://discourse.julialang.org/t/how-to-find-the-centroid-of-a-list-of-nodes/26354>\
**Category:** General Usage\
**Created:** [July 14, 2019, 6:05pm UTC](https://discourse.julialang.org/t/how-to-find-the-centroid-of-a-list-of-nodes/26354 "2019-07-14T18:05:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [July 14, 2019, 6:05pm UTC](https://discourse.julialang.org/t/how-to-find-the-centroid-of-a-list-of-nodes/26354/1 "2019-07-14T18:05:13Z")

</div>

This is probably a naive question. I was a bit confused about this link to find the centroid of a triangle: [Program to find the Centroid of the triangle - GeeksforGeeks](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.

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [July 14, 2019, 6:40pm UTC](https://discourse.julialang.org/t/how-to-find-the-centroid-of-a-list-of-nodes/26354/2 "2019-07-14T18:40:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 15, 2019, 5:27am UTC](https://discourse.julialang.org/t/how-to-find-the-centroid-of-a-list-of-nodes/26354/3 "2019-07-15T05:27:44Z")

</div>

> [@bsnyh](#):
>
> 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 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).

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [July 15, 2019, 8:43am UTC](https://discourse.julialang.org/t/how-to-find-the-centroid-of-a-list-of-nodes/26354/4 "2019-07-15T08:43:32Z")

</div>

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