Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
dd015040
宇宙模拟器
项目概览
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看板
提交
dd015040
编写于
7月 23, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
f17979f8
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
78 addition
and
3 deletion
+78
-3
sim_scenes/solar_system/solar_system_reality.py
sim_scenes/solar_system/solar_system_reality.py
+78
-3
未找到文件。
sim_scenes/solar_system/solar_system_reality.py
浏览文件 @
dd015040
...
@@ -20,6 +20,7 @@ from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, AU
...
@@ -20,6 +20,7 @@ from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, AU
from
sim_scenes.func
import
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_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
ursina
import
camera
from
ursina
import
camera
...
@@ -53,9 +54,70 @@ def get_bodies_names(bodies):
...
@@ -53,9 +54,70 @@ def get_bodies_names(bodies):
names
+=
body
.
__class__
.
__name__
+
","
names
+=
body
.
__class__
.
__name__
+
","
return
names
[
0
:
-
1
]
return
names
[
0
:
-
1
]
def
are_planets_in_line
(
positions
,
line_width
):
# 检查行星的数量是否足够判断是否在一条线上
if
len
(
positions
)
<
3
:
return
False
# 获取第一个行星的坐标
x1
,
y1
,
z1
=
positions
[
0
]
# 计算行星之间的向量差
dx
=
positions
[
1
][
0
]
-
x1
dy
=
positions
[
1
][
1
]
-
y1
dz
=
positions
[
1
][
2
]
-
z1
# 计算线的宽度的平方
line_width_squared
=
line_width
**
2
# 遍历剩余的行星
for
i
in
range
(
2
,
len
(
positions
)):
# 获取当前行星的坐标
x
,
y
,
z
=
positions
[
i
]
# 计算当前行星与第一个行星之间的向量差
current_dx
=
x
-
x1
current_dy
=
y
-
y1
current_dz
=
z
-
z1
# 计算当前行星与线之间的距离的平方
distance_squared
=
(
current_dy
*
dz
-
current_dz
*
dy
)
**
2
+
(
current_dz
*
dx
-
current_dx
*
dz
)
**
2
+
(
current_dx
*
dy
-
current_dy
*
dx
)
**
2
# 如果距离的平方大于线的宽度的平方,则行星不在一条线上
if
distance_squared
>
line_width_squared
:
return
False
# 所有行星都在一条线上
return
True
def
are_planets_in_line
(
planets
,
line_width
):
if
len
(
planets
)
<
2
:
return
False
x_coords
=
[
planet
[
0
]
for
planet
in
planets
]
y_coords
=
[
planet
[
1
]
for
planet
in
planets
]
z_coords
=
[
planet
[
2
]
for
planet
in
planets
]
x_diff
=
[
abs
(
x2
-
x1
)
for
(
x1
,
x2
)
in
zip
(
x_coords
,
x_coords
[
1
:])]
y_diff
=
[
abs
(
y2
-
y1
)
for
(
y1
,
y2
)
in
zip
(
y_coords
,
y_coords
[
1
:])]
z_diff
=
[
abs
(
z2
-
z1
)
for
(
z1
,
z2
)
in
zip
(
z_coords
,
z_coords
[
1
:])]
widths
=
[
max
(
d1
,
d2
,
line_width
)
for
(
d1
,
d2
)
in
zip
(
x_diff
,
y_diff
)]
+
[
line_width
]
+
[
max
(
d1
,
d2
,
line_width
)
for
(
d1
,
d2
)
in
zip
(
x_diff
[::
-
1
],
y_diff
[::
-
1
])]
return
all
(
w
==
widths
[
0
]
for
w
in
widths
)
def
are_planets_in_line
(
planets
,
line_width
):
if
len
(
planets
)
<
2
:
return
False
x_coords
=
[
planet
[
0
]
for
planet
in
planets
]
y_coords
=
[
planet
[
1
]
for
planet
in
planets
]
z_coords
=
[
planet
[
2
]
for
planet
in
planets
]
x_diff
=
[
abs
(
x2
-
x1
)
for
(
x1
,
x2
)
in
zip
(
x_coords
,
x_coords
[
1
:])]
y_diff
=
[
abs
(
y2
-
y1
)
for
(
y1
,
y2
)
in
zip
(
y_coords
,
y_coords
[
1
:])]
z_diff
=
[
abs
(
z2
-
z1
)
for
(
z1
,
z2
)
in
zip
(
z_coords
,
z_coords
[
1
:])]
widths
=
[
max
(
d1
,
d2
,
line_width
**
2
)
for
(
d1
,
d2
)
in
zip
(
x_diff
,
y_diff
)]
+
[
line_width
**
2
]
+
[
max
(
d1
,
d2
,
line_width
**
2
)
for
(
d1
,
d2
)
in
zip
(
x_diff
[::
-
1
],
y_diff
[::
-
1
])]
return
all
(
w
==
widths
[
0
]
for
w
in
widths
)
current_time
=
Time
.
now
()
current_time
=
Time
.
now
()
in_line_datetimes
=
[]
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
# 八大行星:木星(♃)、土星(♄)、天王星(♅)、海王星(♆)、地球(⊕)、金星(♀)、火星(♂)、水星(☿)
# 八大行星:木星(♃)、土星(♄)、天王星(♅)、海王星(♆)、地球(⊕)、金星(♀)、火星(♂)、水星(☿)
# 排列顺序
# 排列顺序
...
@@ -73,7 +135,7 @@ if __name__ == '__main__':
...
@@ -73,7 +135,7 @@ if __name__ == '__main__':
Earth
(
name
=
"地球"
,
size_scale
=
1e3
),
# 地球
Earth
(
name
=
"地球"
,
size_scale
=
1e3
),
# 地球
Moon
(
name
=
"月球"
,
size_scale
=
2e3
),
# 月球
Moon
(
name
=
"月球"
,
size_scale
=
2e3
),
# 月球
Mars
(
name
=
"火星"
,
size_scale
=
1.2e3
),
# 火星
Mars
(
name
=
"火星"
,
size_scale
=
1.2e3
),
# 火星
Asteroids
(
size_scale
=
1e2
,
parent
=
sun
,
rotate_angle
=-
20
),
#
Asteroids(size_scale=1e2, parent=sun, rotate_angle=-20),
Jupiter
(
name
=
"木星"
,
size_scale
=
4e2
),
# 木星
Jupiter
(
name
=
"木星"
,
size_scale
=
4e2
),
# 木星
Saturn
(
name
=
"土星"
,
size_scale
=
4e2
),
# 土星
Saturn
(
name
=
"土星"
,
size_scale
=
4e2
),
# 土星
Uranus
(
name
=
"天王星"
,
size_scale
=
10e2
),
# 天王星
Uranus
(
name
=
"天王星"
,
size_scale
=
10e2
),
# 天王星
...
@@ -99,12 +161,12 @@ if __name__ == '__main__':
...
@@ -99,12 +161,12 @@ if __name__ == '__main__':
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
posvels
=
get_bodies_posvels
(
names
,
t
)
#
posvels = get_bodies_posvels(names, t)
# earth_loc = None
# earth_loc = None
earth_pos
=
None
earth_pos
=
None
sun_pos
=
None
sun_pos
=
None
positions
=
[]
for
body
in
bodies
:
for
body
in
bodies
:
if
isinstance
(
body
,
Asteroids
):
if
isinstance
(
body
,
Asteroids
):
posvel
=
None
posvel
=
None
else
:
else
:
...
@@ -124,6 +186,11 @@ if __name__ == '__main__':
...
@@ -124,6 +186,11 @@ if __name__ == '__main__':
[
posvel
[
1
].
x
.
value
*
AU
/
S_OF_D
,
posvel
[
1
].
z
.
value
*
AU
/
S_OF_D
,
[
posvel
[
1
].
x
.
value
*
AU
/
S_OF_D
,
posvel
[
1
].
z
.
value
*
AU
/
S_OF_D
,
posvel
[
1
].
y
.
value
*
AU
/
S_OF_D
]
posvel
[
1
].
y
.
value
*
AU
/
S_OF_D
]
if
isinstance
(
body
,
Asteroids
)
or
isinstance
(
body
,
Moon
)
or
isinstance
(
body
,
Sun
):
pass
else
:
positions
.
append
(
position
)
body
.
position
=
np
.
array
(
position
)
body
.
position
=
np
.
array
(
position
)
body
.
velocity
=
np
.
array
(
velocity
)
body
.
velocity
=
np
.
array
(
velocity
)
if
isinstance
(
body
,
Earth
):
if
isinstance
(
body
,
Earth
):
...
@@ -133,6 +200,14 @@ if __name__ == '__main__':
...
@@ -133,6 +200,14 @@ if __name__ == '__main__':
sun_pos
=
posvel
[
0
]
sun_pos
=
posvel
[
0
]
dt
=
time_data
.
get_datetime
(
str
(
current_time
))
dt
=
time_data
.
get_datetime
(
str
(
current_time
))
# if len(in_line_datetimes) == 0:
# in_line = are_planets_in_line(positions, 5*AU)
# if in_line:
# in_line_datetimes.append(dt.strftime('%Y-%m-%d %H:%M:%S'))
# print(in_line_datetimes)
# UrsinaConfig.seconds_per = 1
# print(time_data.get_datetime(str(current_time)))
# print(time_data.get_datetime(str(current_time)))
ControlUI
.
current_ui
.
show_message
(
dt
.
strftime
(
'%Y-%m-%d %H:%M:%S'
),
ControlUI
.
current_ui
.
show_message
(
dt
.
strftime
(
'%Y-%m-%d %H:%M:%S'
),
font
=
"verdana.ttf"
,
font
=
"verdana.ttf"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录