提交 6b799320 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 bb1ef362
......@@ -259,18 +259,100 @@ def show_bodies_posvels(dt):
for body_name in sse.bodies:
earth_pos_vel = get_body_barycentric_posvel(body_name, dt)
print(f"{body_name}-坐标(公里):", [earth_pos_vel[0].x.to(u.km),
earth_pos_vel[0].y.to(u.km),
earth_pos_vel[0].z.to(u.km)])
earth_pos_vel[0].y.to(u.km),
earth_pos_vel[0].z.to(u.km)])
print(f"{body_name}-速度(公里/秒):",
[earth_pos_vel[1].x.to(u.km / u.second),
earth_pos_vel[1].y.to(u.km / u.second),
earth_pos_vel[1].z.to(u.km / u.second)])
def gen_real_pos_vel_bodies(body_names, dt):
import pytz
# 安装 astropy 包
# pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com astropy
# 获取天体的坐标pos和速度vel
from astropy.coordinates import get_body_barycentric_posvel
import astropy.units as u # 单位
# from astropy.coordinates import solar_system_ephemeris as sse
print("北京时间:", dt.to_datetime(timezone=pytz.timezone('Asia/Shanghai')))
gen_body_str = " init_pos_vels = {}\n"
for body_name in str(body_names).split(","):
earth_pos_vel = get_body_barycentric_posvel(body_name, dt)
pos,vel = earth_pos_vel[0],earth_pos_vel[1]
gen_body_str += f" init_pos_vels['{body_name.lower()}']={{}}\n"
gen_body_str += f" init_pos_vels['{body_name.lower()}']['pos']=[%.4f,%.4f,%.4f]\n" % (pos.x.to(u.km).value,
pos.y.to(u.km).value,
pos.z.to(u.km).value)
gen_body_str += f" init_pos_vels['{body_name.lower()}']['vel']=[%.4f,%.4f,%.4f]\n" % (vel.x.to(u.km / u.second).value,
vel.y.to(u.km / u.second).value,
vel.z.to(u.km / u.second).value)
return gen_body_str
# pos, vel = earth_pos_vel[0], earth_pos_vel[1]
# print(f"{body_name}-坐标(公里):", [pos.x.to(u.km).value,
# pos.y.to(u.km).value,
# pos.z.to(u.km)].value)
# print(f"{body_name}-速度(公里/秒):",
# [vel.x.to(u.km / u.second).value,
# vel.y.to(u.km / u.second).value,
# vel.z.to(u.km / u.second).value])
def get_init_pos_vels():
init_pos_vels = {}
init_pos_vels['sun'] = {}
init_pos_vels['sun']['pos'] = [120062.8111, -462734.9565, -198328.7512]
init_pos_vels['sun']['vel'] = [0.0093, 0.0037, 0.0014]
init_pos_vels['mercury'] = {}
init_pos_vels['mercury']['pos'] = [-27459444.3141, 33659309.8266, 20887619.1358]
init_pos_vels['mercury']['vel'] = [-49.8268, -24.7415, -8.0569]
init_pos_vels['venus'] = {}
init_pos_vels['venus']['pos'] = [21823958.6720, -97202911.8077, -45109059.0044]
init_pos_vels['venus']['vel'] = [34.0912, 7.0463, 1.0154]
init_pos_vels['earth'] = {}
init_pos_vels['earth']['pos'] = [-25983996.5057, 132369339.0025, 57373518.2429]
init_pos_vels['earth']['vel'] = [-29.7869, -4.9606, -2.1489]
init_pos_vels['mars'] = {}
init_pos_vels['mars']['pos'] = [-230623216.7918, -71477306.3132, -26561224.6080]
init_pos_vels['mars']['vel'] = [8.4564, -18.9614, -8.9250]
init_pos_vels['jupiter'] = {}
init_pos_vels['jupiter']['pos'] = [-357712686.7572, 637570826.6050, 281973598.8065]
init_pos_vels['jupiter']['vel'] = [-11.7897, -5.0252, -1.8671]
init_pos_vels['saturn'] = {}
init_pos_vels['saturn']['pos'] = [713384516.7012, -1202372203.9542, -527442445.4970]
init_pos_vels['saturn']['vel'] = [7.9649, 4.3679, 1.4610]
init_pos_vels['uranus'] = {}
init_pos_vels['uranus']['pos'] = [-2666283945.3730, 544495773.6564, 276202868.3064]
init_pos_vels['uranus']['vel'] = [-1.5476, -6.3725, -2.7691]
init_pos_vels['neptune'] = {}
init_pos_vels['neptune']['pos'] = [2602697275.5219, 3374419276.7397, 1316379531.2695]
init_pos_vels['neptune']['vel'] = [-4.4365, 2.9291, 1.3095]
return init_pos_vels
if __name__ == '__main__':
from astropy.time import Time # 时间
# bodies = [
# sun, # 太阳放大 80 倍
# Mercury(size_scale=4e3, distance_scale=1.3), # 水星放大 4000 倍,距离放大 1.3 倍
# Venus(size_scale=4e3, distance_scale=1.3), # 金星放大 4000 倍,距离放大 1.3 倍
# Earth(size_scale=4e3, distance_scale=1.3), # 地球放大 4000 倍,距离放大 1.3 倍
# Mars(size_scale=4e3, distance_scale=1.2), # 火星放大 4000 倍,距离放大 1.2 倍
# Asteroids(size_scale=1e2, parent=sun), # 小行星模拟(仅 ursina 模拟器支持)
# Jupiter(size_scale=0.68e3, distance_scale=0.72), # 木星放大 680 倍,距离缩小到真实距离的 0.72
# Saturn(size_scale=0.68e3, distance_scale=0.52), # 土星放大 680 倍,距离缩小到真实距离的 0.52
# Uranus(size_scale=0.8e3, distance_scale=0.36), # 天王星放大 800 倍,距离缩小到真实距离的 0.36
# Neptune(size_scale=1e3, distance_scale=0.27), # 海王星放大 1000 倍,距离缩小到真实距离的 0.27
# Pluto(size_scale=10e3, distance_scale=0.23), # 冥王星放大 10000 倍,距离缩小到真实距离的 0.23(从太阳系的行星中排除)
# ]
# 获取当前时间
dt = Time.now()
# 指定未来的日期时间
# dt = Time.now()
# # 指定未来的日期时间
# dt = conv_to_astropy_time('2050-01-01 12:00:00')
show_bodies_posvels(dt)
# # show_bodies_posvels(dt)
# bs = gen_real_pos_vel_bodies('sun,Mercury,Venus,Earth,Mars,Jupiter,Saturn,Uranus,Neptune',dt)
# print(bs)
print(get_init_pos_vels()['sun'])
......@@ -23,6 +23,74 @@ from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, SECONDS_PER_MONTH,
from sim_scenes.func import mayavi_run, ursina_run, create_sphere_sky
from simulators.ursina.ursina_event import UrsinaEvent
def get_init_pos_vels():
init_pos_vels = {}
# init_pos_vels['sun'] = {}
# init_pos_vels['sun']['pos'] = [120062.8111, -462734.9565, -198328.7512]
# init_pos_vels['sun']['vel'] = [0.0093, 0.0037, 0.0014]
# init_pos_vels['mercury'] = {}
# init_pos_vels['mercury']['pos'] = [-27459444.3141, 33659309.8266, 20887619.1358]
# init_pos_vels['mercury']['vel'] = [-49.8268, -24.7415, -8.0569]
# init_pos_vels['venus'] = {}
# init_pos_vels['venus']['pos'] = [21823958.6720, -97202911.8077, -45109059.0044]
# init_pos_vels['venus']['vel'] = [34.0912, 7.0463, 1.0154]
# init_pos_vels['earth'] = {}
# init_pos_vels['earth']['pos'] = [-25983996.5057, 132369339.0025, 57373518.2429]
# init_pos_vels['earth']['vel'] = [-29.7869, -4.9606, -2.1489]
# init_pos_vels['mars'] = {}
# init_pos_vels['mars']['pos'] = [-230623216.7918, -71477306.3132, -26561224.6080]
# init_pos_vels['mars']['vel'] = [8.4564, -18.9614, -8.9250]
# init_pos_vels['jupiter'] = {}
# init_pos_vels['jupiter']['pos'] = [-357712686.7572, 637570826.6050, 281973598.8065]
# init_pos_vels['jupiter']['vel'] = [-11.7897, -5.0252, -1.8671]
# init_pos_vels['saturn'] = {}
# init_pos_vels['saturn']['pos'] = [713384516.7012, -1202372203.9542, -527442445.4970]
# init_pos_vels['saturn']['vel'] = [7.9649, 4.3679, 1.4610]
# init_pos_vels['uranus'] = {}
# init_pos_vels['uranus']['pos'] = [-2666283945.3730, 544495773.6564, 276202868.3064]
# init_pos_vels['uranus']['vel'] = [-1.5476, -6.3725, -2.7691]
# init_pos_vels['neptune'] = {}
# init_pos_vels['neptune']['pos'] = [2602697275.5219, 3374419276.7397, 1316379531.2695]
# init_pos_vels['neptune']['vel'] = [-4.4365, 2.9291, 1.3095]
init_pos_vels['sun'] = {}
init_pos_vels['sun']['pos'] = [-4638653.0000, 0.0000, 1314332.6250]
init_pos_vels['sun']['vel'] = [-0.0165, 0.0000, -0.0097]
init_pos_vels['mercury'] = {}
init_pos_vels['mercury']['pos'] = [-54412616.0000, 0.0000, 31280100.0000]
init_pos_vels['mercury']['vel'] = [-25.2667, 0.0000, -40.0561]
init_pos_vels['venus'] = {}
init_pos_vels['venus']['pos'] = [-32341672.0000, 0.0000, -99861352.0000]
init_pos_vels['venus']['vel'] = [34.3770, 0.0000, -10.6676]
init_pos_vels['earth'] = {}
init_pos_vels['earth']['pos'] = [140427392.0000, 0.0000, 45724572.0000]
init_pos_vels['earth']['vel'] = [-8.1280, 0.0000, 28.2277]
init_pos_vels['mars'] = {}
init_pos_vels['mars']['pos'] = [218751648.0000, 0.0000, -45263688.0000]
init_pos_vels['mars']['vel'] = [5.2205, 0.0000, 23.4601]
init_pos_vels['asteroids'] = {}
init_pos_vels['asteroids']['pos'] = [0.0000, 0.0000, 0.0000]
init_pos_vels['asteroids']['vel'] = [0.0000, 0.0000, 0.0000]
init_pos_vels['jupiter'] = {}
init_pos_vels['jupiter']['pos'] = [769445760.0000, 0.0000, 2017638.5000]
init_pos_vels['jupiter']['vel'] = [0.0389, 0.0000, 13.0879]
init_pos_vels['saturn'] = {}
init_pos_vels['saturn']['pos'] = [-1330536704.0000, 0.0000, -454165280.0000]
init_pos_vels['saturn']['vel'] = [3.2189, 0.0000, -9.1974]
init_pos_vels['uranus'] = {}
init_pos_vels['uranus']['pos'] = [-1757163648.0000, 0.0000, 2272503808.0000]
init_pos_vels['uranus']['vel'] = [-5.3918, 0.0000, -4.1634]
init_pos_vels['neptune'] = {}
init_pos_vels['neptune']['pos'] = [-1480893824.0000, 0.0000, 4351772160.0000]
init_pos_vels['neptune']['vel'] = [-5.1466, 0.0000, -1.7189]
init_pos_vels['pluto'] = {}
init_pos_vels['pluto']['pos'] = [-1293909504.0000, 0.0000, 5770579968.0000]
init_pos_vels['pluto']['vel'] = [-4.5847, 0.0000, -1.0475]
return init_pos_vels
if __name__ == '__main__':
"""
三体二向箔场景模拟
......@@ -45,9 +113,23 @@ if __name__ == '__main__':
]
# endregion
init_pos_vels = get_init_pos_vels()
for body in bodies:
pos_vels = init_pos_vels.get(type(body).__name__.lower(), None)
if pos_vels is None:
continue
body.init_position = pos_vels['pos']
body.init_velocity = pos_vels['vel']
two_way_foil = QuadObj(texture='caustic.jpg', size_scale=4e7,
init_velocity=[0, 0, 100],
init_position=[0, 0, -10*AU]) \
init_position=[0, 0, -10 * AU]) \
.set_light_disable(True).set_ignore_gravity(True)
two_way_foil_circle = CircleObj(texture=two_way_foil.texture,
size_scale=two_way_foil.size_scale * 2,
) \
.set_light_disable(True).set_ignore_gravity(True)
three_dim_bodies = []
......@@ -72,6 +154,8 @@ if __name__ == '__main__':
two_dim_bodies.append(two_dim_body)
bodies.append(two_way_foil)
bodies.append(two_way_foil_circle)
for body in two_dim_bodies:
bodies.append(body)
......@@ -92,9 +176,15 @@ if __name__ == '__main__':
rings = create_rings(body.planet)
rings.scale *= 2e10
two_way_foil_circle.planet.rotation_x = 90
two_way_foil_circle.planet.enabled = False
for b in two_dim_bodies:
b.planet.rotation_x = 90
current_stage = None
def stage_01():
"""
二向箔飞向太阳
......@@ -106,8 +196,11 @@ if __name__ == '__main__':
sun.two_dim.planet.enabled = True
# two_way_foil.explode(sun)
two_way_foil.planet.enabled = False
two_way_foil_circle.planet.alpha = 0.5
two_way_foil_circle.planet.enabled = True
current_stage = stage_02
def blink(body):
if not hasattr(body, "blink_d"):
body.blink_d = 1
......@@ -125,26 +218,27 @@ if __name__ == '__main__':
body.blink_d = 1
def stage_02():
"""
@return:
"""
global current_stage
sun.two_dim.planet.init_scale += 1.1
sun.two_dim.planet.init_scale += 0.01
two_way_foil_circle.planet.init_scale += 0.8
blink(sun.two_dim)
for b in three_dim_bodies:
if two_bodies_colliding(sun.two_dim, b):
if two_bodies_colliding(two_way_foil_circle, b):
b.planet.enabled = False
b.two_dim.planet.enabled = True
if b.two_dim.planet.enabled:
b.two_dim.planet.init_scale += 1.1
b.two_dim.planet.init_scale += 0.01
blink(b.two_dim)
current_stage = stage_01
def on_timer_changed(time_data):
two_way_foil.planet.rotation_x += 1
two_way_foil.planet.rotation_y += 2
......@@ -162,15 +256,26 @@ if __name__ == '__main__':
# sun.planet.enabled = False
# sun.two_dim.planet.enabled = True
# for b in three_dim_bodies:
# b.planet.enabled = False
init_pos_vels_info = ""
for b in two_dim_bodies:
b.planet.rotation_x = 90
# b.planet.rotation_x = 90
b.init_position = b.three_dim.position
print(b.planet.position, b.three_dim.planet.position)
pos, vel = b.three_dim.position, b.three_dim.velocity
t_name = type(b.three_dim).__name__.lower()
init_pos_vels_info += f" init_pos_vels['{t_name}'] = {{}}"
init_pos_vels_info += f" init_pos_vels['{t_name}']['pos'] = [%.4f,%.4f,%.4f]\n" % (
pos[0], pos[1], pos[2])
init_pos_vels_info += f" init_pos_vels['{t_name}']['vel'] = [%.4f,%.4f,%.4f]\n" % (
vel[0], vel[1], vel[2])
# init_pos_vels['sun'] = {}
# init_pos_vels['sun']['pos'] = [120062.8111, -462734.9565, -198328.7512]
# init_pos_vels['sun']['vel'] = [0.0093, 0.0037, 0.0014]
# print(b.planet.position, b.three_dim.planet.position)
print("----------------------------------------------")
print(init_pos_vels_info)
pass
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册