From 39013a210e0d898ec781037a8ea427a179720b9d Mon Sep 17 00:00:00 2001 From: march3 Date: Sun, 16 Apr 2023 20:53:58 +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/science/free_fall_of_ball.py | 34 ++++++++++++---------- simulators/ursina/entities/entity_utils.py | 1 - simulators/ursina/entities/planet.py | 1 + 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/sim_scenes/science/free_fall_of_ball.py b/sim_scenes/science/free_fall_of_ball.py index ff85488..7681188 100644 --- a/sim_scenes/science/free_fall_of_ball.py +++ b/sim_scenes/science/free_fall_of_ball.py @@ -17,22 +17,24 @@ if __name__ == '__main__': """ # 地球在中心位置 earth = Earth(init_position=[0, 0, 0], size_scale=1, texture="earth_hd.jpg", init_velocity=[0, 0, 0]) - # e.raduis = 6373.22 - # math.sqrt(pow(6373.22 + 500, 2) + pow(500, 2))-6373.22 - # math.sqrt(pow(6373.22 + 1000, 2) + pow(500, 2))-6373.22 - # 创建的3个不同质量,不同高度的物体,观察地球表面上的加速度 - bodies = [ - earth, - Football(mass=500, size_scale=3e2, trail_color=[255, 0, 0], - init_position=[-500, earth.raduis + 500, 0], # 球在地面上 518 多公里(向左偏移500公里) - init_velocity=[0, 0, 0], gravity_only_for=[earth]), - Football(mass=1000, size_scale=3e2, trail_color=[0, 255, 0], - init_position=[0, earth.raduis + 800, 0], # 球在地面上 800 多公里 - init_velocity=[0, 0, 0], gravity_only_for=[earth]), - Football(mass=5000, size_scale=3.8e2, trail_color=[0, 0, 255], - init_position=[500, earth.raduis + 1000, 0], # 球在地面上 1016 多公里(向右偏移500公里) - init_velocity=[0, 0, 0], gravity_only_for=[earth]), - ] + # earth.raduis = 6373.22 + # 创建的3个不同质量,不同高度的球,观察这3个球打到地球表面上的加速度 + ball_1 = Football(mass=500, size_scale=3e2, trail_color=[255, 0, 0], + # 球在地面上 518 多公里处 + # 518 = sqrt[(earth.raduis + 500)² + (-500)²] - earth.raduis + init_position=[-500, earth.raduis + 500, 0], + init_velocity=[0, 0, 0], gravity_only_for=[earth]) + ball_2 = Football(mass=1000, size_scale=3e2, trail_color=[0, 255, 0], + # 球在地面上 800 多公里处 + init_position=[0, earth.raduis + 800, 0], + init_velocity=[0, 0, 0], gravity_only_for=[earth]) + ball_3 = Football(mass=5000, size_scale=3.8e2, trail_color=[0, 0, 255], + # 球在地面上 1016 多公里处 + # 1016 = sqrt[(earth.raduis + 1000)² + 500²] - earth.raduis + init_position=[500, earth.raduis + 1000, 0], + init_velocity=[0, 0, 0], gravity_only_for=[earth]) + + bodies = [earth, ball_1, ball_2, ball_3] # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 diff --git a/simulators/ursina/entities/entity_utils.py b/simulators/ursina/entities/entity_utils.py index bb9c2f3..369609c 100644 --- a/simulators/ursina/entities/entity_utils.py +++ b/simulators/ursina/entities/entity_utils.py @@ -295,4 +295,3 @@ def create_trail_info(body, trail): if trail is not None: trail.entity_infos = {"velocity": [vel_value, vel_direction, vel_position], "acceleration": [acc_value, acc_direction, acc_position]} - diff --git a/simulators/ursina/entities/planet.py b/simulators/ursina/entities/planet.py index fba2d4b..3af4c91 100644 --- a/simulators/ursina/entities/planet.py +++ b/simulators/ursina/entities/planet.py @@ -100,6 +100,7 @@ class Planet(Entity): ) if hasattr(self.body, "rotate_angle"): if self.body.rotate_angle != 0: + # 为了给天体增加一个倾斜角,增加了一个Entity self.rotate_angle = self.body.rotate_angle self.main_entity = Entity() self.main_entity.rotation_x = self.rotate_angle -- GitLab