Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
02fa3606
宇宙模拟器
项目概览
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看板
提交
02fa3606
编写于
10月 27, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
28e024d5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
40 addition
and
29 deletion
+40
-29
sim_scenes/solar_system/halley_comet_sim_02.py
sim_scenes/solar_system/halley_comet_sim_02.py
+40
-29
未找到文件。
sim_scenes/solar_system/halley_comet_sim_02.py
浏览文件 @
02fa3606
...
...
@@ -33,21 +33,22 @@ class HalleyCometSim:
def
build_solar_system
(
self
):
# region 构建太阳系
self
.
sun
=
Sun
(
size_scale
=
0.8e2
,
show_trail
=
False
)
self
.
mercury
=
Mercury
(
size_scale
=
5e3
,
show_trail
=
False
)
self
.
venus
=
Venus
(
size_scale
=
5e3
,
show_trail
=
False
)
self
.
earth
=
Earth
(
size_scale
=
5e3
,
rotate_angle
=
0
,
show_trail
=
False
)
self
.
mars
=
Mars
(
size_scale
=
5e3
,
show_trail
=
False
)
self
.
jupiter
=
Jupiter
(
size_scale
=
2.5e3
,
show_trail
=
False
)
self
.
saturn
=
Saturn
(
size_scale
=
2.5e3
,
show_trail
=
False
)
self
.
uranus
=
Uranus
(
size_scale
=
6e3
,
show_trail
=
False
)
self
.
neptune
=
Neptune
(
size_scale
=
6e3
,
show_trail
=
False
)
self
.
pluto
=
Pluto
(
size_scale
=
1e5
,
show_trail
=
False
)
show_trail
=
True
self
.
sun
=
Sun
(
size_scale
=
0.8e2
,
show_trail
=
show_trail
)
self
.
mercury
=
Mercury
(
size_scale
=
5e3
,
show_trail
=
show_trail
)
self
.
venus
=
Venus
(
size_scale
=
5e3
,
show_trail
=
show_trail
)
self
.
earth
=
Earth
(
size_scale
=
5e3
,
rotate_angle
=
0
,
show_trail
=
show_trail
)
self
.
mars
=
Mars
(
size_scale
=
5e3
,
show_trail
=
show_trail
)
self
.
jupiter
=
Jupiter
(
size_scale
=
2.5e3
,
show_trail
=
show_trail
)
self
.
saturn
=
Saturn
(
size_scale
=
2.5e3
,
show_trail
=
show_trail
)
self
.
uranus
=
Uranus
(
size_scale
=
6e3
,
show_trail
=
show_trail
)
self
.
neptune
=
Neptune
(
size_scale
=
6e3
,
show_trail
=
show_trail
)
self
.
pluto
=
Pluto
(
size_scale
=
1e5
,
show_trail
=
show_trail
)
self
.
bodies
=
[
self
.
sun
,
# 太阳
#
self.mercury, # 水星
#
self.venus, # 金星
#
self.earth, # 地球
self
.
mercury
,
# 水星
self
.
venus
,
# 金星
self
.
earth
,
# 地球
self
.
mars
,
# 火星
self
.
jupiter
,
# 木星
self
.
saturn
,
# 土星
...
...
@@ -55,6 +56,11 @@ class HalleyCometSim:
self
.
neptune
,
# 海王星
# self.pluto, # 冥王星
]
self
.
bodies
=
[
self
.
sun
,
# 太阳
self
.
mars
,
# 火星
self
.
neptune
,
# 海王星
]
# endregion
init_bodies_reality_pos_vels
(
self
.
bodies
)
...
...
@@ -81,7 +87,7 @@ class HalleyCometSim:
def
build
(
self
):
self
.
build_solar_system
()
self
.
build_halley_comet
()
#
self.build_halley_comet()
def
calculate_rotation_angles
(
self
,
point1
,
point2
):
dx
=
point2
.
x
-
point1
.
x
...
...
@@ -107,13 +113,13 @@ class HalleyCometSim:
return
angle_x
,
angle_y
,
angle_z
def
calculate_angles
(
self
,
point1
,
point2
):
import
numpy
as
np
# 计算向量AB
AB
=
point2
-
point1
# 计算向量AB与x轴、y轴和z轴之间的夹角
angle_x
=
np
.
degrees
(
np
.
arctan2
(
AB
.
y
,
AB
.
x
))
angle_y
=
np
.
degrees
(
np
.
arctan2
(
AB
.
z
,
np
.
sqrt
(
AB
.
x
**
2
+
AB
.
y
**
2
)
))
angle_z
=
np
.
degrees
(
np
.
arctan2
(
np
.
sqrt
(
AB
.
x
**
2
+
AB
.
y
**
2
),
AB
.
z
))
angle_x
=
math
.
degrees
(
math
.
atan2
(
AB
.
z
,
AB
.
y
))
angle_y
=
math
.
degrees
(
math
.
atan2
(
AB
.
z
,
AB
.
x
))
angle_z
=
math
.
degrees
(
math
.
atan2
(
AB
.
y
,
AB
.
x
))
return
angle_x
,
angle_y
,
angle_z
def
on_ready
(
self
):
...
...
@@ -125,6 +131,7 @@ class HalleyCometSim:
from
ursina
import
scene
UrsinaConfig
.
trail_type
=
"line"
UrsinaConfig
.
trail_length
=
91
UrsinaConfig
.
trail_length
=
1000
UrsinaConfig
.
trail_thickness_factor
=
3
# camera.clip_plane_near = 0.1
camera
.
clip_plane_far
=
1000000
...
...
@@ -167,9 +174,9 @@ body.position - sun.position
# orbit_line.rotation_y = rotation_y + 120
# #
# angle = math.atan2(relative_position.y, relative_position.x)
orbit_line
.
rotation_x
=
angle_x
+
90
orbit_line
.
rotation_y
=
angle_y
+
18
0
orbit_line
.
rotation_z
=
angle_z
orbit_line
.
rotation_x
=
angle_x
orbit_line
.
rotation_y
=
angle_y
# - 5
0
orbit_line
.
rotation_z
=
-
angle_z
orbit_line
.
body
=
body
...
...
@@ -183,14 +190,15 @@ body.position - sun.position
@param time_data:
@return:
"""
# 哈雷彗星飞行的翻转效果
if
self
.
halley_comet
.
planet
.
enabled
:
self
.
halley_comet
.
planet
.
rotation_x
+=
0.1
self
.
halley_comet
.
planet
.
rotation_y
+=
1
# 摄像机始终看向哈雷彗星
# camera_look_at(self.halley_comet)
d
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
sun
.
position
)
self
.
text_panel
.
text
=
"哈雷彗星距离太阳:%.3f AU"
%
(
d
/
AU
)
if
hasattr
(
self
,
"self.halley_comet"
):
# 哈雷彗星飞行的翻转效果
if
self
.
halley_comet
.
planet
.
enabled
:
self
.
halley_comet
.
planet
.
rotation_x
+=
0.1
self
.
halley_comet
.
planet
.
rotation_y
+=
1
# 摄像机始终看向哈雷彗星
# camera_look_at(self.halley_comet)
d
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
sun
.
position
)
self
.
text_panel
.
text
=
"哈雷彗星距离太阳:%.3f AU"
%
(
d
/
AU
)
for
i
,
orbit_line
in
enumerate
(
self
.
orbit_lines
):
if
i
<
4
:
...
...
@@ -207,6 +215,9 @@ if __name__ == '__main__':
"""
sim
=
HalleyCometSim
()
sim
.
build
()
# 订阅事件后,上面2个函数功能才会起作用
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent
.
on_timer_changed_subscription
(
sim
.
on_timer_changed
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录