I would like to know if there is a possible way to join these curves, which have self-intersections in some places, to get a single curve, without changing the overall shape of it (I was wondering if there is a possible way to do this by merging the overlapping curves and then using the ‘join with tolerance’ component of WonbatGH, but I was only able to implement the second step of this idea. I have already tried exploding the curve, divide it, selecting the duplicate points and sorting the points to interpolate it; I have also tried to make a concave polygon and getting the bounds of that, i.e. using Delaunay triangulation, but it returns a convex polygon. So, nothing worked.
which find themselves in the middle of the curve. These curves essentially backtrack on themselves in an attempt to make themselves closed polylines. Then some of these lines don’t even backtrack correctly:
That makes sense, because in trying to create a script, that was my main problem. I couldn’t find a way to ascertain them. Once you have the endpoints, you can iteratively find the nearest neighbour vertex from the startpoint to create a new polyline.
Unfortunately, as you can see, the next nearest neighbour sometimes isn’t the next adjacent point in the polyline, but a point from another nearby section of of the polyline. I suppose you could solve this by artificially injecting extra points into the point collection. Is there a way to do this without Anemone (or another plug-in)?
thas is the exact reason why I thought using Graphs
by creating the Graph Nodes from the Vertexes of each polyline and using some sort of shortest path algorithm, the search happens along the Graph Edges, so it avoids finding a closest point that is not already connected to the current Point with an existing Edge
in alternative it might be worth creating a second loop here:
and this loop would just go through a list of n closest points (instead of just one) and it would stop if and only if the current closest point being examined is somehow connected to the previous one by a Line
I believe the final output of that would not necessarily be the Shortest Path (which is not a requirement by the way… as much as mine isn’t either because it’s just the final path with less amount of nodes used)
I don’t fully understand this. Is Graph Nodes a component? I am imagining a nearest neighbour graph, something like what Delaunay Edges creates, but even this does not create lines soley within the figure.
Yes. This would be a good idea if the geometry wasn’t such garbage. Because the “closed” polylines stray off from the open polyline figure in their back-tracking, it might be that the next vertex doesn’t lie on a line between the current and next vertex.
yes, a Graph is a representation of relations using just Nodes and Edges (eventually with a Weight, eventually with a Direction)
in my example the graph did not have any weight assigned (equal to all Edges have equal weight…) but for instance we could have said that each edge has weight equal to the length of the curve they represent
in this case we have polylines, so each vertex of each polyline becomes a Node (overlapping points gets merged into a single Node) and each line connecting 2 nodes becomes an Edge of the Graph
by doing so, each polyline that would represent a single path connecting a different number of points would merge into a whole intricate map of connected points
if you can only move along edges of a graph, it means that you can only move along lines of the original Polylines: if the search of a given neighbor point is forced to happen along an graph edge the connects the node where you are to another node, it means that there is a connection between the two (so there is also a portion of polyline in your original data that originated that edge in first place)
by doing so, because you can only move between connected points, it could never happen that the search suddenly changes lane like here: there was no portion of Polyline ever connecting those two points, so a graph-edge was not generated between them, and the search of neighbors could only happen along connected edges so there would be no search for that point on the other side
that would be a problem if and only if a polyline would be completely disconnected from the others, meaning that at a certain point of the search there would be islands of Nodes that were completely disconnected from the rest (so there would be no edges that lead to those)
and that would happen if there were no common polyline vertexes, like this:
maybe a further step might be to find all the intersections/self-intersections of and between any polyline, and graph those: in that way -unless polylines would be physically disconnected, like “unbridged” from each other- you could still find a solution to the problem
on a second thought, that would not be such a problem I guess, because you are not really interested in the flow/order of Lines… you are only interested in knowing if eventually a Line exist between current point “A” and candidate closest point “B”: in order for “B” to be promoted from “candidate” to “destination” point, there must be at least a single Line from any initial polyline connecting it to “A”
@inno thank you for your reply. Yes, I was thinking to use A* Algorithm as well, to iterate through the dividing points of curves, but I know almost nothing about graph theory (I need to research about it)
@Volker_Rakow thank you for you reply. This came from a shapefile from a GIS platform, and yes, it is a very bad curve, unfortunately. Actually, I also have several other curves like that, and this is just one of them. In my option, if I could, I would just create that line manually, but that is not straightforward with dozens of curves like this.
@Erik_Beeren thank you for your reply. Yes, this can be used!
That generated good discussion, so thanks to you guys for the knowledge implemented here (I couldn’t figure out indeed)!
Ahhh… see. I had zoomed in, seen messy geometry, and assumed the above would be the case – that all the guardrails were off. Creating a graph doesn’t work unless polyline segments are split at curve intersections and won’t work at all of the polylines are disjoint. And so, I thought of trying nearest neighbour to be able to jump polylines. Not that I would have thought of a graph in the first place. Thank you for the explanation.
Out of interest, how does a graph look like when it is stored in a list in Grasshopper?