diff --git a/bodies/__init__.py b/bodies/__init__.py index dafd1491720c3a72b6237ca400cf73728522e233..4f03f4a741a0b3a735ec64304f5c6856d181ace2 100644 --- a/bodies/__init__.py +++ b/bodies/__init__.py @@ -5,7 +5,6 @@ from bodies.jupiter import Jupiter from bodies.mars import Mars from bodies.mercury import Mercury from bodies.neptune import Neptune -from bodies.pluto import Pluto from bodies.saturn import Saturn from bodies.uranus import Uranus from bodies.venus import Venus @@ -15,6 +14,13 @@ from bodies.torus_zone import TorusZone from bodies.asteroids import Asteroids from bodies.habitable_zone import HabitableZone +# 太阳系中的矮行星 +from bodies.pluto import Pluto +from bodies.ceres import Ceres +from bodies.eris import Eris +from bodies.haumea import Haumea +from bodies.makemake import Makemake + # 木卫 from bodies.jupiter_system import Europa, Ganymede, Callisto diff --git a/bodies/body.py b/bodies/body.py index 9e7402045e5e36c289f47cda50413759e50c0003..5aac8d7555637b6cd0f3f646f6fa967e5ac24124 100644 --- a/bodies/body.py +++ b/bodies/body.py @@ -531,6 +531,37 @@ class Body(metaclass=ABCMeta): return body_data + def show_demo(self, size_scale=1000, + position=(0, 0, -5000000), + on_ready_fun=None, + on_timer_changed_fun=None): + from sim_scenes.func import ursina_run + from sim_scenes.func import camera_look_at + from simulators.ursina.ursina_event import UrsinaEvent + + self.size_scale = size_scale + # self.init_position = np.array([0, -3000000, 9000000]) + self.init_position = np.array([0, 0, 0]) + self.init_velocity = np.array([0, 0, 0]) + + def on_ready(): + camera_look_at(self) + on_ready_fun() + + def on_timer_changed(time_data): + on_timer_changed_fun(time_data) + + if callable(on_ready_fun): + UrsinaEvent.on_ready_subscription(on_ready) + + if callable(on_timer_changed_fun): + UrsinaEvent.on_timer_changed_subscription(on_timer_changed) + timer_enabled = True + else: + timer_enabled = False + + ursina_run(bodies=[self], position=position, timer_enabled=timer_enabled) + if __name__ == '__main__': # build_bodies_from_json('../data/sun.json') diff --git a/bodies/ceres.py b/bodies/ceres.py new file mode 100644 index 0000000000000000000000000000000000000000..6e5836ca1dadd97e5835c0091285f47bb5dca10c --- /dev/null +++ b/bodies/ceres.py @@ -0,0 +1,70 @@ +# -*- coding:utf-8 -*- +# title :谷神星 +# description :谷神星 +# author :Python超人 +# date :2023-12-05 +# link :https://gitcode.net/pythoncr/ +# python_version :3.9 +# ============================================================================== +from bodies.body import Body, AU +from bodies import Earth + + +class Ceres(Body): + """ + 谷神星 + ------------------------ + 自转周期: + 远日点: 2.978au + 近日点: 2.5585725au + 逃逸速度: 0.51km/s + 轨道周期: 1680.5日 + 平均速度: 17.882km/s + 天体质量: 9.43✕10²⁰ kg + 平均密度: 2.09 g/cm³ -> 2.09✕10³ kg/m³ + 直径: 大约950km + """ + + def __init__(self, name="谷神星", mass=9.43e20, + init_position=[0, 0, 2.558 * AU], + init_velocity=[-17.882, 0, 0], + texture="ceres.jpg", size_scale=1.0, distance_scale=1.0, + rotation_speed=0, ignore_mass=False, + trail_color=None, show_name=False): + """ + @param name: 谷神星名称 + @param mass: 谷神星质量 (kg) + @param init_position: 初始位置 (km) + @param init_velocity: 初始速度 (km/s) + @param texture: 纹理图片 + @param size_scale: 尺寸缩放 + @param distance_scale: 距离缩放 + @param rotation_speed: 自旋速度(度/小时) + @param ignore_mass: 是否忽略质量(如果为True,则不计算引力) + TODO: 注意:这里的算法是基于牛顿的万有引力(质量为0不受引力的影响在天体物理学中是不严谨) + @param trail_color:谷神星拖尾颜色(默认天体颜色) + @param show_name: 是否显示谷神星名称 + @param gravity_only_for_earth: 如果为True,则仅适用于地球的重力,与其他天体之间的重力不会受到影响 + """ + params = { + "name": name, + "mass": mass, + "init_position": init_position, + "init_velocity": init_velocity, + "density": 2.09e3, + "color": (162, 162, 162), + "texture": texture, + "size_scale": size_scale, + "distance_scale": distance_scale, + "rotation_speed": rotation_speed, + "ignore_mass": ignore_mass, + "trail_color": trail_color, + "show_name": show_name + } + super().__init__(**params) + + +if __name__ == '__main__': + ceres = Ceres() + ceres.show_demo(size_scale=1000) + print(ceres) diff --git a/bodies/eris.py b/bodies/eris.py new file mode 100644 index 0000000000000000000000000000000000000000..f4621758c243e7009922ecd4809858aafa27000e --- /dev/null +++ b/bodies/eris.py @@ -0,0 +1,70 @@ +# -*- coding:utf-8 -*- +# title :阋神星 +# description :阋神星 +# author :Python超人 +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ +# python_version :3.8 +# ============================================================================== +from bodies.body import Body, AU +from bodies import Earth + + +class Eris(Body): + """ + 阋神星 + ------------------------ + 自转周期: 14.56 天 + 逃逸速度: 1.38km/s + 轨道周期: 559.07 年 + 平均速度: 3.436 km/s + 天体质量: 1.6466✕10²² kg + 平均密度: 2.43 g/cm³ -> 2.43✕10³ kg/m³ + 直 径: 2326 km + 远日点 97.56 AU 14.60×109 km + 近日点 37.77 AU 5.65×109 km + """ + + def __init__(self, name="阋神星", mass=1.6466e22, + init_position=[0, 0, 37.77 * AU], + init_velocity=[-3.436, 0, 0], + texture="eris.png", size_scale=1.0, distance_scale=1.0, + rotation_speed=0, ignore_mass=False, + trail_color=None, show_name=False): + """ + @param name: 阋神星名称 + @param mass: 阋神星质量 (kg) + @param init_position: 初始位置 (km) + @param init_velocity: 初始速度 (km/s) + @param texture: 纹理图片 + @param size_scale: 尺寸缩放 + @param distance_scale: 距离缩放 + @param rotation_speed: 自旋速度(度/小时) + @param ignore_mass: 是否忽略质量(如果为True,则不计算引力) + TODO: 注意:这里的算法是基于牛顿的万有引力(质量为0不受引力的影响在天体物理学中是不严谨) + @param trail_color:阋神星拖尾颜色(默认天体颜色) + @param show_name: 是否显示阋神星名称 + @param gravity_only_for_earth: 如果为True,则仅适用于地球的重力,与其他天体之间的重力不会受到影响 + """ + params = { + "name": name, + "mass": mass, + "init_position": init_position, + "init_velocity": init_velocity, + "density": 2.43e3, + "color": (162, 162, 162), + "texture": texture, + "size_scale": size_scale, + "distance_scale": distance_scale, + "rotation_speed": rotation_speed, + "ignore_mass": ignore_mass, + "trail_color": trail_color, + "show_name": show_name + } + super().__init__(**params) + + +if __name__ == '__main__': + eris = Eris() + eris.show_demo(size_scale=1000) + print(eris) diff --git a/bodies/haumea.py b/bodies/haumea.py new file mode 100644 index 0000000000000000000000000000000000000000..c6de68cec1276fbf7c49c0357016665399666e01 --- /dev/null +++ b/bodies/haumea.py @@ -0,0 +1,69 @@ +# -*- coding:utf-8 -*- +# title :妊神星 +# description :妊神星 +# author :Python超人 +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ +# python_version :3.8 +# ============================================================================== +from bodies.body import Body, AU +from bodies import Earth + + +class Haumea(Body): + """ + 妊神星 + ------------------------ + 自转周期: 0.163139208 天 + 逃逸速度: 0.809km/s + 轨道周期: 103647 天(283.77 年) + 平均速度: 4.484 km/s + 天体质量: 4.006✕10²¹ kg + 平均密度: 2.018 g/cm³ -> 2.018✕10³ kg/m³ + 直 径: 1560 km [9](2100×1680×1074 km) + 近日点为: 35 AU,轨道倾角为28°。 [15]它于1992年初通过了远日点, [22]当前距太阳50多天文单位(AU) + """ + + def __init__(self, name="妊神星", mass=4.006e21, + init_position=[0, 0, 50 * AU], + init_velocity=[-4.484, 0, 0], + texture="haumea.png", size_scale=1.0, distance_scale=1.0, + rotation_speed=0, ignore_mass=False, + trail_color=None, show_name=False): + """ + @param name: 妊神星名称 + @param mass: 妊神星质量 (kg) + @param init_position: 初始位置 (km) + @param init_velocity: 初始速度 (km/s) + @param texture: 纹理图片 + @param size_scale: 尺寸缩放 + @param distance_scale: 距离缩放 + @param rotation_speed: 自旋速度(度/小时) + @param ignore_mass: 是否忽略质量(如果为True,则不计算引力) + TODO: 注意:这里的算法是基于牛顿的万有引力(质量为0不受引力的影响在天体物理学中是不严谨) + @param trail_color:妊神星拖尾颜色(默认天体颜色) + @param show_name: 是否显示妊神星名称 + @param gravity_only_for_earth: 如果为True,则仅适用于地球的重力,与其他天体之间的重力不会受到影响 + """ + params = { + "name": name, + "mass": mass, + "init_position": init_position, + "init_velocity": init_velocity, + "density": 2.018e3, + "color": (162, 162, 162), + "texture": texture, + "size_scale": size_scale, + "distance_scale": distance_scale, + "rotation_speed": rotation_speed, + "ignore_mass": ignore_mass, + "trail_color": trail_color, + "show_name": show_name + } + super().__init__(**params) + + +if __name__ == '__main__': + haumea = Haumea() + print(haumea) + haumea.show_demo(size_scale=1000) diff --git a/bodies/makemake.py b/bodies/makemake.py new file mode 100644 index 0000000000000000000000000000000000000000..57598e440c0fbaef61b006e7531f1ad2b735d690 --- /dev/null +++ b/bodies/makemake.py @@ -0,0 +1,71 @@ +# -*- coding:utf-8 -*- +# title :鸟神星 +# description :鸟神星 +# author :Python超人 +# date :2023-12-05 +# link :https://gitcode.net/pythoncr/ +# python_version :3.9 +# ============================================================================== +from bodies.body import Body, AU +from bodies import Earth + + +class Makemake(Body): + """ + 鸟神星 + ------------------------ + 自转周期: + 远日点: 7 939.7 Gm(53.074 AU); + 近日点: 5760.8 Gm(38.509 AU); + 逃逸速度: 0.84 km/s + 轨道周期: 113183 天(约 310 年) + 平均速度: 4.419 km/s + 天体质量: 4×10²¹ kg + 平均密度: 2 g/cm³ -> 2✕10³ kg/m³ + 直 径: 大约是冥王星的2/3, 1,500+400-200公里 + + """ + + def __init__(self, name="鸟神星", mass=4e21, + init_position=[0, 0, 51 * AU], + init_velocity=[-4.419, 0, 0], + texture="haumea.jpg", size_scale=1.0, distance_scale=1.0, + rotation_speed=0, ignore_mass=False, + trail_color=None, show_name=False): + """ + @param name: 鸟神星名称 + @param mass: 鸟神星质量 (kg) + @param init_position: 初始位置 (km) + @param init_velocity: 初始速度 (km/s) + @param texture: 纹理图片 + @param size_scale: 尺寸缩放 + @param distance_scale: 距离缩放 + @param rotation_speed: 自旋速度(度/小时) + @param ignore_mass: 是否忽略质量(如果为True,则不计算引力) + TODO: 注意:这里的算法是基于牛顿的万有引力(质量为0不受引力的影响在天体物理学中是不严谨) + @param trail_color:鸟神星拖尾颜色(默认天体颜色) + @param show_name: 是否显示鸟神星名称 + @param gravity_only_for_earth: 如果为True,则仅适用于地球的重力,与其他天体之间的重力不会受到影响 + """ + params = { + "name": name, + "mass": mass, + "init_position": init_position, + "init_velocity": init_velocity, + "density": 2.e3, + "color": (162, 162, 162), + "texture": texture, + "size_scale": size_scale, + "distance_scale": distance_scale, + "rotation_speed": rotation_speed, + "ignore_mass": ignore_mass, + "trail_color": trail_color, + "show_name": show_name + } + super().__init__(**params) + + +if __name__ == '__main__': + makemake = Makemake() + makemake.show_demo() + print(makemake) diff --git a/sim_lab/earth_moon_topo_sim.py b/sim_lab/earth_moon_topo_sim.py new file mode 100644 index 0000000000000000000000000000000000000000..da7fa062b6dcf2f35f3eb521e9bdb2b9a1f5a80f --- /dev/null +++ b/sim_lab/earth_moon_topo_sim.py @@ -0,0 +1,45 @@ +# -*- coding:utf-8 -*- +# title :月球和地球地形相似模拟 +# description :月球和地球地形相似模拟 +# author :Python超人 +# date :2023-05-01 +# link :https://gitcode.net/pythoncr/ +# python_version :3.8 +# ============================================================================== +from bodies import Earth, Moon +from common.consts import SECONDS_PER_DAY, SECONDS_PER_WEEK, SECONDS_PER_MONTH +from sim_scenes.func import ursina_run, camera_look_at, create_sphere_sky +from simulators.ursina.ursina_config import UrsinaConfig +from simulators.ursina.ursina_event import UrsinaEvent + +if __name__ == '__main__': + """ + 月球和地球地形相似模拟 + """ + earth = Earth(init_position=[0, 0, 0], rotation_speed=0, rotate_angle=0, + init_velocity=[0, 0, 0], size_scale=4e1) # 地球放大 5 倍,距离保持不变 + moon = Moon(init_position=[0, 0, 0], rotation_speed=0, + init_velocity=[0, 0, 0], size_scale=8e1) # 月球放大 10 倍,距离保持不变 + + earth.rotation_speed = 0 + + bodies = [earth, moon] + + + def on_ready(): + # 运行前触发 + create_sphere_sky(scale=8000) + + + # 运行前会触发 on_ready + UrsinaEvent.on_ready_subscription(on_ready) + + # 使用 ursina 查看的运行效果 + # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 + # position = 左-右+、上+下-、前+后- + ursina_run(bodies, SECONDS_PER_WEEK, + position=(0, 0, -1000000), + gravity_works=False, + cosmic_bg='', + show_grid=False, + show_trail=True) diff --git a/sim_lab/the_lost_planet.py b/sim_lab/the_lost_planet.py new file mode 100644 index 0000000000000000000000000000000000000000..2fac2b56247cb8821ff0451c55aa7abe61f63e87 --- /dev/null +++ b/sim_lab/the_lost_planet.py @@ -0,0 +1,112 @@ +# -*- coding:utf-8 -*- +# title :太阳系中消失的行星 +# description :太阳系中消失的行星 +# author :Python超人 +# date :2023-12-05 +# link :https://gitcode.net/pythoncr/ +# python_version :3.9 +# ============================================================================== +from bodies import Sun, Mercury, Venus, Earth, Mars, Moon, Ceres, Jupiter, Saturn, Uranus, Neptune, Pluto, Asteroids +from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, SECONDS_PER_MONTH, SECONDS_PER_YEAR, AU +from sim_scenes.func import mayavi_run, ursina_run, create_sphere_sky +from sim_scenes.universe_sim_scenes import UniverseSimScenes +from simulators.ursina.ursina_event import UrsinaEvent + +if __name__ == '__main__': + sun = Sun(size_scale=0.4e2) + asteroids = Asteroids(size_scale=1.08e2, parent=sun) # 小行星模拟(仅 ursina 模拟器支持) + moon = Moon(size_scale=3e3, init_position=[0, 0, (0.4 + 2.4) * AU]) + ceres = Ceres(size_scale=3e3) + jupiter = Jupiter(size_scale=0.68e3) + saturn = Saturn(size_scale=0.68e3) + bodies = [ + sun, # 太阳放大 80 倍 + Mercury(size_scale=3e3), # 水星放大 4000 倍 + Venus(size_scale=3e3), # 金星放大 4000 倍 + Earth(size_scale=3e3), # 地球放大 4000 倍 + Mars(size_scale=3e3), # 火星放大 4000 倍 + asteroids, + moon, + ceres, + # Earth(size_scale=3e3, init_position=[0, 0, (2.17) * AU]), # 地球放大 4000 倍 + # Earth(size_scale=3e3, init_position=[0, 0, (3.64) * AU]), # 地球放大 4000 倍 + jupiter, # 木星放大 680 倍 + saturn, # 土星放大 680 倍 + Uranus(size_scale=0.8e3), # 天王星放大 800 倍 + Neptune(size_scale=1e3), # 海王星放大 1000 倍 + ] + # 水星 0.4AU + # 金星 0.4+0.3 AU + # 地球 0.4+0.6 AU + # 火星 0.4+1.2 AU + # 木星 0.4+4.8 AU + # 土星 0.4+9.6 AU + # 天王星 0.4+19.2 AU + # d = (n+4)/10 + # an = 0.4+0.3×(2n-2) + planet_no = -1 + for idx, body in enumerate(bodies): + if isinstance(body, Asteroids): + continue + body.rotation_speed = 0 + planet_no += 1 + # body.init_velocity = [0, 0, 0] + # an = 0.4 + 0.3 * pow(2,idx) + # an = (idx+4)/10 + # 其中k=0,1,2,4,8,16,32,64,128 (0以后数字为2的2次方) + # 行星 公式推得值 实测值 + # 金星 0.7 0.72 + # 地球 1 1 + # 火星 1.6 1.52 + # 谷神星 2.8 2.9 [1] + # 木星 5.2 5.2 + # 土星 10 9.54 + # 天王星 19.6 19.18 + # 海王星 38.8 30.06 + # 冥王星 77.2 39.44 + # 提丢斯-波得定则 + # https://baike.baidu.com/item/%E6%8F%90%E4%B8%A2%E6%96%AF-%E6%B3%A2%E5%BE%97%E5%AE%9A%E5%88%99/859407 + # 小行星 2.17-3.64天文单位 + if planet_no == 0: + continue + elif planet_no == 1: + an = 0.4 + else: + an = 0.4 + 0.3 * pow(2, planet_no - 2) + print(body.name, an, body.position[2] / AU) + + + def on_ready(): + """ + 事件绑定后,模拟器运行前会触发 + @return: + """ + from ursina import camera + # 创建天空 + # create_sphere_sky(scale=20000) + camera.clip_plane_near = 0.1 + camera.clip_plane_far = 1000000 + + # camera.look_at(saturn.planet) + # camera.look_at(sun.planet) + # camera.rotation_y = 90 + + # UniverseSimScenes.show_grid_axises() + + asteroids.planet.enabled = False + # moon.planet.enabled = False + + + # 运行前会触发 on_ready + UrsinaEvent.on_ready_subscription(on_ready) + # 使用 ursina 查看的运行效果 + # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 + # position = 左-右+、上+下-、前+后- + ursina_run(bodies, + SECONDS_PER_YEAR, + gravity_works=False, + position=(0, 2 * AU, -11 * AU), + # position=(0, 20 * AU, 10 * AU), + # position=(0, 20 * AU, 0), + cosmic_bg='', + show_grid=False) diff --git a/textures/ceres.jpg b/textures/ceres.jpg new file mode 100644 index 0000000000000000000000000000000000000000..963443c1641977faeb62010bb6ec712902d9884e Binary files /dev/null and b/textures/ceres.jpg differ diff --git a/textures/ceres.png b/textures/ceres.png new file mode 100644 index 0000000000000000000000000000000000000000..26f60e65537bd211b742f7f5ce6e66bd2a5f9f39 Binary files /dev/null and b/textures/ceres.png differ diff --git a/textures/eris.png b/textures/eris.png new file mode 100644 index 0000000000000000000000000000000000000000..eccc3bac85960561a3244c968fdd08e51fee1e82 Binary files /dev/null and b/textures/eris.png differ diff --git a/textures/haumea.jpg b/textures/haumea.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0221c513e577ab4a9e9d2e6e8e094b5c0a89803c Binary files /dev/null and b/textures/haumea.jpg differ diff --git a/textures/makemake.png b/textures/makemake.png new file mode 100644 index 0000000000000000000000000000000000000000..967538e8cb586a8d988c3ed5e7429144ea2ad2de Binary files /dev/null and b/textures/makemake.png differ