Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
7461139e
宇宙模拟器
项目概览
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看板
提交
7461139e
编写于
11月 09, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
cdaf588d
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
116 addition
and
80 deletion
+116
-80
sim_lab/halley_comet_research_calc.py
sim_lab/halley_comet_research_calc.py
+35
-0
sim_scenes/solar_system/halley_comet_lib.py
sim_scenes/solar_system/halley_comet_lib.py
+26
-0
sim_scenes/solar_system/halley_comet_sim.py
sim_scenes/solar_system/halley_comet_sim.py
+55
-80
未找到文件。
sim_lab/halley_comet_research_calc.py
浏览文件 @
7461139e
...
...
@@ -251,6 +251,41 @@ def target_function(x, y, z):
if
__name__
==
'__main__'
:
pass
# 近日点 0.586 AU
# 上次通过近日点: 1986年2月9日
# 下次通过近日点: 2061年7月28日
# 远日点 35.1 AU 2023年12月9日
# [3.34, 0, 10.7] 2060-4-
# [3.34, 0, 10.712] 2061-5
# [3.34, 0, 10.715] 2061-6-24
# [3.34, 0, 10.718] 2061-8
# init_velocity=[3.34, 0, 10.718],
# init_position=[0, 0.5 * AU, -10 * AU]
# init_velocity=[-3.34, 3, 10.718],
# init_position=[0, -2 * AU, -10 * AU]) \
# start_time='1982-09-24 00:00:00',
# init_velocity=[-2.836, 4.705, 8.85],
# init_position=[0, -5 * AU, -10 * AU]
# 34.801 AU(2019-06-10)
# 35.086 AU(2023-09-01)
# 0.586 AU(1986-02-09)
# start_time='1982-09-24 00:00:00',
# init_velocity=[-2.837, 4.71, 8.852],
# init_position=[0, -5 * AU, -10 * AU]
# 34.840AU34.840 AU(2019-05-10)
# 35.149 AU(2023-10-08)
# 0.586 AU(1986-02-09)
# 35.198 AU(2023-11-07)
# 0.588 AU(1986-02-09)
# start_time='1982-09-24 00:00:00',
# init_velocity=[-2.841, 4.7, 8.86],
# init_position=[0, -5 * AU, -10 * AU]
# 2023年12月9日 - 1986年2月9日 = 13817
# 35.1AU 0.586AU
# target_function(-2.836, 4.705, 8.85)
...
...
sim_scenes/solar_system/halley_comet_lib.py
浏览文件 @
7461139e
...
...
@@ -15,6 +15,7 @@ from common.celestial_data_service import get_reality_orbit_points, init_bodies_
from
common.color_utils
import
trail_color_brightest
from
common.consts
import
AU
from
objs
import
HalleComet
from
simulators.ursina.ui.control_ui
import
ControlUI
from
simulators.ursina.ursina_mesh
import
create_orbit_by_points
...
...
@@ -100,3 +101,28 @@ class HalleyCometSimBase:
init_bodies_reality_pos_vels
(
self
.
bodies
,
start_time
)
else
:
init_bodies_pos_vels
(
self
.
bodies
)
def
show_grid_axises
(
self
):
"""
显示网格以及坐标线
@return:
"""
from
simulators.ursina.entities.world_grid
import
WorldGrid
WorldGrid
().
draw_axises
(
10
)
def
show_clock
(
self
,
dt
):
"""
显示时钟
@param dt: 时间 datetime
@return:
"""
# if self.clock_position_center:
# position, origin = (0, .25), (0, 0),
# else:
position
,
origin
=
(
0.60
,
-
0.465
),
(
-
0.5
,
0.5
),
ControlUI
.
current_ui
.
show_message
(
dt
.
strftime
(
'%Y-%m-%d %H:%M:%S'
),
position
=
position
,
origin
=
origin
,
font
=
"verdana.ttf"
,
close_time
=-
1
)
sim_scenes/solar_system/halley_comet_sim.py
浏览文件 @
7461139e
...
...
@@ -31,35 +31,33 @@ class HalleyCometSim(HalleyCometSimBase):
哈雷彗星场景模拟
"""
def
__init__
(
self
,
params
=
None
):
def
__init__
(
self
,
_
params
=
None
):
super
(
HalleyCometSim
,
self
).
__init__
()
if
params
is
None
:
if
_
params
is
None
:
self
.
params
=
HalleyCometParams
()
else
:
self
.
params
=
params
self
.
params
=
_
params
if
isinstance
(
params
.
start_time
,
str
):
self
.
start_time
=
conv_to_astropy_time
(
params
.
start_time
)
if
isinstance
(
_
params
.
start_time
,
str
):
self
.
start_time
=
conv_to_astropy_time
(
_
params
.
start_time
)
else
:
self
.
start_time
=
params
.
start_time
self
.
start_time
=
_
params
.
start_time
# print("北京时间:", dt.to_datetime(timezone=pytz.timezone('Asia/Shanghai')))
def
build
(
self
):
"""
构建太阳系系统以及哈雷彗星
@return:
"""
self
.
build_solar_system
(
ignore_gravity
=
True
,
start_time
=
self
.
start_time
)
# self.bodies = [
# self.sun, # 太阳
# self.mars, # 火星
# self.neptune, # 海王星
# ]
# 创建哈雷彗星创建哈雷彗星
self
.
halley_comet
=
create_halley_comet
(
self
.
params
.
init_velocity
,
self
.
params
.
init_position
)
self
.
bodies
.
append
(
self
.
halley_comet
)
def
on_ready
(
self
):
def
init_settings
(
self
):
"""
事件绑定后,模拟器运行前会触发
初始化设置
@return:
"""
# 创建天空
...
...
@@ -74,34 +72,35 @@ class HalleyCometSim(HalleyCometSimBase):
# camera.clip_plane_near = 0.1
camera
.
clip_plane_far
=
1000000
# WorldGrid().draw_axises(10)
application
.
time_scale
=
5
self
.
orbit_lines
=
[]
for
body
in
self
.
bodies
[
1
:]:
if
isinstance
(
body
,
HalleComet
):
continue
orbit_line
=
create_orbit_line
(
self
.
sun
,
body
,
self
.
start_time
)
self
.
orbit_lines
.
append
(
orbit_line
)
def
on_ready
(
self
):
"""
事件绑定后,模拟器运行前会触发
@return:
"""
# 初始化设置
self
.
init_settings
()
# 显示网格以及坐标线
# self.show_grid_axises()
# 创建太阳系天体的真实轨迹(太阳和哈雷彗星除外)
self
.
create_orbit_lines
()
# 创建信息显示面板
self
.
text_panel
=
create_text_panel
()
def
show_clock
(
self
,
dt
):
def
create_orbit_lines
(
self
):
"""
显示时钟
@param dt: 时间 datetime
创建太阳系天体的真实轨迹(太阳和哈雷彗星除外)
@return:
"""
# if self.clock_position_center:
# position, origin = (0, .25), (0, 0),
# else:
position
,
origin
=
(
0.60
,
-
0.465
),
(
-
0.5
,
0.5
),
ControlUI
.
current_ui
.
show_message
(
dt
.
strftime
(
'%Y-%m-%d %H:%M:%S'
),
position
=
position
,
origin
=
origin
,
font
=
"verdana.ttf"
,
close_time
=-
1
)
self
.
orbit_lines
=
[]
for
body
in
self
.
bodies
[
1
:]:
if
isinstance
(
body
,
HalleComet
):
continue
orbit_line
=
create_orbit_line
(
self
.
sun
,
body
,
self
.
start_time
)
self
.
orbit_lines
.
append
(
orbit_line
)
def
set_bodies_position
(
self
,
time_data
:
TimeData
):
"""
...
...
@@ -113,28 +112,41 @@ class HalleyCometSim(HalleyCometSimBase):
set_solar_system_celestial_position
(
self
.
bodies
,
t
,
False
)
def
create_year_label
(
self
,
trail
,
year
,
halley_comet_pos
):
"""
在界面上创建年份的标签
@param trail:
@param year:
@param halley_comet_pos:
@return:
"""
if
trail
is
None
:
pos
=
halley_comet_pos
else
:
pos
=
(
0
,
0
,
0
)
label
=
create_label
(
trail
,
label
=
year
,
pos
=
pos
,
color
=
(
255
,
255
,
255
),
scale
=
40
,
alpha
=
1.0
)
# label.udpate
label
.
set_light_off
()
def
show_comet_trail
(
self
,
distance_sun
):
def
set_comet_trail_alpha
(
self
,
distance_sun
):
"""
根据彗哈雷星和太阳的距离,设置彗星尾巴的透明度来模仿接近太阳有慧尾,离开太阳到一定距离就渐渐消失
@param distance_sun: 彗哈雷星和太阳的距离
@return:
"""
# 距离转为天文单位
d_au
=
distance_sun
/
AU
# 渐渐消失的距离范围(开始消失距离, 完全消失距离)
HIDE_DISTANCE
=
1
,
15
# 彗星最大的透明度
MAX_ALPHA
=
0.8
# 大于完全消失距离
if
d_au
>=
HIDE_DISTANCE
[
1
]:
alpha
=
0
elif
HIDE_DISTANCE
[
1
]
>
d_au
>
HIDE_DISTANCE
[
0
]:
elif
HIDE_DISTANCE
[
1
]
>
d_au
>
HIDE_DISTANCE
[
0
]:
# 渐渐消失的距离范围内,通过距离值大小确定透明度(慢慢消失的效果)
alpha
=
MAX_ALPHA
-
(
d_au
-
HIDE_DISTANCE
[
0
])
/
(
HIDE_DISTANCE
[
1
]
-
HIDE_DISTANCE
[
0
])
*
MAX_ALPHA
else
:
alpha
=
MAX_ALPHA
if
alpha
>
MAX_ALPHA
:
alpha
=
MAX_ALPHA
# 修改彗星尾巴的透明度
c
=
self
.
halley_comet
.
planet
.
children
[
0
]
c
.
alpha
=
alpha
...
...
@@ -148,12 +160,8 @@ class HalleyCometSim(HalleyCometSimBase):
year
=
dt
.
strftime
(
"%Y"
)
if
hasattr
(
self
,
"halley_comet"
):
# 哈雷彗星飞行的翻转效果
if
self
.
halley_comet
.
planet
.
enabled
:
# self.halley_comet.planet.rotation_x += 0.1
# self.halley_comet.planet.rotation_y += 1
self
.
halley_comet
.
planet
.
look_at
(
self
.
sun
.
planet
)
d_sun
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
sun
.
position
)
d_earth
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
earth
.
position
)
trail_keys
=
self
.
halley_comet
.
planet
.
trails
.
keys
()
...
...
@@ -200,7 +208,7 @@ class HalleyCometSim(HalleyCometSimBase):
self
.
comet_aphel
=
d_sun
self
.
comet_aphel_dt
=
dt
.
strftime
(
"%Y-%m-%d"
)
self
.
s
how_comet_trail
(
d_sun
)
self
.
s
et_comet_trail_alpha
(
d_sun
)
panel_text
=
"哈雷彗星:
\n
距离太阳:%.3f AU"
%
(
d_sun
/
AU
)
# panel_text += "\n离日最远:%.3f AU(%s)" % (self.comet_aphel / AU, self.comet_aphel_dt)
...
...
@@ -237,19 +245,6 @@ if __name__ == '__main__':
"""
哈雷彗星场景模拟
"""
# 近日点 0.586 AU
# 上次通过近日点: 1986年2月9日
# 下次通过近日点: 2061年7月28日
# 远日点 35.1 AU 2023年12月9日
# [3.34, 0, 10.7] 2060-4-
# [3.34, 0, 10.712] 2061-5
# [3.34, 0, 10.715] 2061-6-24
# [3.34, 0, 10.718] 2061-8
# init_velocity=[3.34, 0, 10.718],
# init_position=[0, 0.5 * AU, -10 * AU]
# init_velocity=[-3.34, 3, 10.718],
# init_position=[0, -2 * AU, -10 * AU]) \
# 远日点: 35.1 AU(2023年12月9日)
# 近日点: 0.586 AU 上次通过近日点:1986年2月9日 下次通过近日点:2061年7月28日
# 2019年5月6日 34.772
...
...
@@ -261,26 +256,6 @@ if __name__ == '__main__':
init_position
=
[
0
,
-
5
*
AU
,
-
10
*
AU
]
)
# start_time='1982-09-24 00:00:00',
# init_velocity=[-2.836, 4.705, 8.85],
# init_position=[0, -5 * AU, -10 * AU]
# 34.801 AU(2019-06-10)
# 35.086 AU(2023-09-01)
# 0.586 AU(1986-02-09)
# start_time='1982-09-24 00:00:00',
# init_velocity=[-2.837, 4.71, 8.852],
# init_position=[0, -5 * AU, -10 * AU]
# 34.840AU34.840 AU(2019-05-10)
# 35.149 AU(2023-10-08)
# 0.586 AU(1986-02-09)
# 35.198 AU(2023-11-07)
# 0.588 AU(1986-02-09)
# start_time='1982-09-24 00:00:00',
# init_velocity=[-2.841, 4.7, 8.86],
# init_position=[0, -5 * AU, -10 * AU]
sim
=
HalleyCometSim
(
params
)
sim
.
build
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录