Plotting elliptical orbits

前端 未结 2 766
青春惊慌失措
青春惊慌失措 2021-01-13 13:47

I\'m trying to write a code that plots the elliptical paths of an object using the equation for the ellipse r=a(1-e^2)/(1+e*cos(theta)). I\'d also like this data to be put

2条回答
  •  灰色年华
    2021-01-13 14:38

    I think you need to do points.append([theta,r]) then at the end plt.polar(points) ... that makes a kinda neat design too

    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
    
    points = []
    while theta <= 2*pi:
        r = (a*(1-e**2))/(1+e*cos(theta))
        print("r = ",r,"theta = ",theta)
        points.append((theta, r))
        theta += pi/180
    #plt.polar(points) #this is cool but probably not what you want
    plt.polar(*zip(*points))
    plt.show()
    

提交回复
热议问题