diff --git a/bodies/asteroid.py b/bodies/asteroid.py index a8fb36a6617ca574d8c618492560cdbb900fd3c5..ea2638ef6f3597aa15a6f3dc7640bf5ff255f72b 100644 --- a/bodies/asteroid.py +++ b/bodies/asteroid.py @@ -50,8 +50,8 @@ class Asteroid(Body): def ignore_gravity(self, body): """ 是否忽略引力 - :param body: - :return: + @param body: + @return: """ # 小行星只对恒星有引力,忽略其他行星的引力 if body.is_fixed_star: diff --git a/bodies/asteroids.py b/bodies/asteroids.py index 240feda2b75f30583109260926130b46bb8a67aa..f1b38dfd0a159dc9b4fe4e1e87f405f293735c1c 100644 --- a/bodies/asteroids.py +++ b/bodies/asteroids.py @@ -53,8 +53,8 @@ class Asteroids(Body): def ignore_gravity(self, body): """ 是否忽略引力 - :param body: - :return: + @param body: + @return: """ # 小行星只对恒星有引力,忽略其他行星的引力 # if body.is_fixed_star: diff --git a/bodies/body.py b/bodies/body.py index c0b2d385da56553b09f055d21cb8c4cb363af796..2f8fa63c46009cad966e534ed81c73026f762102 100644 --- a/bodies/body.py +++ b/bodies/body.py @@ -26,20 +26,21 @@ class Body(metaclass=ABCMeta): is_fixed_star=False, trail_color=None, show_name=False): """ 天体类 - :param name: 天体名称 - :param mass: 天体质量 (kg) - :param init_position: 初始位置 (km) - :param init_velocity: 初始速度 (km/s) - :param density: 平均密度 (kg/m³) - :param color: 天体颜色(纹理图片优先) - :param texture: 纹理图片 - :param size_scale: 尺寸缩放 - :param distance_scale: 距离缩放 - :param rotation_speed: 自旋速度(度/小时) - :param parent: 天体的父对象 - :param ignore_mass: 是否忽略质量(如果为True,则不计算引力) - :param is_fixed_star: 是否为恒星 - :param trail_color: 天体拖尾颜色(默认天体颜色) + @param name: 天体名称 + @param mass: 天体质量 (kg) + @param init_position: 初始位置 (km) + @param init_velocity: 初始速度 (km/s) + @param density: 平均密度 (kg/m³) + @param color: 天体颜色(纹理图片优先) + @param texture: 纹理图片 + @param size_scale: 尺寸缩放 + @param distance_scale: 距离缩放 + @param rotation_speed: 自旋速度(度/小时) + @param parent: 天体的父对象 + @param ignore_mass: 是否忽略质量(如果为True,则不计算引力) + @param is_fixed_star: 是否为恒星 + @param trail_color: 天体拖尾颜色(默认天体颜色) + @param show_name: 是否显示天体名称 """ self.__his_pos = [] self.__his_vel = [] @@ -130,7 +131,7 @@ class Body(metaclass=ABCMeta): def init_position(self): """ 获取天体的初始位置(单位:km) - :return: + @return: """ return self.__init_position @@ -138,8 +139,8 @@ class Body(metaclass=ABCMeta): def init_position(self, value): """ 设置天体的初始位置(单位:km) - :param value: - :return: + @param value: + @return: """ self.__init_position = np.array(value, dtype='float32') self.__position = copy.deepcopy(self.__init_position) @@ -148,7 +149,7 @@ class Body(metaclass=ABCMeta): def init_velocity(self): """ 获取天体的初始速度 (km/s) - :return: + @return: """ return self.__init_velocity @@ -156,8 +157,8 @@ class Body(metaclass=ABCMeta): def init_velocity(self, value): """ 设置天体的初始速度 (km/s) - :param value: - :return: + @param value: + @return: """ self.__init_velocity = np.array(value, dtype='float32') self.__velocity = copy.deepcopy(self.__init_velocity) @@ -166,7 +167,7 @@ class Body(metaclass=ABCMeta): def has_rings(self): """ 是否为带光环的天体(土星为 True) - :return: + @return: """ return self.__has_rings @@ -178,7 +179,7 @@ class Body(metaclass=ABCMeta): def is_fixed_star(self): """ 是否为恒星(太阳为 True) - :return: + @return: """ return self.__is_fixed_star @@ -190,7 +191,7 @@ class Body(metaclass=ABCMeta): def position(self): """ 获取天体的位置(单位:km) - :return: + @return: """ return self.__position @@ -198,8 +199,8 @@ class Body(metaclass=ABCMeta): def position(self, value): """ 设置天体的位置(单位:km) - :param value: - :return: + @param value: + @return: """ self.__position = value self.__record_history() @@ -208,7 +209,7 @@ class Body(metaclass=ABCMeta): def acceleration(self): """ 获取天体的加速度(单位:km/s²) - :return: + @return: """ return self.__acceleration @@ -216,8 +217,8 @@ class Body(metaclass=ABCMeta): def acceleration(self, value): """ 设置天体的加速度(单位:km/s²) - :param value: - :return: + @param value: + @return: """ self.__acceleration = value self.__record_history() @@ -226,7 +227,7 @@ class Body(metaclass=ABCMeta): def velocity(self): """ 获取天体的速度(单位:km/s) - :return: + @return: """ return self.__velocity @@ -234,8 +235,8 @@ class Body(metaclass=ABCMeta): def velocity(self, value): """ 设置天体的速度(单位:km/s) - :param value: - :return: + @param value: + @return: """ self.__velocity = value self.__record_history() @@ -243,9 +244,9 @@ class Body(metaclass=ABCMeta): def __append_history(self, his_list, data): """ 追加每个位置时刻的历史数据 - :param his_list: - :param data: - :return: + @param his_list: + @param data: + @return: """ # 如果历史记录为0 或者 新增数据和最后的历史数据不相同,则添加 if len(his_list) == 0 or \ @@ -255,7 +256,7 @@ class Body(metaclass=ABCMeta): def __record_history(self): """ 记录每个位置时刻的历史数据 - :return: + @return: """ # 如果历史记录数超过了保留数量,则截断,只保留 __his_reserved_num 数量的历史 if len(self.__his_pos) > self.__his_reserved_num: @@ -272,21 +273,21 @@ class Body(metaclass=ABCMeta): def his_position(self): """ 历史位置 - :return: + @return: """ return self.__his_pos def his_velocity(self): """ 历史瞬时速度 - :return: + @return: """ return self.__his_vel def his_acceleration(self): """ 历史瞬时加速度 - :return: + @return: """ return self.__his_acc @@ -294,7 +295,7 @@ class Body(metaclass=ABCMeta): def mass(self): """ 天体质量 (单位:kg) - :return: + @return: """ return self.__mass @@ -302,7 +303,7 @@ class Body(metaclass=ABCMeta): def rotation_speed(self): """ 自旋速度(度/小时) - :return: + @return: """ return self.__rotation_speed @@ -310,7 +311,7 @@ class Body(metaclass=ABCMeta): def rotation_speed(self, value): """ 自旋速度(度/小时) - :return: + @return: """ self.__rotation_speed = value @@ -318,7 +319,7 @@ class Body(metaclass=ABCMeta): def density(self): """ 平均密度 (单位:kg/m³) - :return: + @return: """ return self.__density @@ -340,7 +341,7 @@ class Body(metaclass=ABCMeta): def raduis(self): """ 天体的半径(单位:km) - :return: + @return: """ # V = ⁴⁄₃πr³ -> r = pow((3V)/(4π),1/3) return pow(3 * self.volume / (4 * math.pi), 1 / 3) @@ -349,7 +350,7 @@ class Body(metaclass=ABCMeta): def diameter(self): """ 天体的直径(单位:km) - :return: + @return: """ return self.raduis * 2 @@ -361,8 +362,8 @@ class Body(metaclass=ABCMeta): def ignore_gravity(self, body): """ 是否忽略引力 - :param body: - :return: + @param body: + @return: """ return False @@ -370,7 +371,7 @@ class Body(metaclass=ABCMeta): def position_au(self): """ 获取天体的位置(单位:天文单位 A.U.) - :return: + @return: """ pos = self.position pos_au = pos / AU @@ -385,7 +386,7 @@ class Body(metaclass=ABCMeta): def reset(self): """ 重新设置初始速度和初始位置 - :return: + @return: """ self.position = copy.deepcopy(self.init_position) self.velocity = copy.deepcopy(self.init_velocity) @@ -405,8 +406,8 @@ class Body(metaclass=ABCMeta): def build_bodies_from_json(json_file): """ JSON文件转为天体对象 - :param json_file: - :return: + @param json_file: + @return: """ bodies = [] params = {} @@ -451,8 +452,8 @@ class Body(metaclass=ABCMeta): def exp(body_data): """ 进行表达式分析,将表达式改为eval执行后的结果 - :param body_data: - :return: + @param body_data: + @return: """ # for k in body_data.keys(): diff --git a/bodies/dysen_sphere.py b/bodies/dysen_sphere.py index 54e93bac20f94f007d4a79a052f737016fc36411..ec17cc41e7e2269e7be3894cce01b049025e970e 100644 --- a/bodies/dysen_sphere.py +++ b/bodies/dysen_sphere.py @@ -46,8 +46,8 @@ class DysenSphere(Body): def ignore_gravity(self, body): """ 是否忽略引力 - :param body: - :return: + @param body: + @return: """ return True diff --git a/bodies/fixed_stars/fixed_star.py b/bodies/fixed_stars/fixed_star.py index a2b6069271d318228d88dc6126c64e9ce9afb492..51f3a236a5083c0dbc4cf2d8e6f2ea3cfc0f1ffb 100644 --- a/bodies/fixed_stars/fixed_star.py +++ b/bodies/fixed_stars/fixed_star.py @@ -88,7 +88,7 @@ class FixedStar(Body): def is_fixed_star(self): """ 恒星 - :return: + @return: """ return True diff --git a/bodies/moon.py b/bodies/moon.py index b43c56a2b08bba25ab47275038dad02a6853297c..18bb5f098161b236a163d395d7a635080ed633d2 100644 --- a/bodies/moon.py +++ b/bodies/moon.py @@ -26,7 +26,23 @@ class Moon(Body): init_position=[0, 0, 363104 + 1.12 * AU], init_velocity=[-(29.79 + 1.03), 0, 0], texture="moon.jpg", size_scale=1.0, distance_scale=1.0, - rotation_speed=0.25, ignore_mass=False, trail_color=None, show_name=False): + rotation_speed=0.25, ignore_mass=False, + trail_color=None, show_name=False, + gravity_only_for_earth=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,则不计算引力) + @param trail_color:月球拖尾颜色(默认天体颜色) + @param show_name: 是否显示月球名称 + @param gravity_only_for_earth: 如果为True,则仅适用于地球的重力,与其他天体之间的重力不会受到影响 + """ params = { "name": name, "mass": mass, @@ -43,18 +59,22 @@ class Moon(Body): "show_name": show_name } super().__init__(**params) + self.gravity_only_for_earth = gravity_only_for_earth - # def ignore_gravity(self, body): - # """ - # 是否忽略引力 - # :param body: - # :return: - # """ - # # 月球只对地球有引力,忽略其他的引力 - # if isinstance(body, Earth): - # return False - # - # return True + def ignore_gravity(self, body): + """ + 是否忽略引力 + @param body: + @return: + """ + if self.gravity_only_for_earth: + # 月球只对地球有引力,忽略其他的引力 + if isinstance(body, Earth): + return False + else: + return False + + return True if __name__ == '__main__': diff --git a/bodies/saturn.py b/bodies/saturn.py index 4f9a8bb26797a07c2edca3a4c010e02208f7c071..a5bed5f78306b7ce430a5ba760fc130475249c31 100644 --- a/bodies/saturn.py +++ b/bodies/saturn.py @@ -49,7 +49,7 @@ class Saturn(Body): def has_rings(self): """ 土星带光环的天体 - :return: + @return: """ return True @@ -57,7 +57,7 @@ class Saturn(Body): def rings_color(self): """ 土星光环的颜色 - :return: + @return: """ return 173, 121, 92 diff --git a/bodies/sun.py b/bodies/sun.py index 6327522e8d479ac960d6f974b852d9b712b6e31c..fc17f52ada6fa41ee8cc11cb0ced6560734a9be4 100644 --- a/bodies/sun.py +++ b/bodies/sun.py @@ -46,7 +46,7 @@ class Sun(FixedStar): def is_fixed_star(self): """ 太阳为恒星 - :return: + @return: """ return True diff --git a/common/color_utils.py b/common/color_utils.py index 938e8a084ecf79e6bd0bca7d3ade500b2c8281da..0ec48e41c6e5e3d8d16e73292feb097120b5f30a 100644 --- a/common/color_utils.py +++ b/common/color_utils.py @@ -11,9 +11,9 @@ def conv_to_vec4_color(colour: tuple, alpha=1): """ - :param colour: - :param alpha: - :return: + @param colour: + @param alpha: + @return: """ from ursina import Vec4 if len(colour) == 3: @@ -26,9 +26,9 @@ def conv_to_vec4_color(colour: tuple, alpha=1): def adjust_brightness(color, target_brightness: float = 0.6): """ 调整颜色的亮度到目标 target_brightness(确保亮度不超过 1.0) - :param color: - :param target_brightness:(确保亮度不超过 1.0) - :return: + @param color: + @param target_brightness:(确保亮度不超过 1.0) + @return: """ from ursina import Vec4 # 获取颜色的亮度值 diff --git a/common/func.py b/common/func.py index 28f3aa3f33dfd2fba82440669fd3c4feef04ceca..dfa5602c595ced2401d56f8c330c52449a79a369 100644 --- a/common/func.py +++ b/common/func.py @@ -17,9 +17,9 @@ import math def get_dominant_colors(infile, resize=(20, 20)): """ 获取图片的主要颜色 - :param infile: - :param resize: - :return: + @param infile: + @param resize: + @return: """ image = Image.open(infile) @@ -49,12 +49,12 @@ def get_positions_velocitys(angles, velocity=1, radius=1, radius_offset=None, ve """ 以位置 (0, 0, 0)为中心,随机获取空间上的位置和公转方向的速度集合 (比如:获取大批小行星的位置) - :param angles: 参考中心位置(0, 0, 0)的角度集合 - :param velocity: 速度 - :param radius: 半径(距离中心位置(0, 0, 0)的距离) - :param radius_offset:在半径的基础上,随机偏移的值 - :param velocity_offset:在速度的基础上,随机偏移的值 - :return: + @param angles: 参考中心位置(0, 0, 0)的角度集合 + @param velocity: 速度 + @param radius: 半径(距离中心位置(0, 0, 0)的距离) + @param radius_offset:在半径的基础上,随机偏移的值 + @param velocity_offset:在速度的基础上,随机偏移的值 + @return: """ angles = np.array(angles * np.pi) @@ -99,9 +99,9 @@ def find_file(file_path, default_val=None, find_deep=5): def calculate_distance(pos1, pos2=[0, 0, 0]): """ 计算两点间的距离 - :param pos1: - :param pos2: - :return: + @param pos1: + @param pos2: + @return: """ d = pow(pow(np.array(pos1[0]) - np.array(pos2[0]), 2) + pow(np.array(pos1[1]) - np.array(pos2[1]), 2) + diff --git a/common/image_utils.py b/common/image_utils.py index fc3fe0c0f6d8fd2627592cb69cc4f72fe6a4717b..024cadffb711017c25b1bbd8ef93abc146133614 100644 --- a/common/image_utils.py +++ b/common/image_utils.py @@ -19,13 +19,13 @@ hsv_to_rgb = np.vectorize(colorsys.hsv_to_rgb) def image_file_enhance(imageFilePath, bright, contrast, color, sharpness, saveFolderPath): """ 图像增强之亮度、对比度与饱和度调整 - :param imageFilePath: 图像文件路径 - :param bright: 亮度 - :param contrast: 对比度 - :param color: 饱和度 - :param sharpness: 清晰度 - :param saveFolderPath: 结果保存路径 - :return: + @param imageFilePath: 图像文件路径 + @param bright: 亮度 + @param contrast: 对比度 + @param color: 饱和度 + @param sharpness: 清晰度 + @param saveFolderPath: 结果保存路径 + @return: """ imageFileName = os.path.basename(imageFilePath) imageOriginal = Image.open(imageFilePath) @@ -59,13 +59,13 @@ def image_file_enhance(imageFilePath, bright, contrast, color, sharpness, saveFo def image_enhance(imageOriginal, bright=0, contrast=0, color=0, sharpness=0): """ 图像增强之亮度、对比度与饱和度调整 - :param imageFilePath: 图像文件路径 - :param bright: 亮度 - :param contrast: 对比度 - :param color: 饱和度 - :param sharpness: 清晰度 - :param saveFolderPath: 结果保存路径 - :return: + @param imageFilePath: 图像文件路径 + @param bright: 亮度 + @param contrast: 对比度 + @param color: 饱和度 + @param sharpness: 清晰度 + @param saveFolderPath: 结果保存路径 + @return: """ image = imageOriginal if bright > 0: @@ -194,8 +194,8 @@ def find_texture_root_path(): def find_texture(texture): """ 尝试在多个路径下寻找纹理图片 - :param texture: 纹理图片 - :return: 纹理图片的路径 + @param texture: 纹理图片 + @return: 纹理图片的路径 """ if os.path.exists(texture): return texture @@ -339,8 +339,8 @@ if __name__ == '__main__': # """ # 自适应地调整图片的对比度和亮度。 # -# :param image_path: 图像路径。 -# :return: 调整后的图像对象。 +# @param image_path: 图像路径。 +# @return: 调整后的图像对象。 # """ # if isinstance(src_img, str): # image = Image.open(src_img) @@ -382,8 +382,8 @@ if __name__ == '__main__': # """ # 自适应地调整图片的对比度和亮度。 # -# :param image_path: 图像路径。 -# :return: 调整后的图像对象。 +# @param image_path: 图像路径。 +# @return: 调整后的图像对象。 # """ # if isinstance(src_img, str): # image = Image.open(src_img) @@ -418,8 +418,8 @@ if __name__ == '__main__': # """ # 自适应地调整图片的对比度和亮度。 # -# :param image_path: 图像路径。 -# :return: 调整后的图像对象。 +# @param image_path: 图像路径。 +# @return: 调整后的图像对象。 # """ # if isinstance(src_img, str): # image = Image.open(src_img) diff --git a/common/system.py b/common/system.py index 2ae548e10b76419697e7cb960a0af36d7418c6ea..44c88a42a61382ed9a6abc85d1f5cc6e6e2f9287 100644 --- a/common/system.py +++ b/common/system.py @@ -21,8 +21,8 @@ class System(object): def __init__(self, bodies, max_distance=200 * AU): """ - :param bodies: - :param max_distance:系统的最大范围,超出范围的天体就不显示了 + @param bodies: + @param max_distance:系统的最大范围,超出范围的天体就不显示了 """ self.bodies = bodies # self.adjust_distance_and_velocity() @@ -78,7 +78,7 @@ class System(object): def total_mass(self): """ 总质量 - :return: + @return: """ total_mass = 0.0 for body in self.bodies: @@ -91,7 +91,7 @@ class System(object): def center_of_mass(self): """ 质心 - :return: + @return: """ r = np.zeros(2) for body in self.bodies: @@ -101,8 +101,8 @@ class System(object): def evolve(self, dt): """ - :param dt: - :return: + @param dt: + @return: """ self.calc_bodies_acceleration() @@ -115,9 +115,9 @@ class System(object): def save_to_json(self, json_file_name, params=None): """ - :param json_file_name: - :param params: - :return: + @param json_file_name: + @param params: + @return: """ import json import os @@ -145,14 +145,14 @@ class System(object): def calc_bodies_acceleration(self): """ 计算加速度 - :return: + @return: """ def valid_body(body): """ 判断是否为有效的天体 - :param body: - :return: + @param body: + @return: """ if not body.appeared: # 不显示 return False diff --git a/sim_scenes/func.py b/sim_scenes/func.py index 14c9c6ec67cb1e7f635e6d68b77ddb75d4b8d79e..da4f5f9721834d1e882c7622f8d12b5cb8498e26 100644 --- a/sim_scenes/func.py +++ b/sim_scenes/func.py @@ -20,13 +20,13 @@ def mayavi_run(bodies, dt=SECONDS_PER_WEEK, bgcolor=(1 / 255, 1 / 255, 30 / 255)): """ 用 mayavi 查看运行效果 - :param bodies: 天体 - :param dt: 单位:秒,按时间差进行演变,值越小越精确,但演变速度会慢。 - :param view_azimuth: 观测方位角,可选,float类型(以度为单位,0-360),用x轴投影到x-y平面上的球体上的位置矢量所对的角度。 - :param view_distance: 观测距离,可选,float类型 or 'auto',一个正浮点数,表示距放置相机的焦点的距离。 - :param view_focalpoint: 观测焦点,可选,类型为一个由3个浮点数组成的数组 or 'auto',,代表观测相机的焦点 - :param bgcolor: - :return: + @param bodies: 天体 + @param dt: 单位:秒,按时间差进行演变,值越小越精确,但演变速度会慢。 + @param view_azimuth: 观测方位角,可选,float类型(以度为单位,0-360),用x轴投影到x-y平面上的球体上的位置矢量所对的角度。 + @param view_distance: 观测距离,可选,float类型 or 'auto',一个正浮点数,表示距放置相机的焦点的距离。 + @param view_focalpoint: 观测焦点,可选,类型为一个由3个浮点数组成的数组 or 'auto',,代表观测相机的焦点 + @param bgcolor: + @return: """ from mayavi import mlab from simulators.mayavi_simulator import MayaviSimulator @@ -146,10 +146,10 @@ def ursina_run(bodies, def mpl_run(bodies, dt=SECONDS_PER_WEEK, gif_file_name=None, gif_max_frame=200): """ - :param bodies: 天体 - :param dt: 单位:秒,按时间差进行演变,值越小越精确,但演变速度会慢。 - :param gif_file_name: 导出的 gif 文件名,如果为空,则显示动画 - :return: + @param bodies: 天体 + @param dt: 单位:秒,按时间差进行演变,值越小越精确,但演变速度会慢。 + @param gif_file_name: 导出的 gif 文件名,如果为空,则显示动画 + @return: """ from simulators.mpl_simulator import MplSimulator body_sys = System(bodies) diff --git a/sim_scenes/science/parabolic_curve.py b/sim_scenes/science/parabolic_curve.py index 306312abf67f1f2885743e2ae328941e9050d016..d0da316ce1b5093a404e74c97ac0c49da351cfc0 100644 --- a/sim_scenes/science/parabolic_curve.py +++ b/sim_scenes/science/parabolic_curve.py @@ -10,26 +10,39 @@ 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__': + +def create_ejected_object(velocity, raduis, trail_color, angle=10): """ - 抛物线模拟 + 创建一个被抛的物体 + @param velocity: 抛出去的速度 + @param raduis: 物体地球中心的半径 + @param trail_color: 轨迹颜色 + @param angle: 抛出去的角度(地平线夹角,默认为10) + @return: """ - # TODO: 修改抛出物体的速度 - velocity = 8 # 物体飞不出地球太远,就落地 - # velocity = 10 # 物体能飞出地球很远,但还是无法摆脱地球引力 - # velocity = 11.2 # 脱离地球引力直接飞出。速度11.2千米/秒为脱离地球引力的速度叫第二宇宙速度 - # 根据速度、角度获取矢量速度(vx、vy) -> vx² + vy² = velocity² - vx, vy = get_vector2d_velocity(velocity, angle=10) + vx, vy = get_vector2d_velocity(velocity, angle=angle) + moon = Moon(name=f'物体速度:{velocity}', mass=500, size_scale=2e6, trail_color=trail_color, + init_position=[0, raduis, 0], + init_velocity=[vx, vy, 0], gravity_only_for_earth=True) # 仅适用于地球的重力,物体之间重力不要受到影响 + return moon + +if __name__ == '__main__': + """ + 抛物线模拟 + """ # 地球在中心位置 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]), - ] + raduis = e.raduis + 300 + # 红色:velocity = 8 # 物体飞不出地球太远,就落地 + obj1 = create_ejected_object(velocity=8, raduis=raduis, trail_color=(255, 0, 0)) + # 绿色:velocity = 10 # 物体能飞出地球很远,但还是无法摆脱地球引力 + obj2 = create_ejected_object(velocity=10, raduis=raduis, trail_color=(0, 255, 0)) + # 蓝色:velocity = 11.2 # 脱离地球引力直接飞出。速度11.2千米/秒为脱离地球引力的速度叫第二宇宙速度 + obj3 = create_ejected_object(velocity=11.2, raduis=raduis, trail_color=(0, 0, 255)) + + bodies = [e, obj1, obj2, obj3] # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 diff --git a/sim_scenes/solar_system/solar_system_4.py b/sim_scenes/solar_system/solar_system_4.py index 9c6a48a9ff3f5371d8d2e20f9b702fc02830c72e..4c8b8479b7f686a5f896191ef92ddbc35a412bea 100644 --- a/sim_scenes/solar_system/solar_system_4.py +++ b/sim_scenes/solar_system/solar_system_4.py @@ -16,11 +16,11 @@ from common.consts import G def get_velocity(mass, distance, velocity, target_distance): """ 根据天体的质量和天体原始距离、速度,计算出能稳定围绕太阳转的速度。 - :param mass: 天体质量,单位 kg - :param distance: 天体原始距离,单位 km - :param velocity: 天体原始速度,单位 km/s - :param target_distance: 目标距离,即新轨道的距离,单位 km - :return: 稳定围绕太阳转的速度,单位 km/s + @param mass: 天体质量,单位 kg + @param distance: 天体原始距离,单位 km + @param velocity: 天体原始速度,单位 km/s + @param target_distance: 目标距离,即新轨道的距离,单位 km + @return: 稳定围绕太阳转的速度,单位 km/s """ v = velocity * pow(distance / target_distance, 0.5) # # 计算原始速率 diff --git a/simulators/func.py b/simulators/func.py index b2a4f995aebc4979556bd1b8240e12f318506102..efbc363a39fd6a1546abab4f10429ecd426fdbba 100644 --- a/simulators/func.py +++ b/simulators/func.py @@ -20,8 +20,8 @@ COSMIC_FORE_COLOR = "white" def get_default_colors(styles={}): """ - :param styles: - :return: + @param styles: + @return: """ bg_color = styles["bg_color"] if "bg_color" in styles else "white" # COSMIC_BG_COLOR fore_color = styles["fore_color"] if "fore_color" in styles else "black" # COSMIC_FORE_COLOR @@ -35,8 +35,8 @@ def get_default_colors(styles={}): def create_fig_ax(styles={}): """ - :param styles: - :return: + @param styles: + @return: """ bg_color, fore_color = get_default_colors(styles) @@ -69,9 +69,9 @@ def create_fig_ax(styles={}): def update_ax_styles(ax, styles={}): """ - :param ax: - :param styles: - :return: + @param ax: + @param styles: + @return: """ plt.cla() bg_color, fore_color = get_default_colors(styles) diff --git a/simulators/mpl_simulator.py b/simulators/mpl_simulator.py index 3d558338c8b5da2a03bda4a6dbb81c3169b0c0b5..752a14f9173c2cb6b80416a717d92ce82d53b673 100644 --- a/simulators/mpl_simulator.py +++ b/simulators/mpl_simulator.py @@ -32,10 +32,10 @@ class MplSimulator(Simulator): def save_as_gif(self, dt, gif_max_frame=200, gif_file_name='bodies_run.gif', styles={}): """ 保存 GIF 文件 - :param dt: 单位:秒,按时间差进行演变,值越小越精确,但演变速度会慢。 - :param gif_max_frame: 导出的 gif 文件的画面帧数 - :param gif_file_name: 导出的 gif 文件名 - :return: + @param dt: 单位:秒,按时间差进行演变,值越小越精确,但演变速度会慢。 + @param gif_max_frame: 导出的 gif 文件的画面帧数 + @param gif_file_name: 导出的 gif 文件名 + @return: """ fig, ax = create_fig_ax() @@ -57,11 +57,11 @@ class MplSimulator(Simulator): def run(self, dt, **kwargs): """ - :param dt: 单位:秒,按时间差进行演变,值越小越精确,但演变速度会慢。 - :param kwargs: + @param dt: 单位:秒,按时间差进行演变,值越小越精确,但演变速度会慢。 + @param kwargs: gif_file_name: 导出的 gif 文件名,如果为空,则显示动画 gif_max_frame: 导出的 gif 文件的画面帧数 - :return: + @return: """ gif_file_name = kwargs["gif_file_name"] if "gif_file_name" in kwargs else None gif_max_frame = kwargs["gif_max_frame"] if "gif_max_frame" in kwargs else None @@ -84,10 +84,10 @@ class MplSimulator(Simulator): def show_figure(self, ax, bodies, pause=0.1, update_ax=None, styles={}): """ - :param ax: - :param bodies: - :param pause: - :return: + @param ax: + @param bodies: + @param pause: + @return: """ if update_ax is not None: # 更新 ax diff --git a/simulators/simulator.py b/simulators/simulator.py index bc879ae6c557cd92ac193bcd43c58a12ddfb1461..61eb463bc38f8d32f252a7d0a28d5d5b868a776e 100644 --- a/simulators/simulator.py +++ b/simulators/simulator.py @@ -18,8 +18,8 @@ class Simulator(metaclass=ABCMeta): def __init__(self, bodies_sys: System, viewer_type: type): """ - :param bodies_sys: 天体系统 - :param viewer_type: BodyViewer类型 + @param bodies_sys: 天体系统 + @param viewer_type: BodyViewer类型 """ self.body_views = [] self.bodies_sys = bodies_sys @@ -28,8 +28,8 @@ class Simulator(metaclass=ABCMeta): def init_views(self, viewer_type: type): """ - :param viewer_type: BodyViewer类型 - :return: + @param viewer_type: BodyViewer类型 + @return: """ for body in self.bodies_sys.bodies: view = viewer_type(body, self.bodies_sys) @@ -38,8 +38,8 @@ class Simulator(metaclass=ABCMeta): def evolve(self, dt: int): """ 单位:秒,按时间差进行演变,值越小越精确,但演变速度会慢。 - :param dt: 时间差(秒) - :return: + @param dt: 时间差(秒) + @return: """ self.bodies_sys.evolve(dt) for idx, view in enumerate(self.body_views): @@ -71,7 +71,7 @@ class Simulator(metaclass=ABCMeta): def run(self, dt: int, **kwargs): """ 按时间差运行,值越小越精确,但演变速度会慢。 - :param dt: 时间差(秒) - :return: + @param dt: 时间差(秒) + @return: """ pass diff --git a/simulators/ursina/entities/entity_utils.py b/simulators/ursina/entities/entity_utils.py index 1d5042e81827becd5002688e8908aa0e6a0bce0d..9f2d6ff5982644e3dcd1d77a7dfac03a0996de5e 100644 --- a/simulators/ursina/entities/entity_utils.py +++ b/simulators/ursina/entities/entity_utils.py @@ -42,7 +42,7 @@ def create_name_text(parent): def trail_init(parent): """ 拖尾球体的初始化 - :return: + @return: """ # 存放拖尾球体 parent.trails = {} @@ -79,7 +79,7 @@ def distance_between_two_points(point_a: Vec3, point_b: Vec3) -> float: def create_trails(parent): """ 创建拖尾 - :return: + @return: """ # 当前天体的位置 try: @@ -129,8 +129,8 @@ def create_trails(parent): def create_trail_sphere(parent, pos): """ 在天体当前的位置创建一个拖尾球体 - :param pos: - :return: + @param pos: + @return: """ # sphere = create_sphere(1,6) diamond sphere trail = BodyTrail(color=parent.trail_color, scale=parent.trail_scale, position=pos) @@ -154,8 +154,8 @@ def merge_vectors(vectors): def create_trail_line(parent, pos): """ 在天体当前的位置创建一个拖尾球体 - :param pos: - :return: + @param pos: + @return: """ if hasattr(parent, "trail_last_pos"): trail_last_pos = parent.trail_last_pos @@ -174,7 +174,7 @@ def create_trail_line(parent, pos): def create_rings(self): """ 创建行星环(使用土星贴图) - :return: + @return: """ rings_texture = 'textures/saturnRings.jpg' rings_texture = find_file(rings_texture) @@ -213,8 +213,8 @@ def clear_trails(self): def create_fixed_star_lights(fixed_star): """ 创建恒星的发光的效果、并作为灯光源 - :param entity: - :return: + @param entity: + @return: """ # 如果是恒星(如:太阳),自身会发光,则需要关闭灯光 diff --git a/simulators/ursina/ui/ui_panel.py b/simulators/ursina/ui/ui_panel.py index e1c0dbd2437c86249cdbd3652e5e8ba70b1c570a..1ef22eef8409811eb0b19bc922e61e0989446ddc 100644 --- a/simulators/ursina/ui/ui_panel.py +++ b/simulators/ursina/ui/ui_panel.py @@ -65,9 +65,9 @@ class UiPanel(WindowPanel): def show_message(self, message, close_time=3): """ 显示消息框 - :param message: 消息内容 - :param close_time: 定义显示消息框关闭时间 - :return: + @param message: 消息内容 + @param close_time: 定义显示消息框关闭时间 + @return: """ # 创建消息框 message_box = Text(text=message, font=UrsinaConfig.CN_FONT, background=True, origin=(0, 0), y=.25) diff --git a/simulators/ursina/ursina_mesh.py b/simulators/ursina/ursina_mesh.py index 49eebe5f8342e90553f6e27902c3f97618477966..83d4a287201a8149955d7edd91f2243bcbcab9b7 100644 --- a/simulators/ursina/ursina_mesh.py +++ b/simulators/ursina/ursina_mesh.py @@ -18,9 +18,9 @@ from simulators.ursina.ursina_config import UrsinaConfig def create_sphere(radius, subdivisions): """ 创建一个球体 - :param radius: - :param subdivisions: - :return: + @param radius: + @param subdivisions: + @return: """ # 生成球体的顶点、UV坐标uvs、法线tris和三角面 verts = [] diff --git a/simulators/ursina_simulator.py b/simulators/ursina_simulator.py index 77df8fe19bfa4ef205d3d1b710d08dcc0328f702..09b080108000e54f07156b8ef7c0ea61253aadc8 100644 --- a/simulators/ursina_simulator.py +++ b/simulators/ursina_simulator.py @@ -74,8 +74,8 @@ class UrsinaSimulator(Simulator): def get_bodies_max_distance(self, body_views): """ 算法优化 - :param body_views: - :return: + @param body_views: + @return: """ max_distance = 0 for b1, b2 in itertools.combinations(body_views, 2): @@ -93,7 +93,7 @@ class UrsinaSimulator(Simulator): def adjust_system_motion_params(self): """ 调整天体系统运行的参数 - :return: + @return: """ max_distance = self.get_bodies_max_distance(self.body_views) # 根据天体之间的距离,调整 application.time_scale(控制摄像头运动的速度) @@ -116,7 +116,7 @@ class UrsinaSimulator(Simulator): def check_interval_expired(self): """ 检查时间间隔是否已过期 - :return: + @return: """ now = datetime.datetime.now() elapsed_time = now - self.last_time @@ -154,8 +154,8 @@ class UrsinaSimulator(Simulator): def cosmic_background(self, texture='../textures/cosmic2.jpg'): """ 加入宇宙背景 - :param texture: - :return: + @param texture: + @return: """ # Add skybox diff --git a/simulators/views/body_view.py b/simulators/views/body_view.py index 6edc3df50e66bff25cd954460c0b5da1853ec65e..44d3d17a59d2d4801ec40a358931791479b8a743 100644 --- a/simulators/views/body_view.py +++ b/simulators/views/body_view.py @@ -51,8 +51,8 @@ class BodyView(metaclass=ABCMeta): def __find_texture(self, texture): """ 尝试在多个路径下寻找纹理图片 - :param texture: 纹理图片 - :return: 纹理图片的路径 + @param texture: 纹理图片 + @return: 纹理图片的路径 """ return find_texture(texture) # if os.path.exists(texture): @@ -68,8 +68,8 @@ class BodyView(metaclass=ABCMeta): def __get_texture_main_color(self, texture): """ 获取纹理图片的主要颜色 - :param texture: - :return: + @param texture: + @return: """ try: colors = get_dominant_colors(texture) @@ -83,14 +83,14 @@ class BodyView(metaclass=ABCMeta): def update(self): """ 更新天体信息和数据,比如:更新天体的位置 - :return: + @return: """ pass def disappear(self): """ 天体消失的操作,比如:销毁天体视图对象 - :return: + @return: """ pass @@ -98,6 +98,6 @@ class BodyView(metaclass=ABCMeta): def appear(self): """ 天体显示的操作,比如:构建天体视图对象 - :return: + @return: """ pass diff --git a/simulators/views/mayavi_view.py b/simulators/views/mayavi_view.py index c0d0f9b717f0f3818560c62afab72c8eda84b6da..bfa1d0417db803f0fc3e877feb1e3a636f9796b2 100644 --- a/simulators/views/mayavi_view.py +++ b/simulators/views/mayavi_view.py @@ -24,7 +24,7 @@ class MayaviView(BodyView): def update(self): """ 更新天体信息和数据,比如:更新天体的位置 - :return: + @return: """ if hasattr(self.sphere, "mlab_source"): # self.sphere.mlab_source.x 的位置是已经和 distance_scale 进行了相乘 @@ -83,7 +83,7 @@ class MayaviView(BodyView): def appear(self): """ 天体显示的操作,比如:构建天体视图对象 - :return: + @return: """ if hasattr(self.body, "torus_stars"): # 暂不支持环状小行星群 @@ -131,8 +131,8 @@ class MayaviView(BodyView): def __set_texture(self, image_file): """ 设置纹理图片到天体 - :param image_file: - :return: + @param image_file: + @return: """ outfile = image_file.replace('.jpg', '_flipped.jpg').replace('.png', '_flipped.jpg') if os.path.exists(outfile): diff --git a/simulators/views/ursina_view.py b/simulators/views/ursina_view.py index 45b90a32112d976af060508b24d2d692fe83a4b5..caa6178d8dbe0fc7068f76fc3c4c7736c1bd8a7b 100644 --- a/simulators/views/ursina_view.py +++ b/simulators/views/ursina_view.py @@ -29,7 +29,7 @@ class UrsinaView(BodyView): def update(self): """ - :return: + @return: """ self.planet.update()