plotting a sphere in python for an orbital trajectory

本小妞迷上赌 提交于 2019-12-08 18:35:33

You can add the following code to draw the sphere, before the plt.show():

phi = np.linspace(0, 2 * np.pi, 100)
theta = np.linspace(0, np.pi, 100)
xm = rm * np.outer(np.cos(phi), np.sin(theta)) + r12
ym = rm * np.outer(np.sin(phi), np.sin(theta))
zm = rm * np.outer(np.ones(np.size(phi)), np.cos(theta))
ax.plot_surface(xm, ym, zm)

However, your moon will look all stretched out because the scale is not equal for all axes. In order to change the scales of the axes, you can add something like

ax.auto_scale_xyz([-50000, 400000], [0, 160000], [-130000, 130000])

before plt.show(). The result is still not completely right, but I leave it up to you to play around to get better results -- I just picked some numbers that make it look somewhat better.

All the code for a sphere is here:

http://matplotlib.org/examples/mplot3d/surface3d_demo2.html

From there you just have to shift in whichever direction you want and change the 10 to whatever radius you desire.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!