algorithmic modeling for Rhino
I'm working on a project with Kinect and Grasshopper(with Quokka) and I need to recognize with the kinect a series of (more or less) vertical sticks. My question is: how can I separate the points of my overall point clouds in two lists in order to create two separate geometry(see attached images)? Of course the idea is not to select them manually but find a way to dispatch the point automatically. I don't think sorting by coordinates would be helpful because the system I'm going to scan could be quite intricate sometime. Thank you!
your samples are "separated" thus sorting them appears "doable" (for instance using LINQ):
var sorted = ptsList.OrderBy(p => p.Z).ThenBy(p => p.Y).ThenBy(p => p.X).ToList();
if by "intricate" you mean that the 2 "domains"/clouds share "common" x,y.z coordinates ... sorting the points appears impossible unless there's some other rule/condition that we could take into consideration
Thanks for the reply peter! What I havein mind is more like: take a point and check its distance with all the other points, if the distance value is less than a fixed value, copy all the points with that distance from the point in one new list. Unfortunately I still having some trouble implement this, so if anyone has some idea is welcome. Thanks!
...some trouble implement this...
What do you mean by that? Strictly speaking that's very easy (but if I'll do it for you I'll do it using solely C#, not GH components) : anyway, post some test "isolated" pts dataset(s) and we'll see what could be done.
On the other hand, if the pts Lists "overlap" ... doing pThis.DistanceTo(pOther) ... I hardy can see how we can distinguish apples from apples.
I mean if I pick a point at the top of the stick is closer to another point on the top of the other stick rather than a poin on its bottom. I've attached the rhino file with the pointcloud I'm working with, thank you.
But this is elementary my dear Watson :
1. Points are already in "order" (no need for sort).
2. Point "sets" are not overlapping each other.
So ... case "resolved" (in fact ... far from it but let's pretend that, for the moment)
PS: Points are internalized (but GH can't memorize a thing or two in most of cases)
hmm ... what I was thinking? (blame too many cigars).
There's this handy little GH component called GroupPoints. It sorts points into separate lists according to a maximum distance within the group.
see attached file.
Thank Peter and Hannes, both your solutions work perfectly.
I've been keep working on the sorting pointcloud definition and it works pretty good until two sticks do not overalp with each other, when they do it recognizes a line(which is the average of the two sticks) instead of two crossing ones. I was wondering if there's a way to solve this issue. For my purpose the single stick does not need to be composed by a single polyline, could be segmented in more lines but still, if two are crossing, they need to stay separate until the point they actually cross each other. Thank you!