From 0b08abec603349564ec45c25a62f340bac87e8a1 Mon Sep 17 00:00:00 2001 From: march3 Date: Sat, 8 Apr 2023 15:28:03 +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/earth/parabolic_curve.py | 41 +++++++++++++++++++++++++++++ sim_scenes/func.py | 14 ++++++++++ 2 files changed, 55 insertions(+) create mode 100644 sim_scenes/earth/parabolic_curve.py diff --git a/sim_scenes/earth/parabolic_curve.py b/sim_scenes/earth/parabolic_curve.py new file mode 100644 index 0000000..306312a --- /dev/null +++ b/sim_scenes/earth/parabolic_curve.py @@ -0,0 +1,41 @@ +# -*- coding:utf-8 -*- +# title :抛物线模拟 +# description :抛物线模拟 +# author :Python超人 +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ +# python_version :3.8 +# ============================================================================== +from bodies import Moon, Earth, Body +from common.consts import SECONDS_PER_HOUR, SECONDS_PER_MINUTE +from sim_scenes.func import ursina_run, get_vector2d_velocity + +if __name__ == '__main__': + """ + 抛物线模拟 + """ + # TODO: 修改抛出物体的速度 + velocity = 8 # 物体飞不出地球太远,就落地 + # velocity = 10 # 物体能飞出地球很远,但还是无法摆脱地球引力 + # velocity = 11.2 # 脱离地球引力直接飞出。速度11.2千米/秒为脱离地球引力的速度叫第二宇宙速度 + + # 根据速度、角度获取矢量速度(vx、vy) -> vx² + vy² = velocity² + vx, vy = get_vector2d_velocity(velocity, angle=10) + + # 地球在中心位置 + e = Earth(init_position=[0, 0, 0], size_scale=1, texture="earth_hd.jpg", init_velocity=[0, 0, 0]) + bodies = [ + e, + Moon(name='小月球', mass=500, size_scale=2e6, + init_position=[0, e.raduis + 300, 0], # 在地球表面上 + init_velocity=[vx, vy, 0]), + ] + + # 使用 ursina 查看的运行效果 + # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 + # position = 左-右+、上+下-、前+后- + ursina_run(bodies, SECONDS_PER_HOUR / 2, # 一秒相当于半个小时 + position=(0, 0, -45000), + show_trail=True, + show_timer=True, + view_closely=0.001) diff --git a/sim_scenes/func.py b/sim_scenes/func.py index 271fac2..7bcb635 100644 --- a/sim_scenes/func.py +++ b/sim_scenes/func.py @@ -12,6 +12,7 @@ from common.system import System from simulators.ursina.ursina_config import UrsinaConfig from simulators.ursina.ursina_event import UrsinaEvent from common.consts import LIGHT_SPEED +import math def mayavi_run(bodies, dt=SECONDS_PER_WEEK, @@ -229,6 +230,19 @@ def create_text_panel(width=0.35, height=.5): return text +def get_vector2d_velocity(velocity, angle=15): + """ + 根据速度、角度获取矢量速度(vx、vy) + @param velocity: + @param angle: + @return: + """ + vy = math.sin(math.pi * angle / 180) * velocity + vx = math.cos(math.pi * angle / 180) * velocity + # vx² + vy² = velocity² + return vx, vy + + if __name__ == '__main__': from bodies import Sun, Earth -- GitLab