在python中创建和旋转椭圆,同时检查碰撞

时间:2013-04-12 00:42:59

标签: python packing collision

我设法创建了一些代码来创建各种光盘并检查冲突,但是我将如何为椭圆做呢?

height = 100
width= 100
circles = 15
radius = 4
xL = []
yL = []
count = 0
print("Placing ", circles, "circles on a" , width,\
      "x", height, "grid...")
for j in range(circles):
    x = randint(0,width-1)
    y = randint(0,height-1)
    if len(xList)>0:
        for i in range(len(xL)):
            distance = sqrt((xL[i] - x)**2 + (yL[i] - y)**2)
            if (distance < radius*2):
              print("Circle ", j, "collides with circle ", i)
              count += 1                  
    xL.append(x)
    yL.append(y)
print("Complete.", count, "collisions.")

我是否需要完全重写代码? 另外,作为一个后续工作,我已经能够实现一种算法,可以稍微移动光盘,然后接受或拒绝移动,如果他们走得更近。椭圆有点不同,因为我需要旋转它们。我该怎么办?

0 个答案:

没有答案