绘制椭圆轨道

2024-05-29 11:44:55 发布

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

我试着用椭圆r=a(1-e^2)/(1+e*cos(theta))的方程来写一个绘制物体椭圆路径的代码。我还希望将这些数据放入数组中以供其他使用。

from numpy import *#Imports Python mathematical functions library
import matplotlib.pyplot as plt #Imports plot library
from pylab import *

a = 5
e = 0.3
theta = 0
while theta <= 2*pi:
    r = (a*(1-e**2))/(1+e*cos(theta))
    print("r = ",r,"theta = ",theta)
    plt.polar(theta, r)
    theta += pi/180

plt.show()

代码为r和θ输出正确的值,但绘图为空。“极轴打印”窗口出现,但没有打印任何内容。

请帮忙。提前谢谢。


Tags: 数据代码fromimport路径librarypi绘制

热门问题