Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
2a54d430
宇宙模拟器
项目概览
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看板
提交
2a54d430
编写于
4月 22, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
ceac7abc
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
43 addition
and
4 deletion
+43
-4
common/system.py
common/system.py
+41
-1
sim_scenes/science/jupiter_rocks.py
sim_scenes/science/jupiter_rocks.py
+2
-3
未找到文件。
common/system.py
浏览文件 @
2a54d430
...
@@ -142,11 +142,34 @@ class System(object):
...
@@ -142,11 +142,34 @@ class System(object):
with
open
(
json_file_name
,
"w"
,
encoding
=
'utf-8'
)
as
f
:
with
open
(
json_file_name
,
"w"
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
json_str
)
f
.
write
(
json_str
)
def
fast_calc
(
self
):
"""
快速计算(对于天体过多会导致性能急速下降,这样就需要使用快速算法)
@return: 如果为True,则快速计算成功
"""
# return False
if
not
hasattr
(
self
,
"fast_calc_list"
):
return
False
if
len
(
self
.
fast_calc_list
)
==
0
:
return
for
body1
in
self
.
fast_calc_list
.
keys
():
acceleration
=
np
.
zeros
(
3
)
for
body2
in
self
.
fast_calc_list
[
body1
]:
r
=
body2
.
position
-
body1
.
position
if
np
.
linalg
.
norm
(
r
)
>
0.0
:
acceleration
+=
(
G
*
body2
.
mass
*
r
/
np
.
linalg
.
norm
(
r
)
**
3
)
/
1e9
body1
.
acceleration
=
acceleration
return
True
def
calc_bodies_acceleration
(
self
):
def
calc_bodies_acceleration
(
self
):
"""
"""
计算加速度
计算加速度
@return:
@return:
"""
"""
# 如果快速计算成功,则无需再计算
if
self
.
fast_calc
():
return
def
valid_body
(
body
):
def
valid_body
(
body
):
"""
"""
...
@@ -165,7 +188,13 @@ class System(object):
...
@@ -165,7 +188,13 @@ class System(object):
return
True
return
True
# self.bodies = list(filter(valid_body, self.bodies))
# self.bodies = list(filter(valid_body, self.bodies))
valid_bodies
=
list
(
filter
(
lambda
b
:
not
b
.
ignore_mass
,
self
.
bodies
))
valid_bodies
=
list
(
filter
(
lambda
b
:
not
b
.
ignore_mass
,
self
.
bodies
))
# 如果需要计算的天体超过了10个,则启用快速算法
if
len
(
valid_bodies
)
>
10
:
if
not
hasattr
(
self
,
"fast_calc_list"
):
self
.
fast_calc_list
=
{}
for
body1
in
valid_bodies
:
for
body1
in
valid_bodies
:
# if body1.ignore_mass:
# if body1.ignore_mass:
# continue
# continue
...
@@ -189,6 +218,17 @@ class System(object):
...
@@ -189,6 +218,17 @@ class System(object):
elif
body1
.
ignore_gravity_with
(
body2
)
or
body2
.
ignore_gravity_with
(
body1
):
elif
body1
.
ignore_gravity_with
(
body2
)
or
body2
.
ignore_gravity_with
(
body1
):
continue
continue
if
hasattr
(
self
,
"fast_calc_list"
):
# 构建快速计算列表
if
body1
not
in
self
.
fast_calc_list
:
self
.
fast_calc_list
[
body1
]
=
[]
# 如果 body2 质量太小了,与 body1 悬殊太大,加速度可以忽略不计
if
body1
.
mass
/
body2
.
mass
<
1e10
:
# 10亿倍的差距
self
.
fast_calc_list
[
body1
].
append
(
body2
)
else
:
# print(f"{body2.name}相对{body1.name}质量太小,加速度可以忽略不计!")
continue
r
=
body2
.
position
-
body1
.
position
r
=
body2
.
position
-
body1
.
position
# G = 6.67e-11 # 万有引力常数
# G = 6.67e-11 # 万有引力常数
# m/s² = kg * m / m**3
# m/s² = kg * m / m**3
...
...
sim_scenes/science/jupiter_rocks.py
浏览文件 @
2a54d430
...
@@ -29,12 +29,11 @@ if __name__ == '__main__':
...
@@ -29,12 +29,11 @@ if __name__ == '__main__':
rocks
=
[]
rocks
=
[]
r
=
jupiter
.
raduis
r
=
jupiter
.
raduis
for
i
in
range
(
2
0
):
for
i
in
range
(
3
0
):
# 随机生成岩石位置和初始速度信息
# 随机生成岩石位置和初始速度信息
pos
=
[
-
r
*
random
.
randint
(
120
,
200
)
/
100
,
pos
=
[
-
r
*
random
.
randint
(
120
,
200
)
/
100
,
-
r
*
random
.
randint
(
120
,
200
)
/
1000
,
-
r
*
random
.
randint
(
120
,
200
)
/
1000
,
-
r
*
random
.
randint
(
150
,
350
)
/
100
-
r
*
random
.
randint
(
150
,
350
)
/
100
]
]
# 随机速度
# 随机速度
vel
=
[
0
,
-
random
.
randint
(
90
,
200
)
/
30
,
0
]
vel
=
[
0
,
-
random
.
randint
(
90
,
200
)
/
30
,
0
]
size_scale
=
random
.
randint
(
400
,
600
)
size_scale
=
random
.
randint
(
400
,
600
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录