Shortest distance between points algorithm

前端 未结 7 2018
独厮守ぢ
独厮守ぢ 2020-11-29 03:47

Given a set of points on a plane, find the shortest line segment formed by any two of these points.

How can I do that? The trivial way is obviously to calcu

7条回答
  •  有刺的猬
    2020-11-29 04:12

    I can't immediately think of a quicker alternative than the brute force technique (although there must be plenty) but whatever algorithm you choose don't calculate the distance between each point. If you need to compare distances just compare the squares of the distances to avoid the expensive and entirely redundant square root.

提交回复
热议问题