Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
8a13f772
宇宙模拟器
项目概览
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看板
提交
8a13f772
编写于
10月 28, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
3e5672dc
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
7 addition
and
100 deletion
+7
-100
sim_scenes/solar_system/halley_comet_sim_02.py
sim_scenes/solar_system/halley_comet_sim_02.py
+7
-100
未找到文件。
sim_scenes/solar_system/halley_comet_sim_02.py
浏览文件 @
8a13f772
...
...
@@ -6,25 +6,23 @@
# link :https://gitcode.net/pythoncr/
# python_version :3.9
# ==============================================================================
import
time
import
math
import
pytz
from
ursina
import
camera
,
application
from
astropy.time
import
Time
from
ursina
import
camera
,
application
from
bodies
import
Sun
,
Mercury
,
Venus
,
Earth
,
Mars
,
Jupiter
,
Saturn
,
Uranus
,
Neptune
,
Pluto
from
common.celestial_data_service
import
get_init_pos_vels
,
init_bodies_reality_pos_vels
,
get_reality_orbit_points
,
\
from
common.celestial_data_service
import
init_bodies_reality_pos_vels
,
get_reality_orbit_points
,
\
conv_to_astropy_time
from
common.color_utils
import
trail_color_brightest
from
common.consts
import
SECONDS_PER_YEAR
,
AU
from
common.func
import
calculate_distance
from
objs
import
HalleComet
,
Obj
from
sim_scenes.func
import
c
amera_look_at
,
two_bodies_colliding
,
c
reate_text_panel
from
objs
import
HalleComet
from
sim_scenes.func
import
create_text_panel
from
sim_scenes.func
import
ursina_run
,
create_sphere_sky
from
simulators.ursina.entities.world_grid
import
WorldGrid
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_mesh
import
create_orbit_
line
,
create_orbit_
by_points
from
simulators.ursina.ursina_mesh
import
create_orbit_by_points
class
HalleyCometSim
:
...
...
@@ -92,14 +90,9 @@ class HalleyCometSim:
"""
# 哈雷彗星的平均运行速度约为每小时 70,000 英里或每小时 126,000 公里 。(35公里/秒)
# 每76.1年环绕太阳一周的周期彗星
# 3.335, 0, 10.7 73
# 3.33, 0, 10.7 73
# [3.335, 0, 10.699] 71
# [3.33, 0, 10.655] 68
# [3.33, 0, 10.66] 69
self
.
halley_comet
=
HalleComet
(
# size_scale=4e7,
size_scale
=
1e8
,
init_velocity
=
[
3.34
,
0
,
10.7
],
# [3.33, 0, 10.6] < ? <[3.34, 0, 10.7]
init_velocity
=
[
3.34
,
0
,
10.7
],
init_position
=
[
0
,
0.5
*
AU
,
-
10
*
AU
])
\
.
set_light_disable
(
True
)
...
...
@@ -109,40 +102,6 @@ class HalleyCometSim:
self
.
build_solar_system
()
self
.
build_halley_comet
()
def
calculate_angles
(
self
,
point1
,
point2
):
dx
=
point2
.
x
-
point1
.
x
dy
=
point2
.
y
-
point1
.
y
dz
=
point2
.
z
-
point1
.
z
roll
=
math
.
degrees
(
math
.
atan2
(
dy
,
dz
))
pitch
=
math
.
degrees
(
math
.
atan2
(
dx
,
math
.
sqrt
(
dy
**
2
+
dz
**
2
)))
yaw
=
math
.
degrees
(
math
.
atan2
(
math
.
sin
(
roll
),
math
.
cos
(
roll
)))
return
roll
,
pitch
,
yaw
#
# def calculate_angles(self, point1, point2):
# import numpy as np
# # 计算向量AB
# AB = point1 - point2
#
# # 计算向量AB与x轴、y轴和z轴之间的夹角
# angle_x = np.arctan2(AB.y, AB.x) * 180 / np.pi
# angle_y = np.arctan2(AB.z, np.sqrt(AB.x ** 2 + AB.y ** 2)) * 180 / np.pi
# angle_z = np.arctan2(np.sqrt(AB.x ** 2 + AB.y ** 2), AB.z) * 180 / np.pi
#
# return angle_x, angle_y, angle_z
# def calculate_angles(self, point1, point2):
#
# # 计算向量AB
# AB = point2 - point1
# # 计算向量AB与x轴、y轴和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
create_orbit_line
(
self
,
center_body
,
body
):
orbital_days
=
int
(
math
.
ceil
(
body
.
orbital_days
*
1.02
))
points
=
get_reality_orbit_points
(
type
(
body
).
__name__
.
lower
(),
start_time
=
self
.
dt
,
days
=
orbital_days
,
...
...
@@ -157,7 +116,6 @@ class HalleyCometSim:
@return:
"""
# 创建天空
from
ursina
import
scene
UrsinaConfig
.
trail_type
=
"line"
UrsinaConfig
.
trail_length
=
91
# UrsinaConfig.trail_length = 1000
...
...
@@ -173,56 +131,7 @@ class HalleyCometSim:
for
body
in
self
.
bodies
[
1
:]:
if
isinstance
(
body
,
HalleComet
):
continue
print
(
"create_orbit_line"
,
body
)
"""
# 在 ursina 中,我以 sun.position 为中心, body.position 的所在位置(x,y,z) 画一个圆环(orbit_line)。
到 sun 中心点(x,y,z) 为半径,返回一个圆形轨道 orbit_line
orbit_line = create_orbit_line(sun, body)
# 帮我解决下面的问题,怎么修改下面的值,让 orbit_line 轨道线的倾斜和 body 匹配
orbit_line.rotation_x = ?
orbit_line.rotation_y = ?
orbit_line.rotation_z = ?
body.position - sun.position
"""
orbit_line
=
self
.
create_orbit_line
(
self
.
sun
,
body
)
# # orbit_line.enabled = False
# angle_x, angle_y, angle_z = self.calculate_angles(self.sun.planet.position, body.planet.position)
# # # 获取body相对于self.sun的位置向量
# # relative_position = body.planet.position - self.sun.planet.position
# #
# # rotation_x = -math.degrees(
# # math.atan2(relative_position.y, math.sqrt(relative_position.x ** 2 + relative_position.z ** 2)))
# # rotation_y = math.degrees(math.atan2(relative_position.x, relative_position.z))
# # # 计算旋转角度
# # orbit_line.rotation_x = rotation_x + 90
# # orbit_line.rotation_z = 0
# # orbit_line.rotation_y = rotation_y + 120
# # #
# # angle = math.atan2(relative_position.y, relative_position.x)
# #
# # orbit_line.rotation_x = angle_x - 110 # angle_x+90 # angle_x # angle_x
# # orbit_line.rotation_y = angle_y # angle_y+90 # angle_y # - 50
# # orbit_line.rotation_z = angle_z - 90 # angle_z# angle_z # angle_z
#
# # print(body.name,angle_x,angle_y,angle_z)
# # print(body.name, orbit_line.rotation_x, orbit_line.rotation_y, orbit_line.rotation_z)
# # orbit_line.look_at(body.planet)
# # print(body.name, orbit_line.rotation_x, orbit_line.rotation_y, orbit_line.rotation_z)
# # 火星 -90.0 -90.0 0.0
# # 火星 -0.0 -0.0 0.0
# # 火星 113.2222958819701 137.6691000401162 -158.65250912389882
# # 火星 16.115840911865234 -132.33090209960938 104.18995666503906
#
# # 海王星 -90.0 -90.0 0.0
# # 海王星 -0.0 -0.0 0.0
# # 海王星 131.3906379192235 3.0188762268681826 -2.6611704409164667
# # 海王星 2.6574795246124268 93.01887512207031 -90.14009857177734
# orbit_line.body = body
self
.
orbit_lines
.
append
(
orbit_line
)
self
.
text_panel
=
create_text_panel
()
...
...
@@ -238,8 +147,6 @@ body.position - sun.position
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
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录