Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
太阳系三体模拟器
提交
08c58515
太阳系三体模拟器
项目概览
Python_超人
/
太阳系三体模拟器
通知
1075
Star
131
Fork
128
代码
文件
提交
分支
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看板
提交
08c58515
编写于
3月 12, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
太阳系三体模拟器
上级
34e69c06
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
56 addition
and
20 deletion
+56
-20
common/consts.py
common/consts.py
+4
-0
scenes/earth_moon.py
scenes/earth_moon.py
+5
-7
scenes/solar_system_2.py
scenes/solar_system_2.py
+2
-2
scenes/sun_earth_moon.py
scenes/sun_earth_moon.py
+32
-0
simulators/ursina_simulator.py
simulators/ursina_simulator.py
+7
-4
simulators/views/ursina_view.py
simulators/views/ursina_view.py
+6
-7
未找到文件。
common/consts.py
浏览文件 @
08c58515
...
@@ -37,3 +37,7 @@ SECONDS_PER_WEEK = SECONDS_PER_DAY * 7
...
@@ -37,3 +37,7 @@ SECONDS_PER_WEEK = SECONDS_PER_DAY * 7
一月多少秒(按照30天算)
一月多少秒(按照30天算)
"""
"""
SECONDS_PER_MONTH
=
SECONDS_PER_DAY
*
30
SECONDS_PER_MONTH
=
SECONDS_PER_DAY
*
30
"""
一年多少秒(按照365天算)
"""
SECONDS_PER_YEAR
=
SECONDS_PER_DAY
*
365
scenes/earth_moon.py
浏览文件 @
08c58515
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
# python_version :3.8
# python_version :3.8
# ==============================================================================
# ==============================================================================
from
bodies
import
Sun
,
Earth
,
Moon
from
bodies
import
Sun
,
Earth
,
Moon
from
common.consts
import
SECONDS_PER_HOUR
,
SECONDS_PER_HALF_DAY
,
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
from
common.consts
import
SECONDS_PER_HOUR
,
SECONDS_PER_HALF_DAY
,
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
,
SECONDS_PER_MONTH
from
scenes.func
import
mayavi_run
,
ursina_run
from
scenes.func
import
mayavi_run
,
ursina_run
from
bodies.body
import
AU
from
bodies.body
import
AU
...
@@ -16,17 +16,15 @@ if __name__ == '__main__':
...
@@ -16,17 +16,15 @@ if __name__ == '__main__':
地球、月球
地球、月球
"""
"""
# 地球的Y方向初始速度
# 地球的Y方向初始速度
EARTH_INIT_VELOCITY
=
0
# 200m/s
EARTH_INIT_VELOCITY
=
-
0
# 20m/s
sun
=
Sun
(
init_position
=
[
0
,
AU
,
0
],
init_velocity
=
[
0
,
0
,
0
],
size_scale
=
1e1
)
sun
.
ignore_mass
=
True
bodies
=
[
bodies
=
[
# sun,
# sun,
Earth
(
init_position
=
[
0
,
0
,
0
],
Earth
(
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
EARTH_INIT_VELOCITY
,
0
],
size_scale
=
1
e1
),
# 地球放大 10 倍,距离保持不变
init_velocity
=
[
0
,
EARTH_INIT_VELOCITY
,
0
],
size_scale
=
1
),
# 地球放大 10 倍,距离保持不变
Moon
(
init_position
=
[
363104
,
0
,
0
],
# 距地距离约: 363104 至 405696 km
Moon
(
init_position
=
[
363104
,
0
,
0
],
# 距地距离约: 363104 至 405696 km
init_velocity
=
[
0
,
EARTH_INIT_VELOCITY
+
1.023
,
0
],
size_scale
=
1
e1
)
# 月球放大 10 倍,距离保持不变
init_velocity
=
[
0
,
EARTH_INIT_VELOCITY
+
1.023
,
0
],
size_scale
=
1
)
# 月球放大 10 倍,距离保持不变
]
]
# mayavi_run(bodies, SECONDS_PER_HALF_DAY / 2, view_azimuth=-45)
# mayavi_run(bodies, SECONDS_PER_HALF_DAY / 2, view_azimuth=-45)
# 使用 ursina 查看的运行效果
# 使用 ursina 查看的运行效果
ursina_run
(
bodies
,
SECONDS_PER_
DAY
,
position
=
(
0
,
0
,
0
))
ursina_run
(
bodies
,
SECONDS_PER_
MONTH
,
position
=
(
0
,
0
,
0
))
scenes/solar_system_2.py
浏览文件 @
08c58515
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
# python_version :3.8
# python_version :3.8
# ==============================================================================
# ==============================================================================
from
bodies
import
Sun
,
Mercury
,
Venus
,
Earth
,
Mars
,
Jupiter
,
Saturn
,
Uranus
,
Neptune
,
Pluto
from
bodies
import
Sun
,
Mercury
,
Venus
,
Earth
,
Mars
,
Jupiter
,
Saturn
,
Uranus
,
Neptune
,
Pluto
from
common.consts
import
SECONDS_PER_WEEK
,
SECONDS_PER_DAY
from
common.consts
import
SECONDS_PER_WEEK
,
SECONDS_PER_DAY
,
SECONDS_PER_MONTH
,
SECONDS_PER_YEAR
from
scenes.func
import
mayavi_run
,
ursina_run
from
scenes.func
import
mayavi_run
,
ursina_run
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
@@ -38,4 +38,4 @@ if __name__ == '__main__':
...
@@ -38,4 +38,4 @@ if __name__ == '__main__':
# mayavi_run(bodies, SECONDS_PER_WEEK, view_azimuth=-45, view_distance=3e9, view_focalpoint=[5e2, 5e2, 5e2])
# mayavi_run(bodies, SECONDS_PER_WEEK, view_azimuth=-45, view_distance=3e9, view_focalpoint=[5e2, 5e2, 5e2])
ursina_run
(
bodies
,
SECONDS_PER_DAY
,
position
=
(
0
,
0
,
0
))
ursina_run
(
bodies
,
SECONDS_PER_YEAR
,
position
=
(
0
,
0
,
0
))
\ No newline at end of file
\ No newline at end of file
scenes/sun_earth_moon.py
0 → 100644
浏览文件 @
08c58515
# -*- coding:utf-8 -*-
# title :地月场景模拟
# description :地月场景模拟
# author :Python超人
# date :2023-02-11
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
from
bodies
import
Sun
,
Earth
,
Moon
from
common.consts
import
SECONDS_PER_HOUR
,
SECONDS_PER_HALF_DAY
,
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
from
scenes.func
import
mayavi_run
,
ursina_run
from
bodies.body
import
AU
if
__name__
==
'__main__'
:
"""
地球、月球
"""
# 地球的Y方向初始速度
EARTH_INIT_VELOCITY
=
29.79
# 200m/s
sun
=
Sun
(
init_position
=
[
0
,
AU
,
0
],
init_velocity
=
[
0
,
0
,
0
],
size_scale
=
1e1
)
# sun.ignore_mass = True
bodies
=
[
sun
,
Earth
(
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
EARTH_INIT_VELOCITY
,
0
],
size_scale
=
1e1
),
# 地球放大 10 倍,距离保持不变
Moon
(
init_position
=
[
363104
,
0
,
0
],
# 距地距离约: 363104 至 405696 km
init_velocity
=
[
0
,
EARTH_INIT_VELOCITY
+
1.023
,
0
],
size_scale
=
1e1
)
# 月球放大 10 倍,距离保持不变
]
# mayavi_run(bodies, SECONDS_PER_HALF_DAY / 2, view_azimuth=-45)
# 使用 ursina 查看的运行效果
ursina_run
(
bodies
,
SECONDS_PER_DAY
,
position
=
(
0
,
0
,
0
))
simulators/ursina_simulator.py
浏览文件 @
08c58515
...
@@ -26,7 +26,7 @@ class WorldGrid(Entity): # Entity # 定义构造方法
...
@@ -26,7 +26,7 @@ class WorldGrid(Entity): # Entity # 定义构造方法
def
__init__
(
self
):
def
__init__
(
self
):
super
().
__init__
()
super
().
__init__
()
s
=
100
s
=
100
grid
=
Entity
(
model
=
Grid
(
s
,
s
),
scale
=
s
*
20
,
color
=
color
.
rgba
(
255
,
255
,
255
,
20
),
rotation_x
=
90
,
grid
=
Entity
(
model
=
Grid
(
s
,
s
),
scale
=
s
*
20
,
color
=
color
.
rgba
(
255
,
255
,
255
,
20
),
rotation_x
=
90
,
position
=
(
0
,
-
80
,
0
))
position
=
(
0
,
-
80
,
0
))
# 坐标轴
# 坐标轴
# vertsx = ((0, 0, 0), (10, 0, 0))
# vertsx = ((0, 0, 0), (10, 0, 0))
...
@@ -127,9 +127,11 @@ class UrsinaSimulator(Simulator):
...
@@ -127,9 +127,11 @@ class UrsinaSimulator(Simulator):
# self.sun = "sun"
# self.sun = "sun"
lights
=
[]
lights
=
[]
# 创建多个新的 Entity 对象,作为光晕的容器
# 创建多个新的 Entity 对象,作为光晕的容器
for
i
in
range
(
5
):
for
i
in
range
(
10
):
# glow_entity = Entity(parent=entity, model='sphere', color=color.rgba(1.0, 0.6, 0.2, 1),
# scale=math.pow(1.03, i), alpha=0.2)
glow_entity
=
Entity
(
parent
=
entity
,
model
=
'sphere'
,
color
=
color
.
rgba
(
1.0
,
0.6
,
0.2
,
1
),
glow_entity
=
Entity
(
parent
=
entity
,
model
=
'sphere'
,
color
=
color
.
rgba
(
1.0
,
0.6
,
0.2
,
1
),
scale
=
math
.
pow
(
1.03
,
i
),
alpha
=
0.
2
)
scale
=
math
.
pow
(
1.03
,
i
),
alpha
=
0.
1
)
lights
.
append
(
glow_entity
)
lights
.
append
(
glow_entity
)
# 创建 PointLight 对象,作为恒星的灯光源
# 创建 PointLight 对象,作为恒星的灯光源
...
@@ -159,7 +161,8 @@ class UrsinaSimulator(Simulator):
...
@@ -159,7 +161,8 @@ class UrsinaSimulator(Simulator):
cosmic_bg
=
kwargs
[
"cosmic_bg"
]
cosmic_bg
=
kwargs
[
"cosmic_bg"
]
if
cosmic_bg
is
None
:
if
cosmic_bg
is
None
:
# cosmic_bg = '../textures/cosmic1.png'
# cosmic_bg = '../textures/cosmic1.png'
cosmic_bg
=
'../textures/cosmic2.jpg'
# cosmic_bg = '../textures/cosmic2.jpg'
cosmic_bg
=
'../textures/cosmic3.jpg'
import
os
import
os
if
cosmic_bg
is
not
None
and
os
.
path
.
exists
(
cosmic_bg
):
if
cosmic_bg
is
not
None
and
os
.
path
.
exists
(
cosmic_bg
):
self
.
cosmic_background
(
cosmic_bg
)
self
.
cosmic_background
(
cosmic_bg
)
...
...
simulators/views/ursina_view.py
浏览文件 @
08c58515
...
@@ -22,7 +22,10 @@ from simulators.views.body_view import BodyView
...
@@ -22,7 +22,10 @@ from simulators.views.body_view import BodyView
import
numpy
as
np
import
numpy
as
np
import
math
import
math
SCALE_FACTOR
=
5e-6
SCALE_FACTOR
=
5e-7
# 旋转因子为1,则为正常的转速
ROTATION_SPEED_FACTOR
=
1.0
# ROTATION_SPEED_FACTOR = 0.1
class
UrsinaPlayer
(
FirstPersonController
):
class
UrsinaPlayer
(
FirstPersonController
):
...
@@ -108,12 +111,8 @@ class Planet(Entity):
...
@@ -108,12 +111,8 @@ class Planet(Entity):
# 旋转速度和大小成反比(未使用真实数据)
# 旋转速度和大小成反比(未使用真实数据)
# self.rotspeed = 30000 / self.body_view.raduis # random.uniform(1.0, 2.0)
# self.rotspeed = 30000 / self.body_view.raduis # random.uniform(1.0, 2.0)
else
:
else
:
# 4.60e-6 是通过月球保持一面面对地球,调整得到
# 是通过月球保持一面面对地球,调整得到
# self.rotspeed = self.rotation_speed * dt * 4.60e-6
self
.
rotspeed
=
self
.
rotation_speed
*
(
dt
/
3600
)
/
2.4
*
ROTATION_SPEED_FACTOR
# / 60 / 24
# (self.rotation_speed * dt * 4.60e-6),(self.rotation_speed * (dt / 3600))/60
self
.
rotspeed
=
self
.
rotation_speed
*
(
dt
/
3600
)
/
2.4
# / 60 / 24
# self.rotspeed = self.rotation_speed * (dt / 3600) / 3.65e7
# rotation_speed 度/小时 dt 秒 = (dt / 3600)小时
# rotation_speed 度/小时 dt 秒 = (dt / 3600)小时
self
.
rotation_y
-=
self
.
rotspeed
self
.
rotation_y
-=
self
.
rotspeed
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录