Boids in python; calculating distance between two boids

♀尐吖头ヾ 提交于 2019-12-07 00:24:25

The problems are:

  • You are not passing in any boid data into your function, just the indices element_1 and element_2. So calculate_distance does not know anything about the boids.
  • Even if you were passing in boid data you are assigning empty lists to a and b , which means the inside of your loop is never executed.

You want something like:

for element_1 in range(len(boids)):
    for element_2 in range(len(boids)):
        distance = calculate_distance(boids[element_1],boids[element_2])

and then

def calculate_distance(a,b):
    return sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!