Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
7b36b769
宇宙模拟器
项目概览
Python_超人
/
宇宙模拟器
通知
19
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
宇宙模拟器
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
7b36b769
编写于
7月 23, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
6a718659
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
61 addition
and
30 deletion
+61
-30
sim_scenes/solar_system/solar_system_reality.py
sim_scenes/solar_system/solar_system_reality.py
+59
-30
simulators/ursina_simulator.py
simulators/ursina_simulator.py
+2
-0
未找到文件。
sim_scenes/solar_system/solar_system_reality.py
浏览文件 @
7b36b769
...
@@ -6,31 +6,45 @@
...
@@ -6,31 +6,45 @@
# link :https://gitcode.net/pythoncr/
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# python_version :3.8
# ==============================================================================
# ==============================================================================
# pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com de423
# solar_system_ephemeris.bodies
# ('earth', 'sun', 'moon', 'mercury', 'venus', 'earth-moon-barycenter', 'mars', 'jupiter', 'saturn', 'uranus', 'neptune')
import
numpy
as
np
import
numpy
as
np
from
astropy.coordinates
import
get_body_barycentric_posvel
from
astropy.time
import
Time
from
bodies
import
Sun
,
Mercury
,
Venus
,
Earth
,
Mars
,
Jupiter
,
Saturn
,
Uranus
,
Neptune
,
Pluto
,
Moon
,
Asteroids
from
bodies
import
Sun
,
Mercury
,
Venus
,
Earth
,
Mars
,
Jupiter
,
Saturn
,
Uranus
,
Neptune
,
Moon
from
common.consts
import
SECONDS_PER_WEEK
,
SECONDS_PER_DAY
,
SECONDS_PER_YEAR
,
AU
from
common.consts
import
SECONDS_PER_WEEK
,
SECONDS_PER_DAY
,
AU
from
sim_scenes.func
import
mayavi_run
,
ursina_run
from
sim_scenes.func
import
ursina_run
from
simulators.ursina.entities.body_timer
import
TimeData
from
simulators.ursina.entities.body_timer
import
TimeData
from
simulators.ursina.ui.control_ui
import
ControlUI
from
simulators.ursina.ui.control_ui
import
ControlUI
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
astropy.coordinates
import
get_body_barycentric
from
ursina
import
camera
from
astropy.time
import
Time
def
get_bodies_pos
ition
s
(
planet_names
=
"sun,mercury,venus,earth,moon,mars,jupiter,saturn,uranus,neptune"
,
time
=
None
):
def
get_bodies_pos
vel
s
(
planet_names
=
"sun,mercury,venus,earth,moon,mars,jupiter,saturn,uranus,neptune"
,
time
=
None
):
if
time
is
None
:
if
time
is
None
:
time
=
Time
.
now
()
time
=
Time
.
now
()
planets
=
planet_names
.
split
(
","
)
planets
=
planet_names
.
split
(
","
)
pos
ition
s
=
{}
pos
vel
s
=
{}
for
planet
in
planets
:
for
planet
in
planets
:
try
:
try
:
position
=
get_body_barycentric
(
planet
,
time
)
position
,
velocity
=
get_body_barycentric_posvel
(
planet
,
time
)
pos
itions
[
planet
]
=
position
pos
vels
[
planet
]
=
position
,
velocity
print
(
planet
,
position
)
#
print(planet, position)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
planet
,
str
(
e
))
print
(
planet
,
str
(
e
))
return
positions
return
posvels
def
recalc_moon_position
(
moon_posvel
,
earth_pos
):
moon_pos
,
moon_vel
=
moon_posvel
[
0
],
moon_posvel
[
1
]
moon_pos_to_earth
=
moon_pos
-
earth_pos
moon_pos_to_earth
=
moon_pos_to_earth
*
50
return
moon_pos_to_earth
+
earth_pos
,
moon_vel
def
get_bodies_names
(
bodies
):
def
get_bodies_names
(
bodies
):
...
@@ -51,43 +65,58 @@ if __name__ == '__main__':
...
@@ -51,43 +65,58 @@ if __name__ == '__main__':
# =====================================================================
# =====================================================================
# 以下展示的效果为太阳系真实的距离
# 以下展示的效果为太阳系真实的距离
# 由于宇宙空间尺度非常大,如果按照实际的天体大小,则无法看到天体,因此需要对天体的尺寸进行放大
# 由于宇宙空间尺度非常大,如果按照实际的天体大小,则无法看到天体,因此需要对天体的尺寸进行放大
sun
=
Sun
(
name
=
"太阳"
,
size_scale
=
0.4e2
)
# 太阳放大
8
0 倍,距离保持不变
sun
=
Sun
(
name
=
"太阳"
,
size_scale
=
0.4e2
)
# 太阳放大
4
0 倍,距离保持不变
bodies
=
[
bodies
=
[
sun
,
sun
,
Mercury
(
name
=
"水星"
,
size_scale
=
3
e3
),
# 水星
Mercury
(
name
=
"水星"
,
size_scale
=
1.5
e3
),
# 水星
Venus
(
name
=
"金星"
,
size_scale
=
3
e3
),
# 金星
Venus
(
name
=
"金星"
,
size_scale
=
1
e3
),
# 金星
Earth
(
name
=
"地球"
,
size_scale
=
3
e3
),
# 地球
Earth
(
name
=
"地球"
,
size_scale
=
1
e3
),
# 地球
Moon
(
name
=
"月球"
,
size_scale
=
3
e3
),
# 月球
Moon
(
name
=
"月球"
,
size_scale
=
2
e3
),
# 月球
Mars
(
name
=
"火星"
,
size_scale
=
3
e3
),
# 火星
Mars
(
name
=
"火星"
,
size_scale
=
1.2
e3
),
# 火星
Jupiter
(
name
=
"木星"
,
size_scale
=
6e2
),
# 木星
Jupiter
(
name
=
"木星"
,
size_scale
=
6e2
),
# 木星
Saturn
(
name
=
"土星"
,
size_scale
=
6e2
),
# 土星
Saturn
(
name
=
"土星"
,
size_scale
=
6e2
),
# 土星
Uranus
(
name
=
"天王星"
,
size_scale
=
10e2
),
# 天王星
Uranus
(
name
=
"天王星"
,
size_scale
=
10e2
),
# 天王星
Neptune
(
name
=
"海王星"
,
size_scale
=
10e2
),
# 海王星
Neptune
(
name
=
"海王星"
,
size_scale
=
10e2
),
# 海王星
]
]
# pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com de423
names
=
get_bodies_names
(
bodies
)
names
=
get_bodies_names
(
bodies
)
def
get_body_position
(
body
,
positions
):
position
=
positions
.
get
(
body
.
__class__
.
__name__
,
None
)
if
position
is
None
:
return
[
0
,
0
,
0
]
# return [position.x.value * AU, position.y.value * AU, position.z.value * AU]
def
get_body_posvel
(
body
,
posvels
):
return
[
position
.
x
.
value
*
AU
,
position
.
z
.
value
*
AU
,
position
.
y
.
value
*
AU
]
posvel
=
posvels
.
get
(
body
.
__class__
.
__name__
,
None
)
return
posvel
def
on_ready
():
def
on_ready
():
# 运行前触发
# 运行前触发
pass
camera
.
rotation_z
=
-
20
def
on_timer_changed
(
time_data
:
TimeData
):
def
on_timer_changed
(
time_data
:
TimeData
):
t
=
current_time
+
time_data
.
total_days
t
=
current_time
+
time_data
.
total_days
positions
=
get_bodies_positions
(
names
,
t
)
posvels
=
get_bodies_posvels
(
names
,
t
)
# earth_loc = None
earth_pos
=
None
for
body
in
bodies
:
for
body
in
bodies
:
position
=
get_body_position
(
body
,
positions
)
posvel
=
get_body_posvel
(
body
,
posvels
)
if
isinstance
(
body
,
Moon
):
posvel
=
recalc_moon_position
(
posvel
,
earth_pos
)
if
posvel
is
None
:
position
,
velocity
=
[
0
,
0
,
0
],
[
0
,
0
,
0
]
else
:
S_OF_D
=
24
*
60
*
60
# 坐标单位:千米 速度单位:千米/秒
position
,
velocity
=
[
posvel
[
0
].
x
.
value
*
AU
,
posvel
[
0
].
z
.
value
*
AU
,
posvel
[
0
].
y
.
value
*
AU
],
\
[
posvel
[
1
].
x
.
value
*
AU
/
S_OF_D
,
posvel
[
1
].
z
.
value
*
AU
/
S_OF_D
,
posvel
[
1
].
y
.
value
*
AU
/
S_OF_D
]
body
.
position
=
np
.
array
(
position
)
body
.
position
=
np
.
array
(
position
)
body
.
velocity
=
np
.
array
(
velocity
)
if
isinstance
(
body
,
Earth
):
# earth_loc = EarthLocation(x=posvel[0].x, y=posvel[0].y, z=posvel[0].z)
earth_pos
=
posvel
[
0
]
dt
=
time_data
.
get_datetime
(
str
(
current_time
))
dt
=
time_data
.
get_datetime
(
str
(
current_time
))
# print(time_data.get_datetime(str(current_time)))
# print(time_data.get_datetime(str(current_time)))
...
@@ -102,8 +131,8 @@ if __name__ == '__main__':
...
@@ -102,8 +131,8 @@ if __name__ == '__main__':
# 使用 ursina 查看的运行效果
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
SECONDS_PER_WEEK
,
ursina_run
(
bodies
,
1
,
position
=
(
0
,
2
*
AU
,
-
11
*
AU
),
position
=
(
0
,
0.2
*
AU
,
-
3
*
AU
),
gravity_works
=
False
,
# 关闭万有引力的计算
gravity_works
=
False
,
# 关闭万有引力的计算
show_grid
=
False
,
show_grid
=
False
,
show_timer
=
True
)
show_timer
=
True
)
simulators/ursina_simulator.py
浏览文件 @
7b36b769
...
@@ -224,6 +224,8 @@ class UrsinaSimulator(Simulator):
...
@@ -224,6 +224,8 @@ class UrsinaSimulator(Simulator):
UrsinaEvent
.
on_evolving
(
evolve_dt
)
UrsinaEvent
.
on_evolving
(
evolve_dt
)
# interval_fator 能让更新天体运行状态(位置、速度)更精确
# interval_fator 能让更新天体运行状态(位置、速度)更精确
evolve_dt
=
evolve_dt
*
self
.
interval_fator
evolve_dt
=
evolve_dt
*
self
.
interval_fator
if
run_speed_factor
<
3
:
evolve_dt
*=
1.666
# 人为加入一个针对秒级计算的误差,保证模拟器的1秒和现实同步(不要求精确可以注释掉)
evolve_args
=
{
"evolve_dt"
:
evolve_dt
}
evolve_args
=
{
"evolve_dt"
:
evolve_dt
}
UrsinaEvent
.
on_before_evolving
(
evolve_args
)
UrsinaEvent
.
on_before_evolving
(
evolve_args
)
# if evolve_args["evolve_dt"] > 0:
# if evolve_args["evolve_dt"] > 0:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录