diff --git a/common/celestial_data_service.py b/common/celestial_data_service.py index be4327e2b0c74ec7ed15f4ff73294fef88033e82..28eb18903126ed0483363613cf5b29aaf286eec6 100644 --- a/common/celestial_data_service.py +++ b/common/celestial_data_service.py @@ -127,7 +127,7 @@ def get_celestial_body_data(body_name): def set_solar_system_celestial_position(bodies, dt, recalc_moon_pos, recalc_moon_pos_scale=50, - set_velocity=True, set_acceleration=True): + set_velocity=True, set_acceleration=True, center_pos=None): """ 根据日期时间 dt 设置太阳系中天体的真实位置 @@ -183,8 +183,13 @@ def set_solar_system_celestial_position(bodies, dt, recalc_moon_pos, recalc_moon posvel[1].z.value * AU / SECONDS_PER_DAY, posvel[1].y.value * AU / SECONDS_PER_DAY] + # 实时调整天体的位置和速度 - body.position = np.array(position) + + if center_pos is None: + body.position = np.array(position) + else: + body.position = np.array(position) - center_pos if set_velocity: body.velocity = np.array(velocity) diff --git a/sim_scenes/featured/earth_seasons_live.md b/sim_scenes/featured/earth_seasons_live.md new file mode 100644 index 0000000000000000000000000000000000000000..86a4db069a7fb560a6ba5c7592c47da8550880a0 --- /dev/null +++ b/sim_scenes/featured/earth_seasons_live.md @@ -0,0 +1,7 @@ + + +2024/01/02 11:51 水星留(视赤经17.45h),转为顺行 +2024/01/03 15:52 月球过天赤道,进入南半球,月球视赤纬0度 +2024/01/09 04:10 金星合月,金星在月球以北5.70度? +2024/01/10 02:47 水星合月,水星在月球以北6.59度? +2024/04/09 09:24 水星合月,水星在月球以北2.19度 \ No newline at end of file diff --git a/sim_scenes/featured/earth_seasons_live.py b/sim_scenes/featured/earth_seasons_live.py index 4f3ae8a86bd060dfd2aae704039c4596ade594ca..a0b664976a64fefb4a689a233a343d98f38379e8 100644 --- a/sim_scenes/featured/earth_seasons_live.py +++ b/sim_scenes/featured/earth_seasons_live.py @@ -8,8 +8,8 @@ # ============================================================================== from ursina import camera, window, Text, color -from bodies import Sun, Earth, Moon -from common.celestial_data_service import set_solar_system_celestial_position, conv_to_astropy_time +from bodies import * +from common.celestial_data_service import set_solar_system_celestial_position, conv_to_astropy_time, get_body_posvel from common.consts import SECONDS_PER_DAY, AU from sim_scenes.featured.earth_seasons_base import EarthSeasonsSimBase from sim_scenes.func import ursina_run, camera_look_at, create_sphere_sky @@ -19,19 +19,34 @@ from simulators.ursina.entities.body_timer import TimeData, BodyTimer from simulators.ursina.ui.control_ui import ControlUI from simulators.ursina.ursina_config import UrsinaConfig from simulators.ursina.ursina_event import UrsinaEvent +from simulators.ursina_simulator import UrsinaSimulator +import numpy as np class EarthSeasonsSimLive(EarthSeasonsSimBase): def __init__(self): - super(EarthSeasonsSimLive, self).__init__(exit_at_total_days=370, + super(EarthSeasonsSimLive, self).__init__(sun_transparent=False, + exit_at_total_days=370, delay_run=False, earth_cn_size_factor=1.01, earth_clouds_size_factor=1.015) self.start_time = '2023-12-20 00:00:00' + self.sun.size_scale = 3e1 self.moon = Moon(name="月球", size_scale=5e3, rotation_speed=0.645 ) # 月球 - self.bodies.append(self.moon) + self.mercury = Mercury(size_scale=5e3) + self.venus = Venus(name="金星", size_scale=5e3) + self.mars = Mars(size_scale=5e3) + self.jupiter = Jupiter(size_scale=1e3) + self.saturn = Saturn(size_scale=1e3) + self.uranus = Uranus(size_scale=4e3) + self.neptune = Neptune(size_scale=4e3) + + self.bodies += [self.moon, self.mercury, self.venus, self.mars, + self.jupiter, self.saturn, self.uranus, self.neptune] + + self.last_year = None for body in self.bodies: if isinstance(body, Earth): @@ -40,6 +55,28 @@ class EarthSeasonsSimLive(EarthSeasonsSimBase): body.rotation_speed *= 2.5 body.set_resolution(50) + self.season_earths = [self.earth_1, self.earth_2, self.earth_3, self.earth_4] + self.planets = [] + + self.jieqis = { + "春分-2023": '2023-03-21 00:00:00', + "夏至-2023": '2023-06-21 00:00:00', + "秋分-2023": '2023-09-23 00:00:00', + "冬至-2023": '2023-12-22 00:00:00', + "春分-2024": '2024-03-20 00:00:00', + "夏至-2024": '2024-06-21 00:00:00', + "秋分-2024": '2024-09-22 00:00:00', + "冬至-2024": '2024-12-21 00:00:00', + "春分-2025": '2025-03-20 00:00:00', + "夏至-2025": '2025-06-21 00:00:00', + "秋分-2025": '2025-09-23 00:00:00', + "冬至-2025": '2024-12-21 00:00:00', + } + + for body in self.bodies: + if body not in self.season_earths: + self.planets.append(body) + def earth_text_display(self, term_name): for e in [self.earth_1, self.earth_2, self.earth_3, self.earth_4]: # if hasattr(e, "name_text"): @@ -48,6 +85,12 @@ class EarthSeasonsSimLive(EarthSeasonsSimBase): # else: e.name_text.enabled = True + def get_center_pos(self, dt): + posvel = get_body_posvel(self.earth, dt) + position = [posvel[0].x.value * AU, posvel[0].z.value * AU, posvel[0].y.value * AU] + center_pos = np.array(position) + return center_pos + def on_ready(self): super(EarthSeasonsSimLive, self).on_ready() # camera_look_at(self.sun, rotation_z=0) @@ -57,7 +100,7 @@ class EarthSeasonsSimLive(EarthSeasonsSimBase): self.earth_4.planet.alpha = 0.2 self.earth.planet.name_text.enabled = False - # , self.earth_clouds, self.earth_cn + # , self.earth_clouds, self.earth_cn self.earth_1.planet.rotation_y = 115 # 春分 self.earth_2.planet.rotation_y = 15 # 夏至 @@ -67,13 +110,14 @@ class EarthSeasonsSimLive(EarthSeasonsSimBase): self.moon.planet.rotation_y = 180 self.show_title() + camera.fov = 140 window.borderless = True window.exit_button = False # window.fullscreen = True - window.position = (1920, 0) - # 设置窗口的宽度和高度 - window.size = (2340, 1079) + # window.position = (1920, 0) + # # 设置窗口的宽度和高度 + # window.size = (2340, 1079) def on_timer_changed(self, time_data: TimeData): super(EarthSeasonsSimLive, self).on_timer_changed(time_data) @@ -81,6 +125,9 @@ class EarthSeasonsSimLive(EarthSeasonsSimBase): dt = time_data.get_datetime(self.start_time) self.set_bodies_position(time_data) self.show_clock(dt) + ec = UrsinaSimulator.EditorCamera + # ec.target_z -= 0.05 + # camera.position += camera.left * 0.0001 def set_bodies_position(self, time_data: TimeData): """ @@ -88,34 +135,20 @@ class EarthSeasonsSimLive(EarthSeasonsSimBase): @param time_data: @return: """ - jieqis = { - "春分-2023": '2023-03-21 00:00:00', - "夏至-2023": '2023-06-21 00:00:00', - "秋分-2023": '2023-09-23 00:00:00', - "冬至-2023": '2023-12-22 00:00:00', - "春分-2024": '2024-03-20 00:00:00', - "夏至-2024": '2024-06-21 00:00:00', - "秋分-2024": '2024-09-22 00:00:00', - "冬至-2024": '2024-12-21 00:00:00', - "春分-2025": '2025-03-20 00:00:00', - "夏至-2025": '2025-06-21 00:00:00', - "秋分-2025": '2025-09-23 00:00:00', - "冬至-2025": '2024-12-21 00:00:00', - } - dt = conv_to_astropy_time(self.start_time) - bodies = [] + center_pos = self.get_center_pos(dt) + year = int(dt.jyear) - for body in self.bodies: - jieqir = jieqis.get(f"{body.name}-{year}", None) - if jieqir is not None: - jieqir = conv_to_astropy_time(jieqir) - set_solar_system_celestial_position([body], jieqir, False) - else: - bodies.append(body) + if self.last_year != year: + for body in self.season_earths: + jieqir = self.jieqis.get(f"{body.name}-{year}", None) + if jieqir is not None: + jieqir = conv_to_astropy_time(jieqir) + set_solar_system_celestial_position([body], jieqir, False, center_pos=center_pos) + self.last_year = year t = dt + time_data.total_days - set_solar_system_celestial_position(bodies, t, True, recalc_moon_pos_scale=180) + set_solar_system_celestial_position(self.planets, t, True, recalc_moon_pos_scale=180, center_pos=center_pos) def exit_handle(self): UrsinaEvent.on_reset() @@ -128,10 +161,13 @@ class EarthSeasonsSimLive(EarthSeasonsSimBase): aspect_ratio = window.aspect_ratio position, origin = (-0.5 * aspect_ratio - 0.1, 0.48), (-0.05, 0.1) position2, origin2 = (-0.5 * aspect_ratio - 0.1, 0.40), (-0.05, 0.1) - text1 = Text(text="太阳视角:观察日食月食", color=color.white, scale=2.5, position=position, # (-0.98, 0.48), + # text1 = Text(text="太阳视角:观察日食月食", color=color.white, scale=2.5, position=position, # (-0.98, 0.48), + # font=font) + ext1 = Text(text="太阳视角:2024年重要天象", color=color.white, scale=2.5, position=position, # (-0.98, 0.48), font=font) text2 = Text(text="(地球自转放慢10倍)", color=color.white, scale=1.5, position=position2, # (-0.98, 0.48), font=font) + # 2024年重要天象 def show_clock(self, dt): """ @@ -163,6 +199,7 @@ if __name__ == '__main__': sim.run( # dt=SECONDS_PER_DAY * 10, # dt=SECONDS_PER_DAY * 3, + init_position=[0, 0, -2 * AU], show_exit_button=False, show_camera_info=False, gravity_works=False,