提交 08c58515 编写于 作者: 三月三net's avatar 三月三net

太阳系三体模拟器

上级 34e69c06
......@@ -37,3 +37,7 @@ SECONDS_PER_WEEK = SECONDS_PER_DAY * 7
一月多少秒(按照30天算)
"""
SECONDS_PER_MONTH = SECONDS_PER_DAY * 30
"""
一年多少秒(按照365天算)
"""
SECONDS_PER_YEAR = SECONDS_PER_DAY * 365
......@@ -7,7 +7,7 @@
# 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 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 bodies.body import AU
......@@ -16,17 +16,15 @@ if __name__ == '__main__':
地球、月球
"""
# 地球的Y方向初始速度
EARTH_INIT_VELOCITY = 0 # 200m/s
sun = Sun(init_position=[0, AU, 0], init_velocity=[0, 0, 0], size_scale=1e1)
sun.ignore_mass = True
EARTH_INIT_VELOCITY = -0 # 20m/s
bodies = [
# sun,
Earth(init_position=[0, 0, 0],
init_velocity=[0, EARTH_INIT_VELOCITY, 0], size_scale=1e1), # 地球放大 10 倍,距离保持不变
init_velocity=[0, EARTH_INIT_VELOCITY, 0], size_scale=1), # 地球放大 10 倍,距离保持不变
Moon(init_position=[363104, 0, 0], # 距地距离约: 363104 至 405696 km
init_velocity=[0, EARTH_INIT_VELOCITY + 1.023, 0], size_scale=1e1) # 月球放大 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)
# 使用 ursina 查看的运行效果
ursina_run(bodies, SECONDS_PER_DAY, position=(0, 0, 0))
ursina_run(bodies, SECONDS_PER_MONTH, position=(0, 0, 0))
......@@ -7,7 +7,7 @@
# python_version :3.8
# ==============================================================================
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
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])
ursina_run(bodies, SECONDS_PER_DAY, position=(0, 0, 0))
\ No newline at end of file
ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 0, 0))
\ No newline at end of file
# -*- 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))
......@@ -26,7 +26,7 @@ class WorldGrid(Entity): # Entity # 定义构造方法
def __init__(self):
super().__init__()
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))
# 坐标轴
# vertsx = ((0, 0, 0), (10, 0, 0))
......@@ -127,9 +127,11 @@ class UrsinaSimulator(Simulator):
# self.sun = "sun"
lights = []
# 创建多个新的 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),
scale=math.pow(1.03, i), alpha=0.2)
scale=math.pow(1.03, i), alpha=0.1)
lights.append(glow_entity)
# 创建 PointLight 对象,作为恒星的灯光源
......@@ -159,7 +161,8 @@ class UrsinaSimulator(Simulator):
cosmic_bg = kwargs["cosmic_bg"]
if cosmic_bg is None:
# cosmic_bg = '../textures/cosmic1.png'
cosmic_bg = '../textures/cosmic2.jpg'
# cosmic_bg = '../textures/cosmic2.jpg'
cosmic_bg = '../textures/cosmic3.jpg'
import os
if cosmic_bg is not None and os.path.exists(cosmic_bg):
self.cosmic_background(cosmic_bg)
......
......@@ -22,7 +22,10 @@ from simulators.views.body_view import BodyView
import numpy as np
import math
SCALE_FACTOR = 5e-6
SCALE_FACTOR = 5e-7
# 旋转因子为1,则为正常的转速
ROTATION_SPEED_FACTOR = 1.0
# ROTATION_SPEED_FACTOR = 0.1
class UrsinaPlayer(FirstPersonController):
......@@ -108,12 +111,8 @@ class Planet(Entity):
# 旋转速度和大小成反比(未使用真实数据)
# self.rotspeed = 30000 / self.body_view.raduis # random.uniform(1.0, 2.0)
else:
# 4.60e-6 是通过月球保持一面面对地球,调整得到
# self.rotspeed = self.rotation_speed * dt * 4.60e-6
# (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
# 是通过月球保持一面面对地球,调整得到
self.rotspeed = self.rotation_speed * (dt / 3600) / 2.4 * ROTATION_SPEED_FACTOR # / 60 / 24
# rotation_speed 度/小时 dt 秒 = (dt / 3600)小时
self.rotation_y -= self.rotspeed
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册