vpython中的椭圆轨道

vpython中的椭圆轨道,python,python-3.x,vpython,Python,Python 3.x,Vpython,我有以下代码。该代码是对围绕其他物体(如太阳系)运行的物体的模拟。运行时,对象将以圆形轨道运行 import math from vpython import * lamp = local_light(pos=vector(0,0,0), color=color.yellow) # Data in units according to the International System of Units G = 6.67 * math.pow(10,-11) # Mass of the Eart

我有以下代码。该代码是对围绕其他物体(如太阳系)运行的物体的模拟。运行时,对象将以圆形轨道运行

import math
from vpython import *
lamp = local_light(pos=vector(0,0,0), color=color.yellow)
# Data in units according to the International System of Units
G = 6.67 * math.pow(10,-11)

# Mass of the Earth
ME = 5.973 * math.pow(10,24)
# Mass of the Moon
MM = 7.347 * math.pow(10,22)
# Mass of the Mars
MMa = 6.39 * math.pow(10,23)
# Mass of the Sun
MS = 1.989 * math.pow(10,30)
# Radius Earth-Moon
REM = 384400000
# Radius Sun-Earth
RSE = 149600000000
RMS = 227900000000
# Force Earth-Moon
FEM = G*(ME*MM)/math.pow(REM,2)
# Force Earth-Sun
FES = G*(MS*ME)/math.pow(RSE,2)
# Force Mars-Sun
FEMa = G*(MMa*MS)/math.pow(RMS,2)

# Angular velocity of the Moon with respect to the Earth (rad/s)
wM = math.sqrt(FEM/(MM * REM))
# Velocity v of the Moon (m/s)
vM = wM * REM
print("Angular velocity of the Moon with respect to the Earth: ",wM," rad/s")
print("Velocity v of the Moon: ",vM/1000," km/s")

# Angular velocity of the Earth with respect to the Sun(rad/s)
wE = math.sqrt(FES/(ME * RSE))
# Angular velocity of the Mars with respect to the Sun(rad/s)
wMa = math.sqrt(FEMa/(MMa * RMS))

# Velocity v of the Earth (m/s)
vE = wE * RSE
# Velocity v of the Earth (m/s)
vMa = wMa * RMS
print("Angular velocity of the Earth with respect to the Sun: ",wE," rad/s")
print("Velocity v of the Earth: ",vE/1000," km/s")


# Initial angular position
theta0 = 0

# Position at each time
def positionMoon(t):                                     
    theta = theta0 + wM * t
    return theta

def positionMars(t):                                     
    theta = theta0 + wMa * t
    return theta

def positionEarth(t):
    theta = theta0 + wE * t
    return theta


def fromDaysToS(d):
    s = d*24*60*60
    return s

def fromStoDays(s):
    d = s/60/60/24
    return d

def fromDaysToh(d):
    h = d * 24
    return h

# Graphical parameters
print("\nSimulation Earth-Moon-Sun motion\n")
days = 365
seconds = fromDaysToS(days)
print("Days: ",days)
print("Seconds: ",seconds)

v = vector(384,0,0)
E = sphere(pos = vector(1500,0,0), color = color.blue, radius = 60, make_trail=True)
Ma = sphere(pos = vector(2300,0,0), color = color.orange, radius = 30, make_trail=True)
M = sphere(pos = E.pos + v, color = color.white,radius = 10, make_trail=True)
S = sphere(pos = vector(0,0,0), color = color.yellow, radius=700)

t = 0
thetaTerra1 = 0
dt = 5000
dthetaE = positionEarth(t+dt)- positionEarth(t)
dthetaM = positionMoon(t+dt) - positionMoon(t)
dthetaMa = positionMars(t+dt) - positionMars(t)
print("delta t:",dt,"seconds. Days:",fromStoDays(dt),"hours:",fromDaysToh(fromStoDays(dt)),sep=" ")
print("Variation angular position of the Earth:",dthetaE,"rad/s that's to say",degrees(dthetaE),"degrees",sep=" ")
print("Variation angular position of the Moon:",dthetaM,"rad/s that's to say",degrees(dthetaM),"degrees",sep=" ")

while t < seconds:
    rate(500)
    thetaEarth = positionEarth(t+dt)- positionEarth(t)
    thetaMoon = positionMoon(t+dt) - positionMoon(t)
    thetaMars = positionMars(t+dt) - positionMars(t)
    # Rotation only around z axis (0,0,1)
    E.pos = rotate(E.pos,angle=thetaEarth,axis=vector(0,1,0))
    Ma.pos = rotate(Ma.pos,angle=thetaMars,axis=vector(0,1,0))
    v = rotate(v,angle=thetaMoon,axis=vector(0,1,0))
    M.pos = E.pos + v
