walking an undirected cyclic graph with minimal jumps #1091
Replies: 4 comments 3 replies
-
I'd personally try turning the JTS linework into a JGraphT graph, then look at the various graph traversal methods, etc, offered by that library. |
Beta Was this translation helpful? Give feedback.
-
I tried printing the memory address of every Coordinate as it was added to the graph and then again as the graph is queried for LineStrings.
line 492529533 to 59245685 was never added to the mix, so IDK how it appears in the graph. Both Coordinates were added...but not in that combination. |
Beta Was this translation helpful? Give feedback.
-
So... I'm definitely going about it the wrong way. I see that LineMerger won't find intersections and add nodes. It also can't detect duplicate coordinates at the same location. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hello! I hope you are well. I'm having a funny result and hoping one of you big brains can ELI5 to me. Apologies if this is not strictly a JTS question.. I don't know a better place to ask.
I'm using JTS in Makelangelo Software. Recently someone asked if this plotter software could be made to work for sand plotters. The biggest challenge I see right away is that the plotter can't jump from one place to another. Since I already have my JTS hammer I thought I'd use it to hit this nail. JTS should be perfect for finding intersections and building graphs, right?
The eventual goal is to walk a graph of connections with a stack to remember if I have unvisited neighbors in the past. if i hit a dead end and there are zero unvisited neighbors in the stack, stop. else, retrace the line until I get to the unvisited and explore that branch. I understand that there may be "islands" that are unreachable without a jump - the goal is only to minimize jumps by any means available.
Here's my input line set:

First I swizzle my lines into JTS and get the merged line set. I ran a test to draw all merged lines in alternating colors, which looked OK.
Then I build a graph of the start and end of each line. Note that every line is added at least twice.
I use
getCoordinateSequence()
to avoid allocating new instances AND I want to match by memory address. For example:To test the graph, I tried to draw every connection. Here's where I got my mystery.
Despite the fact that every LineString is in mergedLines and therefore MUST be in the graph, some LineStrings are never reached.
....how?! 🫠 Any hints or advice are greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions