diff --git a/data/tri_bodies_sim_perfect_02.json b/data/tri_bodies_sim_perfect_02.json new file mode 100644 index 0000000000000000000000000000000000000000..be003294da2058f28ccad6f77db366834c3e74a8 --- /dev/null +++ b/data/tri_bodies_sim_perfect_02.json @@ -0,0 +1,81 @@ +{ + "bodies": [ + { + "name": "红轨太阳A", + "mass": 2e+30, + "init_position": [ + 0.0, + 518222240.0, + 0.0 + ], + "init_velocity": [ + -14.890000343322754, + 0.0, + 0.0 + ], + "density": 1408.0, + "color": [ + 255, + 0, + 0 + ], + "texture": "sun2.jpg", + "size_scale": 50.0, + "distance_scale": 1.0 + }, + { + "name": "绿轨太阳B", + "mass": 2e+30, + "init_position": [ + -299195744.0, + 0.0, + 0.0 + ], + "init_velocity": [ + 7.445000171661377, + -12.895118713378906, + 0.0 + ], + "density": 1408.0, + "color": [ + 0, + 255, + 0 + ], + "texture": "sun2.jpg", + "size_scale": 50.0, + "distance_scale": 1.0 + }, + { + "name": "蓝轨太阳C", + "mass": 2e+30, + "init_position": [ + 299195744.0, + 0.0, + 0.0 + ], + "init_velocity": [ + 7.445000171661377, + 12.895118713378906, + 0.0 + ], + "density": 1408.0, + "color": [ + 0, + 0, + 255 + ], + "texture": "sun2.jpg", + "size_scale": 50.0, + "distance_scale": 1.0 + } + ], + "params": { + "dt": 31536000, + "position": [ + 0, + 149597870.7, + -1495978707.0 + ] + } +} \ No newline at end of file diff --git a/data/tri_bodies_sim_perfect_03.json b/data/tri_bodies_sim_perfect_03.json new file mode 100644 index 0000000000000000000000000000000000000000..be003294da2058f28ccad6f77db366834c3e74a8 --- /dev/null +++ b/data/tri_bodies_sim_perfect_03.json @@ -0,0 +1,81 @@ +{ + "bodies": [ + { + "name": "红轨太阳A", + "mass": 2e+30, + "init_position": [ + 0.0, + 518222240.0, + 0.0 + ], + "init_velocity": [ + -14.890000343322754, + 0.0, + 0.0 + ], + "density": 1408.0, + "color": [ + 255, + 0, + 0 + ], + "texture": "sun2.jpg", + "size_scale": 50.0, + "distance_scale": 1.0 + }, + { + "name": "绿轨太阳B", + "mass": 2e+30, + "init_position": [ + -299195744.0, + 0.0, + 0.0 + ], + "init_velocity": [ + 7.445000171661377, + -12.895118713378906, + 0.0 + ], + "density": 1408.0, + "color": [ + 0, + 255, + 0 + ], + "texture": "sun2.jpg", + "size_scale": 50.0, + "distance_scale": 1.0 + }, + { + "name": "蓝轨太阳C", + "mass": 2e+30, + "init_position": [ + 299195744.0, + 0.0, + 0.0 + ], + "init_velocity": [ + 7.445000171661377, + 12.895118713378906, + 0.0 + ], + "density": 1408.0, + "color": [ + 0, + 0, + 255 + ], + "texture": "sun2.jpg", + "size_scale": 50.0, + "distance_scale": 1.0 + } + ], + "params": { + "dt": 31536000, + "position": [ + 0, + 149597870.7, + -1495978707.0 + ] + } +} \ No newline at end of file diff --git a/scenes/tri_bodies_sim_perfect.py b/scenes/tri_bodies_sim_perfect.py new file mode 100644 index 0000000000000000000000000000000000000000..5626bf40ef19bdbc81bdd7c75b5a60058fcbac66 --- /dev/null +++ b/scenes/tri_bodies_sim_perfect.py @@ -0,0 +1,56 @@ +# -*- coding:utf-8 -*- +# title :三体场景模拟01 +# description :三体场景模拟(3个太阳、1个地球) +# author :Python超人 +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ +# python_version :3.8 +# ============================================================================== +from bodies import Sun, Earth +from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, AU, SECONDS_PER_MONTH, SECONDS_PER_YEAR +from scenes.func import mayavi_run, ursina_run + +if __name__ == '__main__': + """ + 3个太阳、1个地球(效果1) + 可以修改影响效果的参数为: + 1、三个方向的初始位置 init_position[x, y, z] + 2、三个方向的初始速度 init_velocity[x, y, z] + 3、天体质量 mass + """ + import math + + mass = 2e30 + r = 2 * AU + # p = 12 # 三体转圆形花 + p = 14.88 # 三体转圈近似圆形 + # p = 16 # 三体转圆形花 + # p = 18 # 三体转圆形花 + # p = 19 # 三体转圆形花 + bodies = [ + Sun(name="红轨太阳A", mass=mass, + init_position=[0, math.sqrt(3) * r, 0], + init_velocity=[-p, 0, 0], + color=(255, 0, 0), + size_scale=5e1, texture="sun2.jpg"), # 太阳放大 100 倍 + Sun(name="绿轨太阳B", mass=mass, + init_position=[-r, 0, 0], + init_velocity=[1 / 2 * p, -math.sqrt(3) / 2 * p, 0], + color=(0, 255, 0), + size_scale=5e1, texture="sun2.jpg"), # 太阳放大 100 倍 + Sun(name="蓝轨太阳C", mass=mass, + init_position=[r, 0, 0], + init_velocity=[1 / 2 * p, math.sqrt(3) / 2 * p, 0], + color=(0, 0, 255), + size_scale=5e1, texture="sun2.jpg"), # 太阳放大 100 倍 + # Earth(init_position=[0, -349597870.700, 0], + # init_velocity=[15.50, 0, 0], + # size_scale=4e3, distance_scale=1), # 地球放大 4000 倍,距离保持不变 + ] + # 使用 mayavi 查看的运行效果 + # mayavi_run(bodies, SECONDS_PER_WEEK, view_azimuth=0) + + # 使用 ursina 查看的运行效果 + # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 + # position = 左-右+、上+下-、前+后- + ursina_run(bodies, SECONDS_PER_YEAR, position=(3 * AU, AU, -4 * AU)) diff --git a/scenes/ursina_json_sim.py b/scenes/ursina_json_sim.py index 8c7c29fa3de98763caa2826d89bbb4a5e3737e38..d9e291c8495731612bf3975ebd336a36a2d402bc 100644 --- a/scenes/ursina_json_sim.py +++ b/scenes/ursina_json_sim.py @@ -18,8 +18,12 @@ if __name__ == '__main__': # bodies, params = Body.build_bodies_from_json('../data/sun_earth.json') # TODO: 去掉注释,在地球上看月相演示变化过程演示 # bodies, params = Body.build_bodies_from_json('../data/sun_earth_moon.json') - # TODO: 去掉注释,完美数据的三体模型的演示01 + # TODO: 去掉注释,完美数据的三体模型的演示01(等边三角形) # bodies, params = Body.build_bodies_from_json('../data/tri_bodies_sim_perfect_01.json') + # TODO: 去掉注释,完美数据的三体模型的演示02(等边三角形) + # bodies, params = Body.build_bodies_from_json('../data/tri_bodies_sim_perfect_02.json') + # TODO: 去掉注释,完美数据的三体模型的演示03(等边三角形) + bodies, params = Body.build_bodies_from_json('../data/tri_bodies_sim_perfect_03.json') # TODO: 去掉注释,引力弹弓的演示 # bodies, params = Body.build_bodies_from_json('../data/gravity_slingshot.json')