Algorithm for calculating the path between two points in JPanel in Java Swing

First of all, I don't want an algorithm like a *, Dijkstra, because this algorithm can calculate the best and shortest method I have two points in JPanel, and I have to connect them with a cable of a point array The only directions allowed are up, down, left and right, and the cable must have a minimum number of direction changes This is the most important requirement. Of course, the algorithm does not calculate the shortest path What shall I do? Is there a similar algorithm?

thank you!

Solution

I think you should take another look at the traditional shortest path algorithm The weight associated with the edge does not need to be related to the physical distance

Build a graph in which the potential corner is the vertex, and each line between the vertices connects the edge, and the weight of each edge is 1.5 The path you want is the "shortest" path through the chart

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>