shortest path between 2 set of coordinates
Show older comments
I have 2 set of coordinates --> set_1 and destination
If i select a cordinate in set_1 and destination (eg: from set_1 [10.5, 4.5] and from destination [2.5, 8.5]
I need to reach destination coordinates [2.5, 8.5] only through the coordinates in set_1 , also through the shortest path
I need to show the movement from [10.5, 4.5] to [2.5, 8.5] in graph
set_1 =
[7.5,6.5;7.5,7.5;4.5,8.5;7.5,6.5;8.5,6.5;9.5,6.5;9.5,5.5;8.5,1.5;7.5,4.5;6.5,4.5;3.5,5.5;2.5,6.5;10.5,4.5]
destination =
[7.5,9.5;8.5,10.5;2.5,8.5;8.5,10.5;6.5,9.5;6.5,2.5;5.5,3.5;5.5,3.5;1.5,1.5;3.5,3.5]
9 Comments
Adam Danz
on 25 Mar 2019
Are you trying to draw a line between two chosen coordinates?
Elysi Cochin
on 25 Mar 2019
Adam Danz
on 25 Mar 2019
Still not clear. The figure below shows your set_1 data in blue (assuming col 1 is x and col 2 is y) and your destination data in red (same x,y assumption). From what I understand, you want to choose any coordinate along the blue line and any coordinate along the red line and connect them with a new straight line. Is that correct?

Image Analyst
on 25 Mar 2019
Elysi you say "I need to reach destination coordinates [2.5, 8.5] only through the coordinates in set_1" but what if the destination coordinate (a point on Adam's red line) is not on the set_1 (blue) line? It can't be done in that case. In fact you can see that your (2.5, 8.5) point is not even in your set_1 at all.
Adam Danz
on 25 Mar 2019
I see. So you want the choose a coordinate that belongs to the blue line and travel along the blue line until you're as close as possible to the target coordinate along the red line.
Elysi Cochin
on 25 Mar 2019
Adam Danz
on 25 Mar 2019
Does this example also fit your rules?

Adam Danz
on 25 Mar 2019
I don't have time to fiddle with this interesting question now but here's what the solution will likely involve. You can get started with it and if no one else provides a solution and you get stuck, follow up here with questions.
- use pdist() to calculate the distance between all points along the blue line and the target red-point. Then use min() to determine which blue point is closest to the red point.
- Now you have the index value of the blue point where you're starting and the index value of the blue point where you're ending - all points in between will be your path of least resistance. Then you just need to add the final red point coordinate.
Adam Danz
on 25 Mar 2019
I continued in the answer section below.
Accepted Answer
More Answers (1)
sam mertens
on 9 Jul 2019
0 votes
Hi, How to find the shortest path in the exact scenario?
Categories
Find more on Motion Planning in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!