0

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

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.")

我需要完全重写代码吗?此外,作为后续行动,我已经能够实现一种算法,使圆盘稍微移动,然后在它们靠得更近时接受或拒绝移动。椭圆有点不同,因为我需要旋转它们。我该怎么做?

4

0 回答 0