所以我试图模拟地球绕太阳运行,地球的速度取决于它与原点和水平面的角度。我通过创建一个对三角形使用 tanh(相反/相邻)规则的函数来做到这一点,O_correction(x,y)
. 问题是它不是一个圆形轨道而是螺旋出来,我不知道为什么。
scene = canvas()
scene.background = color.white
O = 0
ball = sphere(pos=vector(10,0,0), radius=0.1, color=color.blue)
x = ball.pos.x
y = ball.pos.y
def O_correction(x,y):
O = math.atan((((y)**2)**0.5)/(((x)**2)**0.5))
answer = O
if x >= 0 and y >= 0:
answer = O
if x < 0 and y >= 0:
answer = pi - O
if x <= 0 and y < 0:
answer = O + pi
if x > 0 and y < 0:
answer =pi*2 - O
return answer
t =0
while t < 100:
x = ball.pos.x
y = ball.pos.y
print = (float(O_correction(x,y))
print = ((x**2) + (y**2))**0.5)
ball.pos.x -= sin(O_correction(x,y))
ball.pos.y += cos(O_correction(x,y))
print(" ")
t += 1
非常感谢一些帮助,干杯