Python Matplotlib:将轨道程序转换为3D

时间:2014-07-11 17:44:21

标签: python matplotlib geometry trigonometry orbital-mechanics

我使用真实物理完成了2D轨道程序,这很酷。我现在要做的一件事就是添加一个" z"方程的力,加速度和速度。我已经这样做了,但现在程序只是围绕垂直线的垂直线:

Planets are apparently vertical lines, unlike previously thought

由于没有用于创建像圆圈这样的球体的代码,我需要使用trig:

以下是代码:

import numpy as np
import matplotlib.pyplot as plt
import math
import matplotlib.animation as animation
import pdb
from mpl_toolkits.mplot3d import Axes3D

er = 6378100*10#m
mr = 1737400*10#m
em = 5.97219*10**24#kg
mm = 7.34767309*10**22#kg
G = 6.67384*10**(-11)
mv = -1023#m/s
nts = 10000
ts = 10000

def simData():
    tmax = ts*nts
    jx = 0.0
    t = 0.0
    d = 384400000
    mx = d
    my = 0
    mz = 0
    vx = 0
    vy = -mv
    vz = 0

    while t < tmax:
        Fg = G*(em*mm)/d**2
        Fgx = -Fg*mx/d
        Fgy = -Fg*my/d
        Fgz = -Fg*mz/d
        mAx = Fgx/mm
        mAy = Fgy/mm
        mAz = Fgz/mm
        vx = vx + mAx*ts
        vy = vy + mAy*ts
        vz = vz + mAz*ts
        mx = mx + vx*ts
        my = my + vy*ts
        mz = mz + vz*ts

        u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]
        x=np.cos(u)*np.sin(v)+mx
        y=np.sin(u)*np.sin(v)+my
        z=np.cos(v)+mz
        ax.plot_wireframe(x, y, z, color="grey")

        d = math.sqrt(mx**2+my**2+mz**2)
        t = t + ts
        yield jx, t

def simPoints(simData):
    jx, t = simData[0], simData[1]
    time_text.set_text(time_template%(t))
    line.set_data(t, jx)
    return line, time_text



fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_aspect("equal")
line, = ax.plot([], [], 'bo', ms=10)

eu, ev = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]
eax=np.cos(eu)*np.sin(ev)
eay=np.sin(eu)*np.sin(ev)
eaz=np.cos(ev)
ax.plot_wireframe(eax, eay, eaz, color="b")

time_template = 'Time = %.1f s'    # prints running simulation time
time_text = ax.text(0.05, 0.9, 0.9,'', transform=ax.transAxes)

ani = animation.FuncAnimation(fig, simPoints, simData, blit=False,\
     interval=10, repeat=True)
plt.show()

我在没有这个程序的情况下测试了制作圈子的三角形并且它有效。另外,有关制作表面球体而不是线框球体的任何建议吗?

0 个答案:

没有答案