Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
5b1c93ef
宇宙模拟器
项目概览
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看板
提交
5b1c93ef
编写于
4月 25, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
2386ae12
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
18 deletion
+23
-18
sim_lab/research_calc.py
sim_lab/research_calc.py
+17
-14
simulators/calc_simulator.py
simulators/calc_simulator.py
+6
-4
未找到文件。
sim_lab/research_calc.py
浏览文件 @
5b1c93ef
...
@@ -7,10 +7,8 @@
...
@@ -7,10 +7,8 @@
# python_version :3.8
# python_version :3.8
# ==============================================================================
# ==============================================================================
from
bodies
import
Body
,
Sun
,
Earth
,
Moon
from
bodies
import
Body
,
Sun
,
Earth
,
Moon
from
objs
import
Obj
from
objs
import
Obj
,
Satellite
,
Satellite2
from
objs
import
Satellite
,
Satellite2
from
common.consts
import
SECONDS_PER_HOUR
,
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
,
SECONDS_PER_MONTH
from
common.consts
import
SECONDS_PER_HOUR
,
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
,
SECONDS_PER_MONTH
from
sim_scenes.func
import
calc_run
from
bodies.body
import
AU
from
bodies.body
import
AU
...
@@ -41,27 +39,30 @@ bodies = [
...
@@ -41,27 +39,30 @@ bodies = [
]
]
earth
=
bodies
[
0
]
earth
=
bodies
[
0
]
moon
=
bodies
[
1
]
moon
=
bodies
[
1
]
points
=
get_lagrangian_points
(
earth
.
mass
,
moon
.
mass
,
363104
)
L1_p
,
L2_p
,
L3_p
,
L4_p
,
L5_p
=
get_lagrangian_points
(
earth
.
mass
,
moon
.
mass
,
363104
)
L1_point
=
points
[
0
]
point_z
=
L1_p
[
2
]
+
3301.0505
# 越大,离月球越近
point_z
=
L1_point
[
2
]
+
3301.0505
# 越大,离月球越近
init_velocity
=
[
-
0.890211
,
0
,
0
]
init_velocity
=
[
-
0.890211
,
0
,
0
]
satellite
=
Satellite
(
name
=
f
'卫星'
,
mass
=
1.4e10
,
size_scale
=
1e3
,
color
=
(
255
,
200
,
0
),
satellite
=
Satellite
(
name
=
f
'卫星'
,
mass
=
1.4e10
,
size_scale
=
1e3
,
color
=
(
255
,
200
,
0
),
init_position
=
[
L1_p
oint
[
0
],
L1_point
[
1
],
point_z
],
init_position
=
[
L1_p
[
0
],
L1_p
[
1
],
point_z
],
init_velocity
=
init_velocity
,
gravity_only_for
=
[
earth
,
moon
])
init_velocity
=
init_velocity
,
gravity_only_for
=
[
earth
,
moon
])
bodies
.
append
(
satellite
)
bodies
.
append
(
satellite
)
def
calc_simulator
():
def
calc_simulator
(
target
):
from
sim_scenes.func
import
calc_run
from
simulators.calc_simulator
import
CalcSimulator
,
CalcContext
from
simulators.calc_simulator
import
CalcSimulator
,
CalcContext
CalcSimulator
.
init
(
True
)
def
evolve_next
(
context
:
CalcContext
):
def
evolve_next
(
context
:
CalcContext
):
return
context
.
evolve_count
<
500
return
context
.
evolve_count
<
500
def
after_evolve
(
dt
,
context
:
CalcContext
):
def
after_evolve
(
dt
,
context
:
CalcContext
):
target
:
Body
=
context
.
bodies
[
1
]
# target: Body = context.bodies[1] # 月球
# target: Obj = context.bodies[2]
# target: Obj = context.bodies[2]
# 卫星
context
.
init_param
(
"acc_values"
,
[]).
params
[
"acc_values"
].
append
(
target
.
acceleration_value
())
context
.
init_param
(
"acc_values"
,
[]).
append
(
target
.
acceleration_value
())
context
.
init_param
(
"vel_values"
,
[]).
params
[
"vel_values"
].
append
(
target
.
velocity_value
())
context
.
init_param
(
"vel_values"
,
[]).
append
(
target
.
velocity_value
())
print
(
satellite
.
acceleration_value
(),
satellite
.
velocity_value
())
print
(
satellite
.
acceleration_value
(),
satellite
.
velocity_value
())
...
@@ -80,7 +81,7 @@ def calc_simulator():
...
@@ -80,7 +81,7 @@ def calc_simulator():
ax1
.
set_ylabel
(
'加速度'
,
fontdict
=
{
'weight'
:
'normal'
,
'size'
:
15
,
'color'
:
'blue'
})
ax1
.
set_ylabel
(
'加速度'
,
fontdict
=
{
'weight'
:
'normal'
,
'size'
:
15
,
'color'
:
'blue'
})
# ax1.set_title("加速度/速度", fontdict={'weight': 'normal', 'size': 15})
# ax1.set_title("加速度/速度", fontdict={'weight': 'normal', 'size': 15})
plt
.
title
(
"%s max:%.4f mix:%.4f diff:%.4f"
%
(
plt
.
title
(
"%s max:%.4f mix:%.4f diff:%.4f"
%
(
moon
.
init_velocity
[
0
],
max_value
*
1e6
,
min_value
*
1e6
,
(
max_value
-
min_value
)
*
1e6
))
vel_values
[
0
],
max_value
*
1e6
,
min_value
*
1e6
,
(
max_value
-
min_value
)
*
1e6
))
l1
=
ax1
.
legend
(
loc
=
'lower left'
,
labels
=
[
'加速度'
])
l1
=
ax1
.
legend
(
loc
=
'lower left'
,
labels
=
[
'加速度'
])
ax2
=
ax1
.
twinx
()
# this is the important function
ax2
=
ax1
.
twinx
()
# this is the important function
...
@@ -132,5 +133,7 @@ def ursina_simulator():
...
@@ -132,5 +133,7 @@ def ursina_simulator():
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
calc_simulator
()
calc_simulator
(
earth
)
calc_simulator
(
moon
)
calc_simulator
(
satellite
)
# ursina_simulator()
# ursina_simulator()
simulators/calc_simulator.py
浏览文件 @
5b1c93ef
...
@@ -30,7 +30,7 @@ class CalcView(BodyView):
...
@@ -30,7 +30,7 @@ class CalcView(BodyView):
pass
pass
class
CalcContext
(
Singleton
)
:
class
CalcContext
:
def
__init__
(
self
,
simulator
):
def
__init__
(
self
,
simulator
):
self
.
simulator
=
simulator
self
.
simulator
=
simulator
self
.
evolve_count
=
0
self
.
evolve_count
=
0
...
@@ -47,7 +47,7 @@ class CalcContext(Singleton):
...
@@ -47,7 +47,7 @@ class CalcContext(Singleton):
"""
"""
if
key
not
in
self
.
_params
:
if
key
not
in
self
.
_params
:
self
.
put_param
(
key
,
value
)
self
.
put_param
(
key
,
value
)
return
self
return
self
.
params
[
key
]
@
property
@
property
def
bodies
(
self
)
->
[]:
def
bodies
(
self
)
->
[]:
...
@@ -87,8 +87,8 @@ class CalcSimulator(Simulator):
...
@@ -87,8 +87,8 @@ class CalcSimulator(Simulator):
"""
"""
@
staticmethod
@
staticmethod
def
init
():
def
init
(
reset
=
False
):
if
hasattr
(
CalcSimulator
,
"on_reset_funcs"
):
if
hasattr
(
CalcSimulator
,
"on_reset_funcs"
)
and
not
reset
:
return
return
# 重启运行的订阅事件
# 重启运行的订阅事件
CalcSimulator
.
on_reset_funcs
=
[]
CalcSimulator
.
on_reset_funcs
=
[]
...
@@ -178,6 +178,8 @@ class CalcSimulator(Simulator):
...
@@ -178,6 +178,8 @@ class CalcSimulator(Simulator):
c
.
evolve_count
=
0
c
.
evolve_count
=
0
CalcSimulator
.
on_reset_subscription
(
on_reset
)
CalcSimulator
.
on_reset_subscription
(
on_reset
)
CalcSimulator
.
on_ready_subscription
(
on_reset
)
context
=
CalcContext
(
self
)
context
=
CalcContext
(
self
)
CalcSimulator
.
on_ready
(
context
)
CalcSimulator
.
on_ready
(
context
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录