Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
87c7cc14
宇宙模拟器
项目概览
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看板
提交
87c7cc14
编写于
7月 11, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
e6abe7d3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
35 addition
and
3 deletion
+35
-3
common/system.py
common/system.py
+33
-1
sim_lab/speed_of_light_3d_speed.py
sim_lab/speed_of_light_3d_speed.py
+1
-1
sim_scenes/science/jupiter_moon_protects_earth.py
sim_scenes/science/jupiter_moon_protects_earth.py
+1
-1
未找到文件。
common/system.py
浏览文件 @
87c7cc14
...
...
@@ -7,6 +7,7 @@
# python_version :3.8
# ==============================================================================
import
numpy
as
np
from
numpy.linalg
import
norm
import
math
from
common.consts
import
AU
,
G
from
bodies
import
Body
,
Sun
,
Mercury
,
Venus
,
Earth
,
Mars
,
Jupiter
,
Saturn
,
Uranus
,
Neptune
,
Pluto
...
...
@@ -162,9 +163,40 @@ class System(object):
body1
.
acceleration
=
acceleration
return
True
def
calculate_gravitational_accelerations
(
self
,
masses
,
positions
):
'''Params:
- positions: numpy array of size (n,3)
- masses: numpy array of size (n,)
'''
masses
=
np
.
array
(
masses
)
positions
=
np
.
array
(
positions
)
mass_matrix
=
masses
.
reshape
((
1
,
-
1
,
1
))
*
masses
.
reshape
((
-
1
,
1
,
1
))
disps
=
positions
.
reshape
((
1
,
-
1
,
3
))
-
positions
.
reshape
((
-
1
,
1
,
3
))
# displacements
dists
=
norm
(
disps
,
axis
=
2
)
dists
[
dists
==
0
]
=
1
# Avoid divide by zero warnings
forces
=
G
*
disps
*
mass_matrix
/
np
.
expand_dims
(
dists
,
2
)
**
3
return
forces
.
sum
(
axis
=
1
)
/
masses
.
reshape
(
-
1
,
1
)
def
calc_bodies_acceleration
(
self
):
"""
计算加速度
计算加速度(使用矩阵的方式,性能提高很多)
@return:
"""
valid_bodies
=
list
(
filter
(
lambda
b
:
not
b
.
ignore_mass
,
self
.
bodies
))
masses
=
[]
positions
=
[]
for
body
in
valid_bodies
:
masses
.
append
(
body
.
mass
)
positions
.
append
(
body
.
position
*
1000
)
accelerations
=
self
.
calculate_gravitational_accelerations
(
masses
,
positions
)
for
idx
,
body
in
enumerate
(
valid_bodies
):
body
.
acceleration
=
accelerations
[
idx
]
/
1000
def
calc_bodies_acceleration_bak
(
self
):
"""
计算加速度(性能非常低,代码保留)
@return:
"""
# 如果快速计算成功,则无需再计算
...
...
sim_lab/speed_of_light_3d_speed.py
浏览文件 @
87c7cc14
...
...
@@ -8,7 +8,7 @@
# ==============================================================================
import
sys
import
time
from
common.func
import
wait_for
,
calculate_acceleration
from
common.func
import
wait_for
from
common.consts
import
AU
from
sim_scenes.func
import
ursina_run
,
create_solar_system_bodies
,
create_light_ship
,
create_3d_card
from
common.consts
import
LIGHT_SPEED
...
...
sim_scenes/science/jupiter_moon_protects_earth.py
浏览文件 @
87c7cc14
...
...
@@ -202,7 +202,7 @@ if __name__ == '__main__':
# 设置计时器的最小时间单位为年
BodyTimer
().
min_unit
=
BodyTimer
.
MIN_UNIT_YEARS
sim
=
JupiterProtectsEarthSim
(
comet_num
=
2
0
)
sim
=
JupiterProtectsEarthSim
(
comet_num
=
5
0
)
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
sim
.
on_ready
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录