从一系列的数字中创建一个“编队”

2024-03-28 15:04:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我想创建一个'形成'为我的博伊兹遵循,但可以有任何数量的博伊兹在形成。我想要一个圆形的队形。那么,我如何通过构造中的boid数,并在那里操纵(x,y),使它们填充成一个圆形呢

我有:self.flock_formation = [] under class Flock.__init__ and self.pos(math3d.VectorN(x,y) under class Boid.__init__

这是在课堂上:

def create_formation(self):
    for boid in range(0, len(self.boids)):
        spot = math3d.VectorN(x, y)
        self.flock_formation.append(spot)

我很难理解我可能需要做些什么来找出一个圈中的位置,这个圈的大小相当于群中的boid数量。任何想法或示例代码都会有所帮助,谢谢


Tags: andself数量init圆形classunderflock
1条回答
网友
1楼 · 发布于 2024-03-28 15:04:37

你需要为你的圆选择一个半径。这里有一个算法

import math

for pos in range(len(self.boids)):
    angle = 2*math.pi / n
    x = radius * math.sin(angle)
    y = radius * math.cos(angle)

你能从那里拿走吗

相关问题 更多 >