Algorithm to find two points furthest away from each other

前端 未结 9 1318
闹比i
闹比i 2020-12-13 06:23

Im looking for an algorithm to be used in a racing game Im making. The map/level/track is randomly generated so I need to find two locations, start and goal, that makes use

9条回答
  •  囚心锁ツ
    2020-12-13 07:19

    If your objects (points) do not move frequently you can perform such a calculation in a much shorter than O(n^3) time.

    All you need is to break the space into large grids and pre-calculate the inter-grid distance. Then selecting point pairs that occupy most distant grids is a matter of simple table lookup. In the average case you will need to pair-wise check only a small set of objects.

    This solution works if the distance metrics are continuous. Thus if, for example there are many barriers in the map (as in mazes), this method might fail.

提交回复
热议问题