Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
太阳系三体模拟器
提交
137be76b
太阳系三体模拟器
项目概览
Python_超人
/
太阳系三体模拟器
通知
1444
Star
136
Fork
134
代码
文件
提交
分支
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看板
提交
137be76b
编写于
2月 10, 2023
作者:
M
march3
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
三体运行模拟器
上级
2ff34fdc
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
147 addition
and
4 deletion
+147
-4
bodies/body.py
bodies/body.py
+3
-0
bodies/saturn.py
bodies/saturn.py
+8
-0
simulators/mayavi_simulator.py
simulators/mayavi_simulator.py
+1
-1
simulators/mpl_simulator.py
simulators/mpl_simulator.py
+1
-1
simulators/simulator.py
simulators/simulator.py
+2
-0
simulators/views/__init__.py
simulators/views/__init__.py
+0
-0
simulators/views/body_view.py
simulators/views/body_view.py
+1
-1
simulators/views/mayavi_view.py
simulators/views/mayavi_view.py
+130
-0
simulators/views/mpl_view.py
simulators/views/mpl_view.py
+1
-1
未找到文件。
bodies/body.py
浏览文件 @
137be76b
...
@@ -14,6 +14,9 @@ from common.consts import AU
...
@@ -14,6 +14,9 @@ from common.consts import AU
class
Body
(
metaclass
=
ABCMeta
):
class
Body
(
metaclass
=
ABCMeta
):
"""
天体信息基类
"""
def
__init__
(
self
,
name
,
mass
,
init_position
,
init_velocity
,
def
__init__
(
self
,
name
,
mass
,
init_position
,
init_velocity
,
density
=
5e3
,
color
=
(
125
/
255
,
125
/
255
,
125
/
255
),
density
=
5e3
,
color
=
(
125
/
255
,
125
/
255
,
125
/
255
),
texture
=
None
,
size_scale
=
1.0
,
distance_scale
=
1.0
):
texture
=
None
,
size_scale
=
1.0
,
distance_scale
=
1.0
):
...
...
bodies/saturn.py
浏览文件 @
137be76b
...
@@ -46,6 +46,14 @@ class Saturn(Body):
...
@@ -46,6 +46,14 @@ class Saturn(Body):
"""
"""
return
True
return
True
@
property
def
rings_color
(
self
):
"""
土星光环的颜色
:return:
"""
return
173
,
121
,
92
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
saturn
=
Saturn
()
saturn
=
Saturn
()
...
...
simulators/mayavi_simulator.py
浏览文件 @
137be76b
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
from
mayavi
import
mlab
from
mayavi
import
mlab
from
simulators.simulator
import
Simulator
from
simulators.simulator
import
Simulator
from
common.system
import
System
from
common.system
import
System
from
simulators.view
er
s.mayavi_view
import
MayaviView
from
simulators.views.mayavi_view
import
MayaviView
class
MayaviSimulator
(
Simulator
):
class
MayaviSimulator
(
Simulator
):
...
...
simulators/mpl_simulator.py
浏览文件 @
137be76b
...
@@ -10,7 +10,7 @@ import matplotlib.pyplot as plt
...
@@ -10,7 +10,7 @@ import matplotlib.pyplot as plt
import
matplotlib.animation
as
animation
import
matplotlib.animation
as
animation
from
simulators.simulator
import
Simulator
from
simulators.simulator
import
Simulator
from
common.system
import
System
from
common.system
import
System
from
simulators.view
er
s.mpl_view
import
MplView
from
simulators.views.mpl_view
import
MplView
import
numpy
as
np
import
numpy
as
np
import
time
import
time
...
...
simulators/simulator.py
浏览文件 @
137be76b
...
@@ -54,6 +54,8 @@ class Simulator(metaclass=ABCMeta):
...
@@ -54,6 +54,8 @@ class Simulator(metaclass=ABCMeta):
view
.
his_position
=
body
.
his_position
()
view
.
his_position
=
body
.
his_position
()
view
.
is_fixed_star
=
body
.
is_fixed_star
view
.
is_fixed_star
=
body
.
is_fixed_star
view
.
has_rings
=
body
.
has_rings
view
.
has_rings
=
body
.
has_rings
view
.
size_scale
=
body
.
size_scale
view
.
distance_scale
=
body
.
distance_scale
view
.
update
()
view
.
update
()
...
...
simulators/view
er
s/__init__.py
→
simulators/views/__init__.py
浏览文件 @
137be76b
文件已移动
simulators/view
er
s/body_view.py
→
simulators/views/body_view.py
浏览文件 @
137be76b
...
@@ -29,7 +29,7 @@ class BodyView(metaclass=ABCMeta):
...
@@ -29,7 +29,7 @@ class BodyView(metaclass=ABCMeta):
self
.
color
=
tuple
(
np
.
array
(
body
.
color
)
/
255
)
self
.
color
=
tuple
(
np
.
array
(
body
.
color
)
/
255
)
else
:
else
:
self
.
color
=
self
.
__get_texture_main_color
(
self
.
texture
)
self
.
color
=
self
.
__get_texture_main_color
(
self
.
texture
)
self
.
sphere
=
self
.
appear
()
self
.
appear
()
self
.
position
=
[
None
,
None
,
None
]
self
.
position
=
[
None
,
None
,
None
]
self
.
name
=
None
self
.
name
=
None
self
.
mass
=
None
self
.
mass
=
None
...
...
simulators/view
er
s/mayavi_view.py
→
simulators/views/mayavi_view.py
浏览文件 @
137be76b
...
@@ -12,7 +12,7 @@ import os
...
@@ -12,7 +12,7 @@ import os
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
from
common.func
import
get_dominant_colors
from
common.func
import
get_dominant_colors
from
simulators.view
er
s.body_view
import
BodyView
from
simulators.views.body_view
import
BodyView
import
numpy
as
np
import
numpy
as
np
...
@@ -23,48 +23,59 @@ class MayaviView(BodyView):
...
@@ -23,48 +23,59 @@ class MayaviView(BodyView):
def
update
(
self
):
def
update
(
self
):
"""
"""
更新天体信息和数据,比如:更新天体的位置
:return:
:return:
"""
"""
x_offset
=
self
.
body
.
position
[
0
]
-
self
.
sphere
.
mlab_source
.
x
if
hasattr
(
self
.
sphere
,
"mlab_source"
):
y_offset
=
self
.
body
.
position
[
1
]
-
self
.
sphere
.
mlab_source
.
y
x_offset
=
self
.
body
.
position
[
0
]
-
self
.
sphere
.
mlab_source
.
x
z_offset
=
self
.
body
.
position
[
2
]
-
self
.
sphere
.
mlab_source
.
z
y_offset
=
self
.
body
.
position
[
1
]
-
self
.
sphere
.
mlab_source
.
y
z_offset
=
self
.
body
.
position
[
2
]
-
self
.
sphere
.
mlab_source
.
z
self
.
sphere
.
mlab_source
.
set
(
x
=
self
.
position
[
0
],
y
=
self
.
position
[
1
],
z
=
self
.
position
[
2
])
self
.
sphere
.
mlab_source
.
set
(
x
=
self
.
position
[
0
],
y
=
self
.
position
[
1
],
z
=
self
.
position
[
2
])
return
x_offset
[
0
],
y_offset
[
0
],
z_offset
[
0
]
else
:
x_offset
,
y_offset
,
z_offset
=
0
,
0
,
0
# def __find_texture(self, texture):
# """
if
hasattr
(
self
,
"rings"
):
# 在多路径下寻找纹理图片
if
hasattr
(
self
.
rings
,
"mlab_source"
):
# :param texture: 纹理图片
if
hasattr
(
self
,
"rings"
)
and
self
.
body
.
has_rings
:
# :return: 纹理图片的路径
x
=
self
.
rings
.
mlab_source
.
x
# """
y
=
self
.
rings
.
mlab_source
.
y
# paths = ['./textures', '../textures']
z
=
self
.
rings
.
mlab_source
.
z
# for path in paths:
self
.
rings
.
mlab_source
.
set
(
x
=
x
+
x_offset
,
y
=
y
+
y_offset
,
z
=
z
+
z_offset
)
# p = path + "/" + texture
# if os.path.exists(p):
# return x_offset[0], y_offset[0], z_offset[0]
# return p
#
def
build_rings
(
self
):
# return None
if
not
hasattr
(
self
,
"rings"
)
or
self
.
rings
is
None
:
#
# def __texture_to_color(self, texture):
R
=
2
# """
r
=
0.3
# 根据纹理图片获取颜色
rings_scale
=
0.5e5
# :param texture:
resolution
=
50
# :return:
theta
=
np
.
linspace
(
0
,
2
*
np
.
pi
,
resolution
)
# """
phi
=
np
.
linspace
(
0
,
2
*
np
.
pi
,
resolution
)
# colors = get_dominant_colors(texture)
torus
=
np
.
zeros
((
3
,
resolution
,
resolution
))
# first_color = colors[0]
# # print(self.name, first_color)
for
i
in
range
(
0
,
resolution
):
# return tuple(np.array(first_color) / 255)
for
j
in
range
(
0
,
resolution
):
# size_scale=8.0e2
torus
[
0
][
i
][
j
]
=
(
R
+
r
*
np
.
cos
(
phi
[
j
]))
*
np
.
cos
(
theta
[
i
])
*
\
self
.
body
.
size_scale
*
rings_scale
+
self
.
body
.
position
[
0
]
torus
[
1
][
i
][
j
]
=
(
R
+
r
*
np
.
cos
(
phi
[
j
]))
*
np
.
sin
(
theta
[
i
])
*
\
self
.
body
.
size_scale
*
rings_scale
+
self
.
body
.
position
[
1
]
torus
[
2
][
i
][
j
]
=
1
*
np
.
sin
(
phi
[
j
])
+
self
.
body
.
position
[
2
]
rings_color
=
(
173
/
255
,
121
/
255
,
92
/
255
)
if
hasattr
(
self
.
body
,
"rings_color"
):
rings_color
=
tuple
(
np
.
array
(
self
.
body
.
rings_color
)
/
255
)
self
.
rings
=
mlab
.
mesh
(
torus
[
0
],
torus
[
1
],
torus
[
2
],
color
=
rings_color
,
representation
=
'surface'
)
return
self
.
rings
def
appear
(
self
):
def
appear
(
self
):
"""
"""
构建球体
对象
天体显示的操作,比如:构建天体视图
对象
:return:
:return:
"""
"""
if
not
hasattr
(
self
,
"sphere"
)
or
self
.
sphere
is
None
:
if
not
hasattr
(
self
,
"sphere"
)
or
self
.
sphere
is
None
:
scale_factor
=
self
.
body
.
size_scale
*
self
.
body
.
raduis
scale_factor
=
self
.
body
.
size_scale
*
self
.
body
.
diameter
sphere
=
mlab
.
points3d
(
self
.
body
.
position
[
0
],
self
.
body
.
position
[
1
],
self
.
body
.
position
[
2
],
sphere
=
mlab
.
points3d
(
self
.
body
.
position
[
0
],
self
.
body
.
position
[
1
],
self
.
body
.
position
[
2
],
scale_factor
=
scale_factor
,
scale_factor
=
scale_factor
,
color
=
self
.
color
,
color
=
self
.
color
,
...
@@ -87,17 +98,30 @@ class MayaviView(BodyView):
...
@@ -87,17 +98,30 @@ class MayaviView(BodyView):
if
self
.
texture
is
not
None
and
self
.
texture
!=
''
:
if
self
.
texture
is
not
None
and
self
.
texture
!=
''
:
self
.
__set_texture
(
self
.
texture
)
self
.
__set_texture
(
self
.
texture
)
pass
return
self
.
sphere
if
self
.
body
.
has_rings
:
self
.
build_rings
()
return
self
.
sphere
,
self
.
rings
return
self
.
sphere
,
def
__set_texture
(
self
,
image_file
):
def
__set_texture
(
self
,
image_file
):
if
not
os
.
path
.
exists
(
image_file
):
"""
return
设置纹理图片到天体
img
=
plt
.
imread
(
image_file
)
:param image_file:
:return:
"""
outfile
=
image_file
.
replace
(
'.jpg'
,
'_flipped.jpg'
)
outfile
=
image_file
.
replace
(
'.jpg'
,
'_flipped.jpg'
)
img
=
img
[::
-
1
,
...]
if
os
.
path
.
exists
(
outfile
):
plt
.
imsave
(
outfile
,
img
)
image_file
=
outfile
image_file
=
outfile
else
:
if
not
os
.
path
.
exists
(
image_file
):
return
img
=
plt
.
imread
(
image_file
)
img
=
img
[::
-
1
,
...]
plt
.
imsave
(
outfile
,
img
)
image_file
=
outfile
img
=
tvtk
.
JPEGReader
(
file_name
=
image_file
)
img
=
tvtk
.
JPEGReader
(
file_name
=
image_file
)
texture
=
tvtk
.
Texture
(
input_connection
=
img
.
output_port
,
interpolate
=
0
,
repeat
=
0
)
texture
=
tvtk
.
Texture
(
input_connection
=
img
.
output_port
,
interpolate
=
0
,
repeat
=
0
)
self
.
sphere
.
actor
.
actor
.
texture
=
texture
self
.
sphere
.
actor
.
actor
.
texture
=
texture
...
...
simulators/view
er
s/mpl_view.py
→
simulators/views/mpl_view.py
浏览文件 @
137be76b
...
@@ -10,7 +10,7 @@ import os
...
@@ -10,7 +10,7 @@ import os
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
from
common.func
import
get_dominant_colors
from
common.func
import
get_dominant_colors
from
simulators.view
er
s.body_view
import
BodyView
from
simulators.views.body_view
import
BodyView
import
numpy
as
np
import
numpy
as
np
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录