From 5d5b19a966897f2067d424156f97fb4da7a7a11e Mon Sep 17 00:00:00 2001 From: march3 Date: Sun, 23 Mar 2025 16:41:04 +0800 Subject: [PATCH] =?UTF-8?q?Python=E8=B6=85=E4=BA=BA-=E5=AE=87=E5=AE=99?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sim_scenes/tri_bodies/two_bodies_02.py | 33 +++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/sim_scenes/tri_bodies/two_bodies_02.py b/sim_scenes/tri_bodies/two_bodies_02.py index 7d46c9c..9103c92 100644 --- a/sim_scenes/tri_bodies/two_bodies_02.py +++ b/sim_scenes/tri_bodies/two_bodies_02.py @@ -8,9 +8,11 @@ # ============================================================================== from bodies import Sun, Earth from common.consts import SECONDS_PER_WEEK, SECONDS_PER_YEAR, SECONDS_PER_DAY, AU, G -from sim_scenes.func import mayavi_run, mpl_run, ursina_run +from sim_scenes.func import mayavi_run, mpl_run, ursina_run, create_sphere_sky import math +from simulators.ursina.ursina_event import UrsinaEvent + if __name__ == '__main__': r2 = 0.02 * AU r1 = 2 * r2 @@ -28,7 +30,9 @@ if __name__ == '__main__': vyA = -math.sqrt((G * mA * mB) / math.pow(r1 * 1000 + r2 * 1000, 2) * r1 * 1000 / mA) # 万有引力常量 *mA * mB/ math.pow(r1+r2,2) = mB*math.pow(vyB,2)/r2 vyB = math.sqrt((G * mA * mB) / math.pow(r1 * 1000 + r2 * 1000, 2) * r2 * 1000 / mB) - vA, vB = [vxA, vyA / 1000, 0], [vxB, vyB / 1000, 0] + vz = 0.02 + vz= 0 + vA, vB = [vxA, vyA / 1000, vz], [vxB, vyB / 1000, vz] # vA, vB = [0,0,0],[0,0,0] bodies = [ Earth(name="A", rotation_speed=1, mass=mA, @@ -37,7 +41,30 @@ if __name__ == '__main__': init_position=pB, init_velocity=vB, size_scale=5e1, distance_scale=1) ] + + def on_ready(): + """ + 事件绑定后,模拟器运行前会触发 + @return: + """ + # 创建天空 + # camera.clip_plane_near = 0.1 + from ursina import camera, application + camera.clip_plane_far = 1000000 + create_sphere_sky(scale=200000) + application.time_scale = 5 + + + UrsinaEvent.on_ready_subscription(on_ready) # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- - ursina_run(bodies, SECONDS_PER_YEAR, position=(r1, r1, -7 * r2), show_trail=True) + ursina_run(bodies, + SECONDS_PER_YEAR, + cosmic_bg='', + # show_grid=False, + position=(r1, r1, -7 * r2), + show_camera_info=False, + show_control_info=False, + timer_enabled=True, + show_trail=True) -- GitLab