2017-07-07 83 views
0

因此,我試圖模擬地球在太陽周圍的行駛,其中地球的速度由其在原點和水平面的角度決定。我通過創建一個函數使用三角形的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 

非常感謝一些幫助, 乾杯

+0

這並不回答你的問題,但我認爲,而不是'O_correction',你可以使用['atan2'](https://docs.python.org/2/library/math.html#math.atan2)而不是'atan'。 – jadhachem

回答

0

我不知道蟒蛇,但我知道物理學。

在每個步驟中,您將地球沿着軌道移動一個固定距離,沿切線而不是軌道本身。這給了你一個外在的螺旋(當你外出時,它實際上會變得更不嚴重)。

嘗試使時間增量更小(例如通過將位置調整除以100),並且螺旋效果將變得更小。

如果你想做得比這更好,你需要一個不同的公式。你可以強加一個圓形軌道,或者做一些基於保守量(這需要對基本物理學有相當的瞭解)。

+0

是的,這是有道理的,我沒有考慮增量之間的時間。謝謝 – ojj920