How to combine a number of coordinates with one continuous line?

12 views (last 30 days)
Hi all,
I was wondering whether there exists a solution/algorithm for my problem: I have a large number of coordinates, e.g. nodes, that I want to automatically link with one continuous line. The problems are my restrictions:
  1. Each node must only be covered once
  2. The lines must not overlap with other lines or coordinates
  3. There's a maximum length for the lines
  4. I want to feed in arbitrary structures
Are there any ideas on how I could solve this issue? Shown are some examples for the rules, they don't cover all of them though.
Thanks a lot in advance! Jay
  6 Comments
Image Analyst
Image Analyst on 15 Apr 2017
Esteban - that's ambiguous. Do you mean you have the problem where you have a square grid and diagonal lines are not allowed? Or do you mean that you have the grid problem but the lines are diagonal, like with diamond-shaped cells instead of square shaped cells? Please post a diagram in your own new question.
João Rosas
João Rosas on 24 Mar 2018
hi! i have that same problem, can you please give me the code? i don't know how to code :(

Sign in to comment.

Answers (3)

Image Analyst
Image Analyst on 21 Jun 2015
Well, the easy one is step #3. Use pdist() (In the stats toolbox) to find distance from every point to every other point. Then take the max of that. If that max distance is more than your max allowable line length, then there is no solution.
Assuming it passes that test, then there could be multiple solutions. Imagine a rectangular grid. There are tons of ways you could draw a single line connecting them all: raster up/down, raster left right, raster diagonally, spiral inwards, spiral outwards, etc.
Is any solution okay? Or do you need the shortest path, like the famous "Traveling Salesman Problem"? Do you have any specified starting and ending points? Or can you start and stop on any point, and you need to find the endpoints that give you the shortest total path length?
  4 Comments
Walter Roberson
Walter Roberson on 26 Mar 2018
The problem has not yet been clearly enough defined to code.
If the selected locations form a grid or subset of a grid, then the task becomes easier to set up.
A key question is whether any of the Hamiltonian paths are acceptable, or if the shortest such path is required. The shortest such path takes a lot more work.

Sign in to comment.


Image Analyst
Image Analyst on 21 Jun 2015
There are a number of ways to attach the traveling salesman problem. See the Mathworks suggestions: http://www.mathworks.com/search/site_search.html?q=traveling+salesman&term=traveling+salesman&c[]=entire_site_en

Walter Roberson
Walter Roberson on 21 Jun 2015
Edited: Walter Roberson on 22 Jun 2015
This is mostly just a traveling salesman problem with just not adding in edges that are too long. The only thing that is not normal is checking that the lines do not cross: typically they do not cross (because uncrossing them would usually lower the energy.) If the example you show, if you only provide vertices to the nodes that are adjacent horizontally and vertically then you cannot end up with a crossing line.
  2 Comments
Jay Muller
Jay Muller on 21 Jun 2015
Thank you both very much. I'll have a closer look into the TSP, as you say, maybe I "just" need to modify the algorithm a bit, e.g. by deleting unwanted lines.
Walter Roberson
Walter Roberson on 22 Jun 2015
If you have a grid like you show in the examples, you cannot end up with unwanted lines provided you only populate edges between nodes that are horizontally or vertically connected. If the nodes are not on a regular grid then there could potentially be circumstances under which the edges crossed with a path that was otherwise valid.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!