Distance formula between two points in a list

前端 未结 7 1732
刺人心
刺人心 2021-01-31 19:39

I need to take a list I have created and find the closest two points and print them out. How can I go about comparing each point in the list?

There isn\'t any need to pl

相关标签:
7条回答
  • 2021-01-31 20:13

    Note that the math.sqrt function is both slow and, in this case, unnecessary. Try comparing the distance squared to speed it up (sorting distances vs. distance squared will always produce the same ordering):

    def distSquared(p0, p1):
        return (p0[0] - p1[0])**2 + (p0[1] - p1[1])**2
    
    0 讨论(0)
提交回复
热议问题