Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
eae03e5d
宇宙模拟器
项目概览
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看板
提交
eae03e5d
编写于
4月 20, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
4897c35d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
17242 addition
and
55 deletion
+17242
-55
objs/__init__.py
objs/__init__.py
+1
-1
objs/models/satellite.obj
objs/models/satellite.obj
+0
-0
objs/models/satellite2.obj
objs/models/satellite2.obj
+17154
-0
objs/satellite.py
objs/satellite.py
+36
-3
sim_scenes/earth/earth_satellites.py
sim_scenes/earth/earth_satellites.py
+51
-51
textures/satellite.png
textures/satellite.png
+0
-0
textures/satellite2.jpg
textures/satellite2.jpg
+0
-0
未找到文件。
objs/__init__.py
浏览文件 @
eae03e5d
from
objs.diamond
import
Diamond
from
objs.diamond
import
Diamond
from
objs.football
import
Football
from
objs.football
import
Football
from
objs.satellite
import
Satellite
from
objs.satellite
import
Satellite
,
Satellite2
from
objs.space_ship
import
SpaceShip
from
objs.space_ship
import
SpaceShip
objs/models/satelite.obj
→
objs/models/satel
l
ite.obj
浏览文件 @
eae03e5d
文件已移动
objs/models/satellite2.obj
0 → 100644
浏览文件 @
eae03e5d
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
objs/satellite.py
浏览文件 @
eae03e5d
...
@@ -17,10 +17,43 @@ class Satellite(Obj):
...
@@ -17,10 +17,43 @@ class Satellite(Obj):
def
__init__
(
self
,
name
=
"卫星"
,
mass
=
5.97237e24
,
def
__init__
(
self
,
name
=
"卫星"
,
mass
=
5.97237e24
,
init_position
=
[
0
,
0
,
0
],
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
texture
=
"satelite.png"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
texture
=
"satel
l
ite.png"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
ignore_mass
=
False
,
density
=
1e3
,
color
=
(
7
,
0
,
162
),
ignore_mass
=
False
,
density
=
1e3
,
color
=
(
7
,
0
,
162
),
trail_color
=
(
255
,
255
,
255
),
show_name
=
False
,
trail_color
=
(
255
,
255
,
255
),
show_name
=
False
,
model
=
"satelite.obj"
,
model
=
"satellite.obj"
,
parent
=
None
,
gravity_only_for
=
[]):
params
=
{
"name"
:
name
,
"mass"
:
mass
,
"init_position"
:
init_position
,
"init_velocity"
:
init_velocity
,
"density"
:
density
,
"color"
:
color
,
"texture"
:
texture
,
"size_scale"
:
size_scale
,
"distance_scale"
:
distance_scale
,
"ignore_mass"
:
ignore_mass
,
"trail_color"
:
trail_color
,
"show_name"
:
show_name
,
"parent"
:
parent
,
"gravity_only_for"
:
gravity_only_for
,
"model"
:
model
}
super
().
__init__
(
**
params
)
class
Satellite2
(
Obj
):
"""
卫星
"""
def
__init__
(
self
,
name
=
"卫星"
,
mass
=
5.97237e24
,
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
texture
=
"satellite2.jpg"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
ignore_mass
=
False
,
density
=
1e3
,
color
=
(
7
,
0
,
162
),
trail_color
=
(
255
,
255
,
255
),
show_name
=
False
,
model
=
"satellite2.obj"
,
parent
=
None
,
gravity_only_for
=
[]):
parent
=
None
,
gravity_only_for
=
[]):
params
=
{
params
=
{
"name"
:
name
,
"name"
:
name
,
...
@@ -43,5 +76,5 @@ class Satellite(Obj):
...
@@ -43,5 +76,5 @@ class Satellite(Obj):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
satellite
=
Satellite
()
satellite
=
Satellite
2
()
print
(
satellite
)
print
(
satellite
)
sim_scenes/earth/earth_satellites.py
浏览文件 @
eae03e5d
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
# python_version :3.8
# python_version :3.8
# ==============================================================================
# ==============================================================================
from
bodies
import
Moon
,
Earth
,
Body
from
bodies
import
Moon
,
Earth
,
Body
from
objs
import
Satellite
from
objs
import
Satellite
,
Satellite2
from
common.consts
import
SECONDS_PER_HOUR
,
SECONDS_PER_HALF_DAY
,
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
,
SECONDS_PER_MONTH
from
common.consts
import
SECONDS_PER_HOUR
,
SECONDS_PER_HALF_DAY
,
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
,
SECONDS_PER_MONTH
from
sim_scenes.func
import
mayavi_run
,
ursina_run
,
camera_look_at
from
sim_scenes.func
import
mayavi_run
,
ursina_run
,
camera_look_at
import
math
import
math
...
@@ -42,56 +42,56 @@ from simulators.ursina.ursina_config import UrsinaConfig
...
@@ -42,56 +42,56 @@ from simulators.ursina.ursina_config import UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_event
import
UrsinaEvent
def
get_satellite_position_velocity
(
earth_mass
,
earth_position
,
earth_radius
,
altitude
):
#
def get_satellite_position_velocity(earth_mass, earth_position, earth_radius, altitude):
# 万有引力常数
#
# 万有引力常数
G
=
6.6743
*
10
**
(
-
11
)
#
G = 6.6743 * 10 ** (-11)
# 地球质量
#
# 地球质量
M
=
earth_mass
#
M = earth_mass
# 地球半径+海拔高度
#
# 地球半径+海拔高度
R
=
earth_radius
+
altitude
#
R = earth_radius + altitude
#
# 随机生成卫星的位置,确保在球面上
#
# 随机生成卫星的位置,确保在球面上
phi
=
random
.
uniform
(
0
,
2
*
math
.
pi
)
#
phi = random.uniform(0, 2 * math.pi)
costheta
=
random
.
uniform
(
-
1
,
1
)
#
costheta = random.uniform(-1, 1)
u
=
random
.
uniform
(
0
,
1
)
#
u = random.uniform(0, 1)
#
theta
=
math
.
acos
(
costheta
)
#
theta = math.acos(costheta)
r
=
R
*
(
u
**
(
1
/
3
))
#
r = R * (u ** (1 / 3))
#
x
=
r
*
math
.
sin
(
theta
)
*
math
.
cos
(
phi
)
#
x = r * math.sin(theta) * math.cos(phi)
y
=
r
*
math
.
sin
(
theta
)
*
math
.
sin
(
phi
)
#
y = r * math.sin(theta) * math.sin(phi)
z
=
r
*
math
.
cos
(
theta
)
#
z = r * math.cos(theta)
#
# 计算速度的方向
#
# 计算速度的方向
# 位置矢量
#
# 位置矢量
r_vec
=
[
x
,
y
,
z
]
#
r_vec = [x, y, z]
# 速度方向和位置矢量垂直,采用向量叉积的性质
#
# 速度方向和位置矢量垂直,采用向量叉积的性质
v_dir
=
[
-
y
,
x
,
0
]
#
v_dir = [-y, x, 0]
# 归一化
#
# 归一化
v_dir_norm
=
[
v
/
math
.
sqrt
(
x
**
2
+
y
**
2
)
for
v
in
v_dir
]
#
v_dir_norm = [v / math.sqrt(x ** 2 + y ** 2) for v in v_dir]
#
# 计算速度大小
#
# 计算速度大小
v
=
math
.
sqrt
(
G
*
M
/
R
)
#
v = math.sqrt(G * M / R)
#
# 计算速度矢量
#
# 计算速度矢量
v_vec
=
[
v
*
dir
for
dir
in
v_dir_norm
]
#
v_vec = [v * dir for dir in v_dir_norm]
#
# 计算卫星的位置和速度
#
# 计算卫星的位置和速度
position
=
[
earth_position
[
0
]
+
x
,
earth_position
[
1
]
+
y
,
earth_position
[
2
]
+
z
]
#
position = [earth_position[0] + x, earth_position[1] + y, earth_position[2] + z]
velocity
=
v_vec
#
velocity = v_vec
#
return
tuple
(
position
),
[
0
,
0
,
0
]
#
return tuple(position), [0, 0, 0]
#
#
def
generate_satellite_coordinates
(
earth_radius
,
altitude
):
#
def generate_satellite_coordinates(earth_radius, altitude):
theta
=
random
.
uniform
(
0
,
2
*
math
.
pi
)
# 在0~2π内随机生成一个角度
#
theta = random.uniform(0, 2 * math.pi) # 在0~2π内随机生成一个角度
phi
=
random
.
uniform
(
0
,
math
.
pi
)
# 在0~π内随机生成一个角度
#
phi = random.uniform(0, math.pi) # 在0~π内随机生成一个角度
r
=
earth_radius
+
altitude
# 地球半径+海拔高度
#
r = earth_radius + altitude # 地球半径+海拔高度
x
=
r
*
math
.
sin
(
phi
)
*
math
.
cos
(
theta
)
# 计算x坐标
#
x = r * math.sin(phi) * math.cos(theta) # 计算x坐标
y
=
r
*
math
.
sin
(
phi
)
*
math
.
sin
(
theta
)
# 计算y坐标
#
y = r * math.sin(phi) * math.sin(theta) # 计算y坐标
z
=
r
*
math
.
cos
(
phi
)
# 计算z坐标
#
z = r * math.cos(phi) # 计算z坐标
#
return
[
x
,
y
,
z
]
#
return [x, y, z]
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
textures/satelite.png
→
textures/satel
l
ite.png
浏览文件 @
eae03e5d
文件已移动
textures/satellite2.jpg
0 → 100644
浏览文件 @
eae03e5d
803.3 KB
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录