提交 bac2ca3a 编写于 作者: M march3

三体运行模拟器

上级 495f030b
# -*- 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)
# -*- 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,
......
# -*- 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
......
# -*- 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
......
# -*- 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
......
# -*- 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
......
# -*- 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)
# -*- 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
......
# -*- 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
......
# -*- 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
......
# -*- 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
......
# -*- 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
......
# -*- 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
......
# -*- 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
# ==============================================================================
......
# -*- 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]):
......
# -*- 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
......
......@@ -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
......
# -*- 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
......
......@@ -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
......
......@@ -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
......
......@@ -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,
pxs, pys, vxs, vys = get_positions_velocitys(angles,
radius=1.60 * AU,
force=23.37,
velocity=23.37,
radius_offset=0.1 * AU,
force_offset=0.2)
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],
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册