Sort points from a jumbled point order to form a polyline

Hello Guys, I’ve been trying to form a polyline from a jumbled point data

Below you can find the present order where each have their own set of tree’s individual point data

Here’s what i expect to let the polyline component recognise the order to form a curve

Any ways to get a neat point order to use that to form a polyline

Attached .gh script FYR

Any help is greatly appreciated!!

POINT_ORDER_TO_FORM_POLYLINES_DOUBT_FORUM_GH.gh (43.8 KB)

https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.point3d/sortandcullpointlist

Hi Tom, can I ask how is Rhino.API docs fit to a Grasshopper script question, can we actually use this?, if so would you care to explain?

Many thanks!



POINT_ORDER_TO_FORM_POLYLINES_DOUBT_FORUM_EW.gh (44.9 KB)

I selected a set of two of the surfaces you are working on.
(this because you merged many branches, where the underlying tree connection, I was not able, to trace back)
By selecting just two surfaces (and you will know how to select the many sets of two surfaces in your drawing), I made a “fresh start” .

Region Difference gives you the polyline you want. (with nicely sorted points. )
If the specifice starting point has to be moved:

  • explode the polyline
  • shift the vertices (shift list + slider) to where you want to start.
  • build polyline from resorted vertices.

Regards, Eef

The tree were clean, I didnt organise the script to have them visible to reviewers

I traded compute for having a quick solution here, used the ‘Solid difference‘ component here

But would like to know how to sort points before forming a surface than to form a surface and then get a clean point list

Thanks for your help here, Eef

Most quick solutions run into dead-ends.
Probably most fast to

  1. Create your grid
  2. Create one panel with all variations you want.
  3. Orient this one panel to all the points (planes) in your grid).

Everytime you use Flatten or Simplify, you loose tree branch informationen.
Looking at the result at “Merge” (just before where you want the points sorted), there is no way ( at least I did not see it) how to know what branches with points will form you polyline together.
So if you want to get the line from points (not from surfaces), you take care all tree-info is kept.

There are ways, to sort the points along a curve (to get them in a order)
or sort on distance to centre of group of points (to get the outer and inner groups)
and you have to find a way to connect the groups again.

Another approach is to get x, y and z values, and sort with them.

Give it a try and you will see that is a lot of work.

What I showed with the surfaces, works very fast and clear.
The other option is, that rebuild the whole thing and keep track of the place of every point in the datatree, so you can just pick them straight from there.

But as almost always there are other smart people on this forum who have better the solutions, maybe they will give them. Regards, Eef

1 Like

@Eef_Weenink ‘s diagnosis looks correct to me. This is a symptom of an over-complicated underlying generation. Lots of making geometry, moving it, intersecting it, offsetting it, exploding it etc. A good recipe for a messy tree structure and the resulting “aaargh, looks like I have to flatten to make it work!”

When dealing with simple rectilinear profies like this, I prefer the “calculate all X and Y values then Merge them in vertex order” method. No geometric operations required. You do have to take a little care to make sure everything has the same tree structure. For example I multiply the “widths” tree by zero to get an indentical tree structure with a zero at each leaf.

Rather than untangle and transplant into your script, I have made a new polyline generator from scratch, which takes three inputs: the rectangular surfaces and two dimensions for the border offsets. This generates all the polylines on the XY plane at 0,0 then uses Map to Surface to transform them into place on the facade.

If this needs some other kind of shape, then I hope you can see how easy it would be to do different maths and assemble the vertices in some other order.

simpler border generator.gh (31.0 KB)

1 Like