Shortest route between multiple points

前端 未结 4 674
悲哀的现实
悲哀的现实 2021-01-29 11:46

I need to find the shortest route between multipe points. Let\'s say that I have these four points:

var startPoint = new Point(1, 1);
var pointsToGoPast = new Li         


        
4条回答
  •  死守一世寂寞
    2021-01-29 12:28

    You can do this by Dijkstra's Algorithm.

    Sample project with code here

    The only thing that needs to change is the weights in the project, since the weight is based off of distance between the two points. (So you need to modify the Location to store a Point and the Connection to calculate the weight (distance) in the constructor.

    Wikipedia has a very nice article on the algorithm

提交回复
热议问题