diff --git a/common/consts.py b/common/consts.py index 960ab1af7cf2c8175393660f99b4589124cfc6d0..c016bb0ce0a9e55e058154cc5eed4228b984d394 100644 --- a/common/consts.py +++ b/common/consts.py @@ -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 diff --git a/scenes/earth_moon.py b/scenes/earth_moon.py index b281473adaedfcc476f72ef3932b2303fb648d72..fe7d7e7a6be3830776b75171ce46f4efe0292b9d 100644 --- a/scenes/earth_moon.py +++ b/scenes/earth_moon.py @@ -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)) diff --git a/scenes/solar_system_2.py b/scenes/solar_system_2.py index 7b60db3903eb525a3bce069a0cba19156d3b19cd..26183e533db9b5aaee778100274cf538fe5201f9 100644 --- a/scenes/solar_system_2.py +++ b/scenes/solar_system_2.py @@ -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 diff --git a/scenes/sun_earth_moon.py b/scenes/sun_earth_moon.py new file mode 100644 index 0000000000000000000000000000000000000000..b0d068036a7530d9d84e104300f6be51b1796d8f --- /dev/null +++ b/scenes/sun_earth_moon.py @@ -0,0 +1,32 @@ +# -*- 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)) diff --git a/simulators/ursina_simulator.py b/simulators/ursina_simulator.py index 496c45196e991af1c373bd1a1ca64477e2d1f7d7..5b797d857f4d5e3f9d584f08b10f6102aa707f0a 100644 --- a/simulators/ursina_simulator.py +++ b/simulators/ursina_simulator.py @@ -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) diff --git a/simulators/views/ursina_view.py b/simulators/views/ursina_view.py index 815d76dc1418e0bc6b84ad5e4e03ab2525c6b3d5..175e617e43d3040bc3f0dac3066a804df9e5c1bf 100644 --- a/simulators/views/ursina_view.py +++ b/simulators/views/ursina_view.py @@ -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