提交 3558bb8c 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 33f7d6af
...@@ -51,6 +51,8 @@ class Earth(Body): ...@@ -51,6 +51,8 @@ class Earth(Body):
"parent": parent "parent": parent
} }
super().__init__(**params) super().__init__(**params)
# 公转周期(天)
self.orbital_days = 365.24219
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -45,6 +45,8 @@ class Jupiter(Body): ...@@ -45,6 +45,8 @@ class Jupiter(Body):
"show_name": show_name "show_name": show_name
} }
super().__init__(**params) super().__init__(**params)
# 公转周期(天)
self.orbital_days = 11.862 * 365.24219
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -45,6 +45,8 @@ class Mars(Body): ...@@ -45,6 +45,8 @@ class Mars(Body):
"show_name": show_name "show_name": show_name
} }
super().__init__(**params) super().__init__(**params)
# 公转周期(天)
self.orbital_days = 686.971
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -46,6 +46,8 @@ class Mercury(Body): ...@@ -46,6 +46,8 @@ class Mercury(Body):
"show_name": show_name "show_name": show_name
} }
super().__init__(**params) super().__init__(**params)
#
self.orbital_days = 87.9691
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -46,6 +46,8 @@ class Neptune(Body): ...@@ -46,6 +46,8 @@ class Neptune(Body):
"show_name": show_name "show_name": show_name
} }
super().__init__(**params) super().__init__(**params)
# 公转周期(天)
self.orbital_days = 164.8 * 365.24219
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -47,6 +47,8 @@ class Saturn(Body): ...@@ -47,6 +47,8 @@ class Saturn(Body):
} }
self.__has_rings = True self.__has_rings = True
super().__init__(**params) super().__init__(**params)
# 公转周期(天)
self.orbital_days = 29.4571 * 365.24219
def show_rings(self, value): def show_rings(self, value):
self.__has_rings = value self.__has_rings = value
......
...@@ -46,6 +46,8 @@ class Uranus(Body): ...@@ -46,6 +46,8 @@ class Uranus(Body):
"show_name": show_name "show_name": show_name
} }
super().__init__(**params) super().__init__(**params)
# 公转周期(天)
self.orbital_days = 84.0205 * 365.24219
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -46,6 +46,8 @@ class Venus(Body): ...@@ -46,6 +46,8 @@ class Venus(Body):
"show_name": show_name "show_name": show_name
} }
super().__init__(**params) super().__init__(**params)
# 公转周期(天)
self.orbital_days = 224.701
if __name__ == '__main__': if __name__ == '__main__':
......
# -*- coding:utf-8 -*-
# title :哈雷彗星场景半真实模拟共用库
# description :
# author :Python超人
# date :2023-11-06
# link :https://gitcode.net/pythoncr/
# python_version :3.9
# ==============================================================================
import math
from dataclasses import dataclass
from dataclasses import field
from common.celestial_data_service import get_reality_orbit_points
from common.consts import AU
from objs import HalleComet
from simulators.ursina.ursina_mesh import create_orbit_by_points
@dataclass(order=True)
class HalleyCometParams:
start_time: str = field(default='1983-03-20 00:00:00')
init_velocity: list[float] = field(default_factory=[3.34, 0, 10.718])
init_position: list[float] = field(default_factory=[0, 0.5 * AU, -10 * AU])
def create_halley_comet(init_velocity, init_position):
"""
创建哈雷彗星
@return:
"""
# 哈雷彗星的平均运行速度约为每小时 70,000 英里或每小时 126,000 公里 。(35公里/秒)
# 每76.1年环绕太阳一周的周期彗星
halley_comet = HalleComet(
# size_scale=4e7,
size_scale=1e8,
init_velocity=init_velocity,
init_position=init_position) \
.set_light_disable(True)
return halley_comet
def create_orbit_line(center_body, body, start_time):
orbital_days = int(math.ceil(body.orbital_days * 1.02))
points = get_reality_orbit_points(type(body).__name__.lower(), start_time=start_time, days=orbital_days,
segments=100)
# print(points)
orbit_line = create_orbit_by_points(center_body.position, points, line_color=body.trail_color)
return orbit_line
...@@ -20,6 +20,7 @@ from common.func import calculate_distance ...@@ -20,6 +20,7 @@ from common.func import calculate_distance
from objs import HalleComet from objs import HalleComet
from sim_scenes.func import create_text_panel from sim_scenes.func import create_text_panel
from sim_scenes.func import ursina_run, create_sphere_sky from sim_scenes.func import ursina_run, create_sphere_sky
from sim_scenes.solar_system.halley_comet_lib import HalleyCometParams, create_halley_comet, create_orbit_line
from simulators.ursina.entities.body_timer import TimeData from simulators.ursina.entities.body_timer import TimeData
from simulators.ursina.entities.entity_utils import get_value_direction_vectors from simulators.ursina.entities.entity_utils import get_value_direction_vectors
from simulators.ursina.ui.control_ui import ControlUI from simulators.ursina.ui.control_ui import ControlUI
...@@ -30,13 +31,6 @@ from dataclasses import dataclass ...@@ -30,13 +31,6 @@ from dataclasses import dataclass
from dataclasses import field from dataclasses import field
@dataclass(order=True)
class HalleyCometParams:
start_time: str = field(default='1983-03-20 00:00:00')
init_velocity: list[float] = field(default_factory=[3.34, 0, 10.718])
init_position: list[float] = field(default_factory=[0, 0.5 * AU, -10 * AU])
class HalleyCometSim: class HalleyCometSim:
""" """
哈雷彗星场景模拟 哈雷彗星场景模拟
...@@ -80,14 +74,6 @@ class HalleyCometSim: ...@@ -80,14 +74,6 @@ class HalleyCometSim:
self.neptune, # 海王星 self.neptune, # 海王星
# self.pluto, # 冥王星 # self.pluto, # 冥王星
] ]
self.mercury.orbital_days = 87.9691
self.venus.orbital_days = 224.701
self.earth.orbital_days = 365.24219
self.mars.orbital_days = 686.971
self.jupiter.orbital_days = 11.862 * 365.24219
self.saturn.orbital_days = 29.4571 * 365.24219
self.uranus.orbital_days = 84.0205 * 365.24219
self.neptune.orbital_days = 164.8 * 365.24219
# self.bodies = [ # self.bodies = [
# self.sun, # 太阳 # self.sun, # 太阳
...@@ -107,27 +93,13 @@ class HalleyCometSim: ...@@ -107,27 +93,13 @@ class HalleyCometSim:
创建哈雷彗星 创建哈雷彗星
@return: @return:
""" """
# 哈雷彗星的平均运行速度约为每小时 70,000 英里或每小时 126,000 公里 。(35公里/秒) self.halley_comet = create_halley_comet(self.params.init_velocity, self.params.init_position)
# 每76.1年环绕太阳一周的周期彗星
self.halley_comet = HalleComet( # size_scale=4e7,
size_scale=0.4e8,
init_velocity=self.params.init_velocity,
init_position=self.params.init_position) \
.set_light_disable(True)
self.bodies.append(self.halley_comet) self.bodies.append(self.halley_comet)
def build(self): def build(self):
self.build_solar_system() self.build_solar_system()
self.build_halley_comet() self.build_halley_comet()
def create_orbit_line(self, center_body, body):
orbital_days = int(math.ceil(body.orbital_days * 1.02))
points = get_reality_orbit_points(type(body).__name__.lower(), start_time=self.start_time, days=orbital_days,
segments=100)
# print(points)
orbit_line = create_orbit_by_points(center_body.position, points, line_color=body.trail_color)
return orbit_line
def on_ready(self): def on_ready(self):
""" """
...@@ -150,7 +122,7 @@ class HalleyCometSim: ...@@ -150,7 +122,7 @@ class HalleyCometSim:
for body in self.bodies[1:]: for body in self.bodies[1:]:
if isinstance(body, HalleComet): if isinstance(body, HalleComet):
continue continue
orbit_line = self.create_orbit_line(self.sun, body) orbit_line = create_orbit_line(self.sun, body, self.start_time)
self.orbit_lines.append(orbit_line) self.orbit_lines.append(orbit_line)
self.text_panel = create_text_panel() self.text_panel = create_text_panel()
...@@ -323,8 +295,6 @@ if __name__ == '__main__': ...@@ -323,8 +295,6 @@ if __name__ == '__main__':
# init_velocity=[-2.841, 4.7, 8.86], # init_velocity=[-2.841, 4.7, 8.86],
# init_position=[0, -5 * AU, -10 * AU] # init_position=[0, -5 * AU, -10 * AU]
sim = HalleyCometSim(params) sim = HalleyCometSim(params)
sim.build() sim.build()
......
...@@ -20,6 +20,7 @@ from common.func import calculate_distance ...@@ -20,6 +20,7 @@ from common.func import calculate_distance
from objs import HalleComet from objs import HalleComet
from sim_scenes.func import create_text_panel from sim_scenes.func import create_text_panel
from sim_scenes.func import ursina_run, create_sphere_sky from sim_scenes.func import ursina_run, create_sphere_sky
from sim_scenes.solar_system.halley_comet_lib import create_halley_comet, create_orbit_line
from simulators.ursina.ursina_config import UrsinaConfig from simulators.ursina.ursina_config import UrsinaConfig
from simulators.ursina.ursina_event import UrsinaEvent from simulators.ursina.ursina_event import UrsinaEvent
from simulators.ursina.ursina_mesh import create_orbit_by_points from simulators.ursina.ursina_mesh import create_orbit_by_points
...@@ -64,14 +65,6 @@ class HalleyCometSim: ...@@ -64,14 +65,6 @@ class HalleyCometSim:
self.neptune, # 海王星 self.neptune, # 海王星
# self.pluto, # 冥王星 # self.pluto, # 冥王星
] ]
self.mercury.orbital_days = 87.9691
self.venus.orbital_days = 224.701
self.earth.orbital_days = 365.24219
self.mars.orbital_days = 686.971
self.jupiter.orbital_days = 11.862 * 365.24219
self.saturn.orbital_days = 29.4571 * 365.24219
self.uranus.orbital_days = 84.0205 * 365.24219
self.neptune.orbital_days = 164.8 * 365.24219
# self.bodies = [ # self.bodies = [
# self.sun, # 太阳 # self.sun, # 太阳
...@@ -88,28 +81,20 @@ class HalleyCometSim: ...@@ -88,28 +81,20 @@ class HalleyCometSim:
创建哈雷彗星 创建哈雷彗星
@return: @return:
""" """
# 哈雷彗星的平均运行速度约为每小时 70,000 英里或每小时 126,000 公里 。(35公里/秒) self.halley_comet = create_halley_comet([-2.836, 4.705, 8.85], [0, -5 * AU, -10 * AU])
# 每76.1年环绕太阳一周的周期彗星
self.halley_comet = HalleComet(
# size_scale=4e7,
size_scale=1e8,
init_velocity=[-2.836, 4.705, 8.85],
init_position=[0, -5 * AU, -10 * AU]) \
.set_light_disable(True)
self.bodies.append(self.halley_comet) self.bodies.append(self.halley_comet)
def build(self): def build(self):
self.build_solar_system() self.build_solar_system()
self.build_halley_comet() self.build_halley_comet()
def create_orbit_line(self, center_body, body): # def create_orbit_line(self, center_body, body):
orbital_days = int(math.ceil(body.orbital_days * 1.02)) # orbital_days = int(math.ceil(body.orbital_days * 1.02))
points = get_reality_orbit_points(type(body).__name__.lower(), start_time=self.dt, days=orbital_days, # points = get_reality_orbit_points(type(body).__name__.lower(), start_time=self.dt, days=orbital_days,
segments=100) # segments=100)
# print(points) # # print(points)
orbit_line = create_orbit_by_points(center_body.position, points, line_color=body.trail_color) # orbit_line = create_orbit_by_points(center_body.position, points, line_color=body.trail_color)
return orbit_line # return orbit_line
def on_ready(self): def on_ready(self):
""" """
...@@ -134,7 +119,7 @@ class HalleyCometSim: ...@@ -134,7 +119,7 @@ class HalleyCometSim:
for body in self.bodies[1:]: for body in self.bodies[1:]:
if isinstance(body, HalleComet): if isinstance(body, HalleComet):
continue continue
orbit_line = self.create_orbit_line(self.sun, body) orbit_line = create_orbit_line(self.sun, body, self.dt)
self.orbit_lines.append(orbit_line) self.orbit_lines.append(orbit_line)
self.text_panel = create_text_panel() self.text_panel = create_text_panel()
......
...@@ -18,6 +18,7 @@ from common.func import calculate_distance ...@@ -18,6 +18,7 @@ from common.func import calculate_distance
from objs import HalleComet, Obj from objs import HalleComet, Obj
from sim_scenes.func import camera_look_at, two_bodies_colliding, create_text_panel from sim_scenes.func import camera_look_at, two_bodies_colliding, create_text_panel
from sim_scenes.func import ursina_run, create_sphere_sky from sim_scenes.func import ursina_run, create_sphere_sky
from sim_scenes.solar_system.halley_comet_lib import create_halley_comet
from simulators.ursina.ursina_config import UrsinaConfig from simulators.ursina.ursina_config import UrsinaConfig
from simulators.ursina.ursina_event import UrsinaEvent from simulators.ursina.ursina_event import UrsinaEvent
from simulators.ursina.ursina_mesh import create_orbit_line from simulators.ursina.ursina_mesh import create_orbit_line
...@@ -64,14 +65,7 @@ class HalleyCometSim: ...@@ -64,14 +65,7 @@ class HalleyCometSim:
创建哈雷彗星 创建哈雷彗星
@return: @return:
""" """
# 哈雷彗星的平均运行速度约为每小时 70,000 英里或每小时 126,000 公里 。(35公里/秒) self.halley_comet = create_halley_comet([-3.34, 3, 10.718], [0, -2 * AU, -10 * AU])
# 每76.1年环绕太阳一周的周期彗星
self.halley_comet = HalleComet( # size_scale=4e7,
size_scale=1e8,
init_velocity=[-3.34, 3, 10.718],
init_position=[0, -2 * AU, -10 * AU]) \
.set_light_disable(True)
self.bodies.append(self.halley_comet) self.bodies.append(self.halley_comet)
def build(self): def build(self):
...@@ -84,7 +78,6 @@ class HalleyCometSim: ...@@ -84,7 +78,6 @@ class HalleyCometSim:
@return: @return:
""" """
# 创建天空 # 创建天空
from ursina import scene
UrsinaConfig.trail_type = "line" UrsinaConfig.trail_type = "line"
UrsinaConfig.trail_length = 91 UrsinaConfig.trail_length = 91
UrsinaConfig.trail_thickness_factor = 3 UrsinaConfig.trail_thickness_factor = 3
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册