Grasshopper

algorithmic modeling for Rhino

Sorting Points from 2 Lists based on their vicinity

I am trying to sort Points from 2 Lists based on their vicinity. I came across an older solution from David, but it is not working in my case. I have tried everything I came across but can not figure it out. I was wondering if someone had a solution for this problem

Views: 2287

Attachments:

Replies to This Discussion

ok I tried some C# code but it seems to have issues as if the IsPointInside is not working right... see attached code

Attachments:

Wait a minute:

Do you want in fact to create some sort of pair prox connections ? (from a given pt in List1 connect to the closest in List2).

Or (alter ego) sample in a DataTree these pairs etc etc.

Used the fastest way ... notify if you want lot's of slower ones (LINQ and the likes).

see attached

Attachments:

Hi Peter... thanx for looking into my problem - have come across your solutions for others before - Kudos... You are right that I want to pair the points closest to one another. I used your solution and attempted to sort the points based on the lines drawn between them, but they are still not the same... I tried to use the spheres and IsPointInside because what happens if more then 1 line have the same lenght?

 

Thank you,

Oliver

Attachments:

Er ...

First things first:

1. If you want to sort the master List1 (or the other) ... well you should FIRST sort the List:

Due to the topology I would strongly suggest some "radial" (so to speak) sort using the "centroid" (ditto) point from List1 as the apex point for the vector angle calculations (with regard some user defined ref Vector and plane).

Notify if you want a Function that does that ... or describe what "sort" means to you.

2 Then do the prox pairs sampling.

thanx Peter...

That's why I thought using sphere is the way to go.

with sorting I mean I need the point pairs to have the same index within a list.

I have 176 spheres each containing 2 points. These 2 points are from 2 lists - one from each - the 2 points do not have the same index in their lists. 

I take a sphere check against all points from list 1 to see if it is inside. If yes I stick it into a new list1.

I take the same spheres check against all points from list 2 to see if it is inside. If yes I stick in to a new list2.

these 2 list should now have the point pairs having the same index - right???

List<Point3d> sortedPoints = new List<Point3d>();
List<Brep> brepList = new List<Brep>();
foreach (var sphere in spheres)
{
foreach (var point in points)
{
if (sphere.IsPointInside(point, 0, true))
{
sortedPoints.Add(point);
brepList.Add(sphere);
}
}

}

Well ... don't panic: it's VERY simple:

Leaving sorting List1 aside (Easy: I'll prepare "some" ways ASAP) IF we sample (during the pair matching loop) the current point AND the prox point into a DataTree (with specific order: first the current , then the prox) ... AND THEN split the Tree into 2 ... well the Columbus egg or what?

Of course instead we could sample (during the pair matching loop) the current into a newList1 and the prox into a newList2 and have the very same effect: pairs with THE SAME indices. But a DataTree is more "mysterious" ... therefore preferable, he he (what about having more Lists in mind?: "prox" triads/quads and the likes).

elementary my dear Watson.

But the main point here is not that: it's worth examining various prox finding methods (say for a gazillion of points in List1/List2) and locate the fastest: that's a thingy worth the name I confess.

more soon

I concur Sherlock... I was just looking for a down and dirty solution for my problem - which I am trying to solve for 2 days now. I could have just referenced each point by hand - but that would just not be the grasshopper way.... Oliver

Get the index matching thingy (2 Lists would be more elegant I confess, he he) and allow me a couple of minutes to mastermind 4 of the slowest pair matching methods known to man (in the Name of Science, what else?)

I'll be back, Arnie (Terminator 5)

Attachments:

I'm very pleased:

The fastest pair option is ~ 600 times faster than the slowest one (ideal for the Jack Daniels distillery man).

A clear prove that Science is a bad thing.

Of course the connections are so small that nobody can see them ... a fact that makes the whole thingy ultra LOL

Attachments:

And since progress (kinda) never stops: i.e. more nonsense that supposedly are great (kinda) things ... get the v4 that does LOL and/or ultraLOL stuff as well == progress (kinda).

Radial sort + ultraLOL = true.

No sort +  ultraLOL = true.

Roll the bones +  ultraLOL = false.:

Moral: LOL

Attachments:

And since you flirt with the Dark Side (the only side, mind) ... I've added some small challenge for your C# adventures:

modify the first thingy, make 2 squeezed eggs, trim them (or not), populate them with random points ... and then do the sort, the pairing or ... er ....  some other more proper stuff (if waves are around to catch). 

May The Force (the dark option) be with you

Attachments:

I made small changes to your code and got exactly what I needed... I owe you a cold one... thank you thank you and did i mention thank you

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service