Testing Waters

Search…

Projects

Patterns

Geometry

Lists

Consecutive Points

Closest subsequent point in sequence

closestPointsSequence.zip

3KB

Binary

Dynamo 2.9

1

def ClosestPointsSequence (stPt, pnts:var[]..[])

2

{

3

return = [Imperative]

4

{

5

cnt1 = List.Count (pnts);

6

pnt1 = pnts;

7

pnt2 = [stPt];

8

9

while (List.Count(pnt2)<cnt1)

10

{

11

pnt3 = List.SetDifference(pnt1,pnt2);

12

pnt4 = List.LastItem(pnt2);

13

dis1 = pnt4.DistanceTo(pnt3);

14

pnt5 = List.SortByKey(pnt3,dis1)["sorted list"];

15

pnt1 = List.RestOfItems(pnt5);

16

pnt2 = List.AddItemToEnd(List.FirstItem(pnt5),pnt2);

17

}

18

19

return pnt2;

20

}

21

};

Copied!

This can be extended to obtain the shortest path connecting a list of points by obtaining sequences with all possible start points and then calculating the length of the connecting poly line

shortestPathConnectingPoints.zip

3KB

Binary

Dynamo 2.9

Last modified 1yr ago

Copy link