# How to sort two list of points

**URL:** <https://discourse.mcneel.com/t/how-to-sort-two-list-of-points/157193>\
**Category:** Grasshopper\
**Tags:** windows, rhino7\
**Created:** [March 27, 2023, 3:33pm UTC](https://discourse.mcneel.com/t/how-to-sort-two-list-of-points/157193 "2023-03-27T15:33:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lazan](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/lazan/32/485012_2.png) [@Lazan](https://discourse.mcneel.com/u/Lazan)\
**Post date:** [March 27, 2023, 3:33pm UTC](https://discourse.mcneel.com/t/how-to-sort-two-list-of-points/157193/1 "2023-03-27T15:33:58Z")

</div>

Hi, the order of the point in the two points list is different, so I can not connect them with lines in a drawn way. What is the easiest way to connect the point in the center to the points around it? Each bunch of points located inside has to connect two bunch of points which are located around like the lines were drawn as help.  
[Connecting points.gh](https://discourse.mcneel.com/uploads/short-url/sceOECQXIzE2t3H9PntKQh2PAO.gh) (8.0 KB)

 ![Screenshot 2023-03-27 173455](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/c/a/1/ca1b1c0e50f3f8e12ea2b46ec44df4bb16d0f515.jpeg)

---

<div class="post-metadata">

**Author:** ![magicteddy](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@magicteddy](https://discourse.mcneel.com/u/magicteddy)\
**Post date:** [March 27, 2023, 4:09pm UTC](https://discourse.mcneel.com/t/how-to-sort-two-list-of-points/157193/2 "2023-03-27T16:09:04Z")

</div>

Here is a solution that features a considerable amount of workarounds…

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/3/3/1/331f524d167cca5ab170f584085c1e992abba00c.jpeg)

First, your outer points contain duplicates. I removed them by culling duplicate average points.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/0/7/a/07a975b35ddfbfb6396a9f59aeb37aa3258c5737.png)

Then, ordering inner and outer points counterclockwise in YZ.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/1/0/f/10f0a046aba1c7efc95216bf335f76ad487daf06.png)

For the inner points, the trick is to add 4 “fake” branches to the tree containing a single point that will take the place of the missing group (because you only have, on purpose I suppose, 8 groups in the center).

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/e/4/a/e4aceb02140ed3ffc5c6ded77ede8d8ca92db496.png)

The points end up sorted.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/6/2/1/621578a3c84b8ff67c02dbc5246e0b6c6decc465.jpeg)

Finally, remove “fake” branches from the inner tree, and retrieve branches {i+1} and {i-1} because these are indeed the target points. This requires to mod 12. Hooray, you can build the lines.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/2/a/1/2a15013fbb3d362e5a231a8e293347c180be4b67.png)

And the points are not even in order inside the branches, but I’ll leave that to you !

[Connecting points.gh](https://discourse.mcneel.com/uploads/short-url/5DZ7AHxwNp0hBvaSiMeI8gyWCtd.gh) (18.8 KB)

---

<div class="post-metadata">

**Author:** ![Lazan](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/lazan/32/485012_2.png) [@Lazan](https://discourse.mcneel.com/u/Lazan)\
**Post date:** [March 27, 2023, 9:44pm UTC](https://discourse.mcneel.com/t/how-to-sort-two-list-of-points/157193/3 "2023-03-27T21:44:10Z")

</div>

Very informative and helpful, thank you.