t += dt
导入数学
从vpython导入*
灯=局部光(位置=矢量(0,0,0),颜色=颜色。黄色)
#根据国际单位制以单位表示的数据
G=6.67*数学功率(10,-11)
#地球质量
ME=5.973*数学功率(10,24)
#月球质量
毫米=7.347*数学功率(10,22)
#火星的质量
MMa=6.39*数学功率(10,23)
#太阳质量
MS=1.989*数学功率(10,30)
#地月半径
雷姆=384400000
#日地半径
RSE=1496000000
RMS=227900000
#强迫地月
FEM=G*(ME*MM)/数学功率(REM,2)
#地日引力
FES=G*(MS*ME)/math.pow(RSE,2)
#火星太阳
FEMa=G*(MMa*MS)/数学功率(RMS,2)
#月球相对于地球的角速度(rad/s)
wM=数学平方比(FEM/(MM*REM))
#月球速度v(m/s)
vM=wM*REM
打印(“月球相对于地球的角速度:”,wM,“rad/s”)
打印(“月球速度v:,vM/1000,“km/s”)
#地球相对于太阳的角速度(rad/s)
wE=math.sqrt(FES/(ME*RSE))
#火星相对于太阳的角速度(rad/s)
wMa=数学sqrt(FEMa/(MMa*RMS))
#地球速度v(m/s)
vE=我们*RSE
#地球速度v(m/s)
vMa=wMa*RMS
print(“地球相对于太阳的角速度:,wE,“rad/s”)
打印(“地球速度v:,vE/1000,“km/s”)
#初始角位置
θ0=0
#每次定位
def位置(t):
θ=θ0+wM*t
返回θ
def位置(t):
θ=θ0+wMa*t
返回θ
def位置接地(t):
θ=θ0+wE*t
返回θ
def fromDaysToS(d):
s=d*24*60*60
返回s
def从40天开始:
d=s/60/60/24
返回d
从DaysToh(d)开始的def:
h=d*24
返回h
#图形参数
打印(“\n模拟地球-月球-太阳运动\n”)
天数=365天
秒=从天到秒(天)
打印(“天:”,天)
打印(“秒:”,秒)
v=向量(384,0,0)
E=球体(位置=矢量(1500,0,0),颜色=颜色。蓝色,半径=60,使轨迹为真)
Ma=球体(位置=矢量(2300,0,0),颜色=颜色。橙色,半径=30,使_轨迹=真)
M=球体(位置=E.pos+v,颜色=颜色。白色,半径=10,使轨迹为真)
S=球体(位置=矢量(0,0,0),颜色=颜色。黄色,半径=700)
t=0
Theaterra1=0
dt=5000
dthetaE=位置接地(t+dt)-位置接地(t)
dthetaM=位置月球(t+dt)-位置月球(t)
dthetaMa=位置mars(t+dt)-位置mars(t)
打印(“delta t:,dt,“秒.天:”,fromStoDays(dt),“小时:”,fromStoDays(dt)),sep=“”)
打印(“地球角度位置的变化:”,dthetaE,“rad/s,也就是说,”,度(dthetaE),“度”,sep=“”)
打印(“月亮的变化角位置:”,dthetaM,“rad/s,也就是说”,度(dthetaM),“度”,sep=“”)
当t
我想知道如何把轨道改成椭圆? 我试过几种方法,但都找不到解决办法

多谢各位。
谢谢

这似乎更像是一个物理问题,而不是编程问题。问题是,在线性计算速度和积分位置(例如v*dt)时,假设每个轨道都是圆形的。这不是计算轨道物体轨迹的方法

为了简单起见,我们假设所有的质量都是点质量,所以没有任何奇怪的重力梯度或姿态动力学可以解释

从那里,你可以参考麻省理工学院的网页。()轨道动力学。在第7页上,有一个方程,它将中心体的径向位置作为多个轨道参数的函数联系起来。看起来除了轨道的偏心率,你有所有的参数。如果你有详细的短命数据或近地点/近地点信息,你可以在线查找或计算

从这个方程中,你会看到分母中的φ-φ0项。这通俗地说就是卫星的真正反常现象。代替时间,您将在0到360之间迭代此真异常参数,以找到径向距离,从真异常、倾角、到上升节点的直角以及近点的参数,您可以找到特定真异常处的三维笛卡尔坐标

从真正的异常出发是不那么琐碎的。您需要找到偏心异常,然后是每个偏心异常步骤的平均异常。你现在有了作为时间函数的平均异常。可以在使用v*dt计算位置的“节点”之间进行线性插值。你可以用vis-viva方程计算速度,dt是计算出的时间步长之间的差值

在每个时间步中,您都可以在python程序中更新卫星的位置,它将正确地绘制您的轨迹

关于真实异常的更多信息,维基百科有一个很好的描述:


有关轨道元素的更多信息(需要从径向位置转换为笛卡尔坐标):

它们已经是椭圆了,只是偏心率太小了,你可以将其视为一个圆。您需要在不更改任何其他参数的情况下修改动能(显著)。试着把你的速度提高到100公里/秒,你会看到的change@v