diff --git a/bodies/asteroid.py b/bodies/asteroid.py index 5d88491e69778cdc347e5056688e2f10af15e7d1..0add125489cb3df10d0344a839ad6413b48dd3e2 100644 --- a/bodies/asteroid.py +++ b/bodies/asteroid.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :小行星 +# description :小行星 # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies.body import Body, AU @@ -55,6 +55,7 @@ class Asteroid(Body): return True + if __name__ == '__main__': asteroid = Asteroid() print(asteroid) diff --git a/bodies/body.py b/bodies/body.py index 17e1cbef878fcafaf552a4ccb63878a7dc635834..5237f1544bdb29ac6745239490773dcec70fa5d6 100644 --- a/bodies/body.py +++ b/bodies/body.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :天体基类 +# description :天体基类(所有星体都继承了该类) # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from abc import ABCMeta, abstractmethod @@ -15,7 +15,7 @@ from common.consts import AU class Body(metaclass=ABCMeta): """ - 天体信息基类 + 天体基类 """ def __init__(self, name, mass, init_position, init_velocity, diff --git a/bodies/earth.py b/bodies/earth.py index e16d1efd69d4cd82e49593ed9b90462f196f8931..5181e1d32735a51f94d4987a37b7d6803213872b 100644 --- a/bodies/earth.py +++ b/bodies/earth.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :地球 +# description :地球 # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies.body import Body, AU diff --git a/bodies/jupiter.py b/bodies/jupiter.py index e0199550b4b06d38e81d441d4168a7fcf477cc11..2852c53ecdf1db7a4255c87a4ac31fab2d189f8c 100644 --- a/bodies/jupiter.py +++ b/bodies/jupiter.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :木星 +# description :木星 # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies.body import Body, AU diff --git a/bodies/mars.py b/bodies/mars.py index 51723919ca8178519e7221a8222f0718b4f5a931..d540a23aeb6c2e257eecf4ac532974adc4ac9431 100644 --- a/bodies/mars.py +++ b/bodies/mars.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :火星 +# description :火星 # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies.body import Body, AU diff --git a/bodies/mercury.py b/bodies/mercury.py index e32fdcfba20d9cd17422a46e49becbed0531e857..b403ad258ba24fc732979e18c2c006d4ecb9588b 100644 --- a/bodies/mercury.py +++ b/bodies/mercury.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :水星 +# description :水星 # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies.body import Body, AU diff --git a/bodies/moon.py b/bodies/moon.py index d8acafb080be3a6278b81d3af7ea9a97930fabad..f7192e97c1a37817740f47d8bfc1e2476e7f4283 100644 --- a/bodies/moon.py +++ b/bodies/moon.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :月球 +# description :月球 # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies.body import Body, AU @@ -40,5 +40,5 @@ class Moon(Body): if __name__ == '__main__': - earth = Earth() - print(earth) + moon = Moon() + print(moon) diff --git a/bodies/neptune.py b/bodies/neptune.py index 8bb1261338e809f3dda3cc580375cf0df41e9ee9..c5663b9326c663e4f88e0cd5b01ed7d06057d195 100644 --- a/bodies/neptune.py +++ b/bodies/neptune.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :海王星 +# description :海王星 # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies.body import Body, AU diff --git a/bodies/pluto.py b/bodies/pluto.py index dd16f56f970f34de11fc0dfade92172a55f914d2..73062bd46a16f5d9ec7be13c954d1081ec36c2d0 100644 --- a/bodies/pluto.py +++ b/bodies/pluto.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :冥王星 +# description :冥王星(从太阳系的行星中排除) # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies.body import Body, AU diff --git a/bodies/saturn.py b/bodies/saturn.py index 803cdead71b32f05920ad764c71cba7f2a360eb6..82c88e48495b4bc303837f44f741798405215b90 100644 --- a/bodies/saturn.py +++ b/bodies/saturn.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :土星 +# description :土星 # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies.body import Body, AU diff --git a/bodies/sun.py b/bodies/sun.py index 1ded492aaed09ad77298a75451b61aaa1d15c44a..89d41b3454426b299afe9e83afcc0c653a6f15e8 100644 --- a/bodies/sun.py +++ b/bodies/sun.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :太阳 +# description :太阳 # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies.body import Body diff --git a/bodies/uranus.py b/bodies/uranus.py index aabf13f76d4ce5b473467a6cb74e04a8c8b2fa4b..e61871226bf02471e1958a98addbca8016090618 100644 --- a/bodies/uranus.py +++ b/bodies/uranus.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :天王星 +# description :天王星 # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies.body import Body, AU diff --git a/bodies/venus.py b/bodies/venus.py index 10dba3ca5031e8dbcf62e1d22c4d1594a641e2af..75fe2e14c0b937725defaf3dfbb714b991024239 100644 --- a/bodies/venus.py +++ b/bodies/venus.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :金星 +# description :金星 # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies.body import Body, AU diff --git a/common/consts.py b/common/consts.py index d7d756c29fba56538244cdc9056eff6981db3fd5..6f9aaac3c28bfd647eb774df36810e467e5d9d2f 100644 --- a/common/consts.py +++ b/common/consts.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :常量定义 +# description :常量定义 # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== diff --git a/common/func.py b/common/func.py index d3510027cb05c54f775d02c7f6b95dcc59462db6..5e56ba3b5ed265739a5a72cc105707ef09c6c3f5 100644 --- a/common/func.py +++ b/common/func.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :公共库函数 +# description :公共库函数 # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from PIL import Image @@ -42,26 +42,15 @@ def get_dominant_colors(infile, resize=(20, 20)): return colors -def circle_x_y(points, radius=1.6 * AU): +def get_positions_velocitys(angles, velocity=1, radius=1, radius_offset=None, velocity_offset=None): """ - - :param points: - :param radius: - :return: - """ - x = radius * np.cos(points) - y = radius * np.sin(points) - return x, y - - -def get_position_force(angles, force=1, radius=1, radius_offset=None, force_offset=None): - """ - - :param angles: - :param force: - :param radius: - :param radius_offset: - :param force_offset: + 以位置 (0, 0, 0)为中心,随机获取空间上的位置和公转方向的速度集合 + (比如:获取大批小行星的位置) + :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) @@ -69,17 +58,17 @@ def get_position_force(angles, force=1, radius=1, radius_offset=None, force_offs if isinstance(radius_offset, float): radius = radius + np.random.rand(len(angles)) * radius_offset - if isinstance(force_offset, float): - force = force + np.random.rand(len(angles)) * force_offset + if isinstance(velocity_offset, float): + velocity = velocity + np.random.rand(len(angles)) * velocity_offset pxs = radius * np.cos(angles) pys = radius * np.sin(angles) - fys = force * np.cos(angles) # math.cos(math.radians(angle)) - fxs = force * np.sin(angles) # math.sin(math.radians(angle)) + vys = velocity * np.cos(angles) + vxs = velocity * np.sin(angles) # return pxs, pys, fxs, fys - return np.round(pxs, 2), np.round(pys, 2), -np.round(fxs, 2), np.round(fys, 2) + return np.round(pxs, 2), np.round(pys, 2), -np.round(vxs, 2), np.round(vys, 2) def calculate_distance(pos1, pos2=[0, 0, 0]): diff --git a/common/system.py b/common/system.py index b2ce664d058d6a3ed76a1ccd7941156a11fff5cb..47e20cdf2eaa96872c9fc93634f51321c2d89838 100644 --- a/common/system.py +++ b/common/system.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :天体系统 +# description :天体系统,多个天体就是一个系统 # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== import numpy as np diff --git a/scenes/demo.py b/scenes/demo.py index 485fb605591e0ea42a08f2abadd151c23a55db20..f27286f3baa2253d2885b655b1fac1f49a4035b8 100644 --- a/scenes/demo.py +++ b/scenes/demo.py @@ -2,8 +2,8 @@ # title : # description : # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies import Sun, Earth diff --git a/scenes/func.py b/scenes/func.py index 0b1ca4858c8c8afe35274220e0ae00d95f107ccb..ff24f2e8f2e0f4bb3243b0aec5e45c66591a38a9 100644 --- a/scenes/func.py +++ b/scenes/func.py @@ -1,9 +1,9 @@ # -*- coding:utf-8 -*- -# title : -# description : +# title :场景用功能库 +# description :场景用功能库 # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from common.consts import SECONDS_PER_WEEK diff --git a/scenes/solar_system_1.py b/scenes/solar_system_1.py index a75563147f3c3052ade848bdf4190dab00772860..ad94b2faaaa542aaf26de8b48bcbdefb451f268f 100644 --- a/scenes/solar_system_1.py +++ b/scenes/solar_system_1.py @@ -2,8 +2,8 @@ # title :太阳系场景 # description : # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies import Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto, Moon diff --git a/scenes/solar_system_2.py b/scenes/solar_system_2.py index 7366d95fe2e32ee05b1387a84e9612b28b9b4cc2..c23f859d848664defff47a7e0cf8f47dfc47ecd7 100644 --- a/scenes/solar_system_2.py +++ b/scenes/solar_system_2.py @@ -2,8 +2,8 @@ # title :太阳系场景 # description : # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies import Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto diff --git a/scenes/solar_system_3.py b/scenes/solar_system_3.py index 1fdd7cd3211199e3889dcfa7cada0deb4e5a9ad1..7489253e94171a6dbffd1bb92ec0b77dd3681f6f 100644 --- a/scenes/solar_system_3.py +++ b/scenes/solar_system_3.py @@ -2,14 +2,14 @@ # title :太阳系场景 # description : # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies import Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto, Asteroid from bodies.body import AU from common.consts import SECONDS_PER_WEEK -from common.func import get_position_force +from common.func import get_positions_velocitys from scenes.func import mayavi_run import numpy as np @@ -50,13 +50,13 @@ if __name__ == '__main__': NUM_OF_ASTEROIDS = 60 asteroids = [] angles = np.linspace(0, 40 * np.pi, NUM_OF_ASTEROIDS) - pxs, pys, fxs, fys = get_position_force(angles, - radius=1.60 * AU, - force=23.37, - radius_offset=0.1 * AU, - force_offset=0.2) + pxs, pys, vxs, vys = get_positions_velocitys(angles, + radius=1.60 * AU, + velocity=23.37, + radius_offset=0.1 * AU, + velocity_offset=0.2) for i, px in enumerate(pxs): - py, fx, fy = pys[i], fxs[i], fys[i] + py, fx, fy = pys[i], vxs[i], vys[i] asteroids.append(Asteroid(size_scale=1e9, # 小行星放大 1000000000 倍,距离放大 1.4 倍 init_position=[px, py, 0], init_velocity=[fx, fy, 0], diff --git a/scenes/sun_earth.py b/scenes/sun_earth.py index f555d979b653ad4e1b65d8a6b1f24d29f43e6ed6..c97a1b741e0ddf5b6258aea0a025e0aaa4570cf6 100644 --- a/scenes/sun_earth.py +++ b/scenes/sun_earth.py @@ -2,8 +2,8 @@ # title : # description : # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies import Sun, Earth diff --git a/scenes/sun_earth_jupiter.py b/scenes/sun_earth_jupiter.py index c63529aa3fb145ef1143c980bdd0bbeda6ed1466..ce62e1d08472d6a147ed812586059828485e5b4d 100644 --- a/scenes/sun_earth_jupiter.py +++ b/scenes/sun_earth_jupiter.py @@ -2,8 +2,8 @@ # title : # description : # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from bodies import Sun, Earth, Jupiter diff --git a/scenes/three_body_01.py b/scenes/three_body_01.py index 81003f5856b98bc5008120d352bdd5265b0ea2be..5a545bdd71dd84ea9db6e0772e7931371dc0d6da 100644 --- a/scenes/three_body_01.py +++ b/scenes/three_body_01.py @@ -2,8 +2,8 @@ # title :太阳系场景 # description : # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from mayavi import mlab diff --git a/scenes/three_body_02.py b/scenes/three_body_02.py index 39f91c0a20e7753965a120ed0aab115ce093571b..70eb3fe8d95488aede4fc84f2180175821401a63 100644 --- a/scenes/three_body_02.py +++ b/scenes/three_body_02.py @@ -2,8 +2,8 @@ # title :太阳系场景 # description : # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from mayavi import mlab diff --git a/simulators/mayavi_simulator.py b/simulators/mayavi_simulator.py index b9e5db2d7e4c1a2dd21729ce66fb85398f8e3151..85b3f62412c1e7203ab2404be84a32475c26a067 100644 --- a/simulators/mayavi_simulator.py +++ b/simulators/mayavi_simulator.py @@ -2,8 +2,8 @@ # title : # description : # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from mayavi import mlab diff --git a/simulators/mpl_simulator.py b/simulators/mpl_simulator.py index 477552d96096fb7d896aacc10550ae2e37d8670d..b594d00c313ec6940adaa75cc3ca8b9f097ddbc1 100644 --- a/simulators/mpl_simulator.py +++ b/simulators/mpl_simulator.py @@ -2,8 +2,8 @@ # title : # description : # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== import matplotlib.pyplot as plt diff --git a/simulators/simulator.py b/simulators/simulator.py index 421403301055b9741d249760dbe55015bbae0624..302ce86fbc5f9cccc5ed0c7b920bf63e20610951 100644 --- a/simulators/simulator.py +++ b/simulators/simulator.py @@ -2,8 +2,8 @@ # title : # description : # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from abc import ABCMeta, abstractmethod diff --git a/simulators/views/body_view.py b/simulators/views/body_view.py index 2a840792bffa48c81efbc55b49ecdbf4af4be72a..0275935d90c93082cb19a2b7d08e03973b163b60 100644 --- a/simulators/views/body_view.py +++ b/simulators/views/body_view.py @@ -2,8 +2,8 @@ # title : # description : # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from abc import ABCMeta, abstractmethod diff --git a/simulators/views/mayavi_view.py b/simulators/views/mayavi_view.py index 5eadb63c6c2366ec1fc8b5953f55e11ee704f16b..2e1cdd86684dcc81e275ffd6fddd4de80b4351f6 100644 --- a/simulators/views/mayavi_view.py +++ b/simulators/views/mayavi_view.py @@ -2,8 +2,8 @@ # title : # description : # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== from mayavi import mlab diff --git a/simulators/views/mpl_view.py b/simulators/views/mpl_view.py index a3890efd0cb6f8ee1a51688fd285ca04300da13e..f714e23069e6873e7b983f47376e953dfb74caff 100644 --- a/simulators/views/mpl_view.py +++ b/simulators/views/mpl_view.py @@ -2,8 +2,8 @@ # title : # description : # author :Python超人 -# date :2023-01-22 -# notes : +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== import os