Last active
March 22, 2019 08:45
-
-
Save jhorikawa/1b5f48917d0670679c8c9d7cb03aeddb to your computer and use it in GitHub Desktop.
Pack objects by objects' distance in Grasshopper. (C#)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void RunScript(List<Point3d> pts, List<object> objs, double thresh, ref object A, ref object B) | |
{ | |
DataTree<object> tree = new DataTree<object>(); | |
List<int> usedList = new List<int>(); | |
List<Point3d> centers = new List<Point3d>(); | |
for(int i = 0; i < pts.Count; i++){ | |
var pt1 = pts[i]; | |
if(!usedList.Contains(i)){ | |
GH_Path path = new GH_Path(i); | |
tree.Add(objs[i], path); | |
centers.Add(pts[i]); | |
for(int n = 0; n < pts.Count; n++){ | |
if(i != n){ | |
if(!usedList.Contains(n)){ | |
var pt2 = pts[n]; | |
double dist = pt1.DistanceTo(pt2); | |
if(dist < thresh){ | |
tree.Add(objs[n], path); | |
usedList.Add(n); | |
} | |
} | |
} | |
} | |
usedList.Add(i); | |
} | |
} | |
A = tree; | |
B = centers; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment