diff --git a/bodies/asteroid.py b/bodies/asteroid.py index 777948563737cba5b61e0190d370750ca4082db2..da81d3a23f0cb867885d0cb6d9d0bb21c10629e5 100644 --- a/bodies/asteroid.py +++ b/bodies/asteroid.py @@ -27,8 +27,10 @@ class Asteroid(Body): """ def __init__(self, name="小行星", mass=4.1e10, - init_position=[1.6 * AU, 0, 0], - init_velocity=[0, 25.37, 0], + # init_position=[1.6 * AU, 0, 0], + # init_velocity=[0, 25.37, 0], + init_position=[0, 0, 1.6 * AU], + init_velocity=[-25.37, 0, 0], texture="", size_scale=1.0, distance_scale=1.0): params = { "name": name, @@ -43,6 +45,10 @@ class Asteroid(Body): } super().__init__(**params) + @property + def show_trail(self): + return False + def ignore_gravity(self, body): """ 是否忽略引力 diff --git a/bodies/body.py b/bodies/body.py index ce0b4ebe319b42622fd3986cab24b2df289d0785..ab48a0517f99127428140eb8c6a289aece58a042 100644 --- a/bodies/body.py +++ b/bodies/body.py @@ -403,6 +403,9 @@ class Body(metaclass=ABCMeta): body = FixedStar(**body_data) else: body = Body(**body_data) + # [x, y, z]->[-y, z, x] + # body.init_velocity = [-body.init_velocity[1],body.init_velocity[2],body.init_velocity[0]] + # body.init_position = [-body.init_position[1],body.init_position[2],body.init_position[0]] bodies.append(body) if "params" in json_data: params = json_data["params"] diff --git a/bodies/earth.py b/bodies/earth.py index 0ab341a1f91b2faae58027d6af9988a3ddb391c6..01fc076b92825b298cf763996fda66316d386292 100644 --- a/bodies/earth.py +++ b/bodies/earth.py @@ -22,10 +22,11 @@ class Earth(Body):  天体质量: 5.97237✕10²⁴ kg  平均密度: 5507.85 kg/m³ """ - def __init__(self, name="地球", mass=5.97237e24,rotate_angle=0, - init_position=[1.12 * AU, 0, 0], - init_velocity=[0, 29.79, 0], + # init_position=[1.12 * AU, 0, 0], + # init_velocity=[0, 29.79, 0], + init_position=[0, 0, 1.12 * AU], + init_velocity=[-29.79, 0, 0], texture="earth1.jpg", size_scale=1.0, distance_scale=1.0, rotation_speed=15, ignore_mass=False, trail_color=None, show_name=False): params = { diff --git a/bodies/jupiter.py b/bodies/jupiter.py index fc85189cd2243476681bd59abac92d808fbac127..5ce8fdb7b8b268ac32c3d1b985b4b6d13e8c8aa9 100644 --- a/bodies/jupiter.py +++ b/bodies/jupiter.py @@ -22,10 +22,11 @@ class Jupiter(Body):  天体质量: 1.8982✕10²⁷ kg(317.8 M⊕)  平均密度: 1.326 g/cm³ -> -> 1.326✕10³ kg/m³ """ - def __init__(self, name="木星", mass=1.8982e27, - init_position=[5.2 * AU, 0, 0], - init_velocity=[0, 13.06, 0], + # init_position=[5.2 * AU, 0, 0], + # init_velocity=[0, 13.06, 0], + init_position=[0, 0, 5.2 * AU], + init_velocity=[-13.06, 0, 0], texture="jupiter1.jpg", size_scale=1.0, distance_scale=1.0, rotation_speed=36.2537, ignore_mass=False, trail_color=None, show_name=False): params = { diff --git a/bodies/mars.py b/bodies/mars.py index 0c3a6f6964ef91a6853234354d459106cdf31406..9a541dd47793cbe220daf03dca7e4688f2bcebfe 100644 --- a/bodies/mars.py +++ b/bodies/mars.py @@ -23,8 +23,10 @@ class Mars(Body):  平均密度: 3.9335 g/cm³ -> 3.9335✕10³ kg/m³ """ def __init__(self, name="火星", mass=6.4171e23, - init_position=[1.5 * AU, 0, 0], - init_velocity=[0, 24.13, 0], + # init_position=[1.5 * AU, 0, 0], + # init_velocity=[0, 24.13, 0], + init_position=[0, 0, 1.5 * AU], + init_velocity=[-24.13, 0, 0], texture="mars.jpg", size_scale=1.0, distance_scale=1.0, rotation_speed=14.6223, ignore_mass=False, trail_color=None, show_name=False): params = { diff --git a/bodies/mercury.py b/bodies/mercury.py index 1e7409712e87ed0cea23a4b5721031dacb5f332c..fcf328e9d045e0b81e9f0863cee6aec23f75f0ae 100644 --- a/bodies/mercury.py +++ b/bodies/mercury.py @@ -24,8 +24,10 @@ class Mercury(Body): """ def __init__(self, name="水星", mass=3.3011e23, - init_position=[0.4 * AU, 0, 0], - init_velocity=[0, 47.87, 0], + # init_position=[0.4 * AU, 0, 0], + # init_velocity=[0, 47.87, 0], + init_position=[0, 0, 0.4 * AU], + init_velocity=[-47.87, 0, 0], texture="mercury.jpg", size_scale=1.0, distance_scale=1.0, rotation_speed=0.2558, ignore_mass=False, trail_color=None, show_name=False): params = { diff --git a/bodies/moon.py b/bodies/moon.py index 2d0b17b61386d56430b710312af4f67cbf929761..6d05d920e0820e9b848e60130ef7178b31965e4d 100644 --- a/bodies/moon.py +++ b/bodies/moon.py @@ -23,8 +23,10 @@ class Moon(Body): """ def __init__(self, name="月球", mass=7.342e22, - init_position=[363104 + 1.12 * AU, 0, 0], - init_velocity=[0, 29.79 + 1.023, 0], + # init_position=[363104 + 1.12 * AU, 0, 0], + # init_velocity=[0, 29.79 + 1.023, 0], + init_position=[0, 0, 363104 + 1.12 * AU], + init_velocity=[-(29.79 + 1.023), 0, 0], texture="moon.jpg", size_scale=1.0, distance_scale=1.0, rotation_speed=0.5487, ignore_mass=False, trail_color=None, show_name=False): params = { diff --git a/bodies/neptune.py b/bodies/neptune.py index 92a3370c1ca673b7ce3b24a067639155e3bdf4c9..354ffbeba435664526fce27cb45d74fe3aa9b65a 100644 --- a/bodies/neptune.py +++ b/bodies/neptune.py @@ -24,8 +24,10 @@ class Neptune(Body): """ def __init__(self, name="海王星", mass=1.0241e26, - init_position=[30 * AU, 0, 0], - init_velocity=[0, 5.43, 0], + # init_position=[30 * AU, 0, 0], + # init_velocity=[0, 5.43, 0], + init_position=[0, 0, 30 * AU], + init_velocity=[-5.43, 0, 0], texture="neptune.png", size_scale=1.0, distance_scale=1.0, rotation_speed=22.3463, ignore_mass=False, trail_color=None, show_name=False): params = { diff --git a/bodies/pluto.py b/bodies/pluto.py index 3656c87aca411da9833af7dff96d17a30af0a865..794096c484d24933bd99da92e0c266f6b0b1356b 100644 --- a/bodies/pluto.py +++ b/bodies/pluto.py @@ -24,8 +24,10 @@ class Pluto(Body): """ def __init__(self, name="冥王星", mass=1.303e22, - init_position=[40 * AU, 0, 0], - init_velocity=[0, 4.7, 0], + # init_position=[40 * AU, 0, 0], + # init_velocity=[0, 4.7, 0], + init_position=[0, 0, 40 * AU], + init_velocity=[-4.7, 0, 0], texture="pluto.png", size_scale=1.0, distance_scale=1.0, rotation_speed=-2.3474, ignore_mass=False, trail_color=None, show_name=False): params = { diff --git a/bodies/saturn.py b/bodies/saturn.py index 7379039733f03e428cf2308c46e64fb2a92cd5b6..973ced2e2934c50a6d9f401a47cfdc670906e959 100644 --- a/bodies/saturn.py +++ b/bodies/saturn.py @@ -24,8 +24,10 @@ class Saturn(Body): """ def __init__(self, name="土星", mass=5.6834e26, - init_position=[10 * AU, 0, 0], - init_velocity=[0, 9.64, 0], + # init_position=[10 * AU, 0, 0], + # init_velocity=[0, 9.64, 0], + init_position=[0, 0, 10 * AU], + init_velocity=[-9.64, 0, 0], texture="saturn.jpg", size_scale=1.0, distance_scale=1.0, rotation_speed=33.7711, ignore_mass=False, trail_color=None, show_name=False): params = { diff --git a/bodies/uranus.py b/bodies/uranus.py index 3e3267bed5791db56065e40054da3b1095e2a3d4..8122a8f35145f5ab69be314ff3d78e48b32a73ff 100644 --- a/bodies/uranus.py +++ b/bodies/uranus.py @@ -24,8 +24,10 @@ class Uranus(Body): """ def __init__(self, name="天王星", mass=8.681e25, - init_position=[19 * AU, 0, 0], - init_velocity=[0, 6.81, 0], + # init_position=[19 * AU, 0, 0], + # init_velocity=[0, 6.81, 0], + init_position=[0, 0, 19 * AU], + init_velocity=[-6.81, 0, 0], texture="uranus.png", size_scale=1.0, distance_scale=1.0, rotation_speed=-20.8816, ignore_mass=False, trail_color=None, show_name=False): params = { diff --git a/bodies/venus.py b/bodies/venus.py index f63517c222e31fc8bce629b01149a2fe63840e9e..1be74ac3bc0056e2472b3c1d9ecd136d72f40e18 100644 --- a/bodies/venus.py +++ b/bodies/venus.py @@ -24,8 +24,10 @@ class Venus(Body): """ def __init__(self, name="金星", mass=4.8675e24, - init_position=[0.72 * AU, 0, 0], - init_velocity=[0, 35, 0], + # init_position=[0.72 * AU, 0, 0], + # init_velocity=[0, 35, 0], + init_position=[0, 0, 0.72 * AU], + init_velocity=[-35, 0, 0], texture="venus.jpg", size_scale=1.0, distance_scale=1.0, rotation_speed=-0.0617, ignore_mass=False, trail_color=None, show_name=False): params = { diff --git a/common/func.py b/common/func.py index ea1e1fa2737c730fa6487eea4c3964f23322e4e0..dd992b13270a3d74a4095e9e88c9dc5a27038bee 100644 --- a/common/func.py +++ b/common/func.py @@ -64,13 +64,13 @@ def get_positions_velocitys(angles, velocity=1, radius=1, radius_offset=None, ve velocity = velocity + np.random.rand(len(angles)) * velocity_offset pxs = radius * np.cos(angles) - pys = radius * np.sin(angles) + pzs = radius * np.sin(angles) - vys = velocity * np.cos(angles) + vzs = 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(vxs, 2), np.round(vys, 2) + # return pxs, pzs, vxs, vzs + return np.round(pxs, 2), np.round(pzs, 2), -np.round(vxs, 2), np.round(vzs, 2) def find_file(file_path, default_val=None, find_deep=5): diff --git a/data/gravity_slingshot.json b/data/gravity_slingshot.json index b0f9ffaf65f20f024fab127e8d445a4cb4978ea7..9321c275c7d50e2c6232588fc89db8bb7758dee2 100644 --- a/data/gravity_slingshot.json +++ b/data/gravity_slingshot.json @@ -4,12 +4,12 @@ "name": "太阳", "mass": 1.9891e+30, "init_position": [ - 0.0, + -0.0, 0.0, 0.0 ], "init_velocity": [ - 0.0, + -0.0, 0.0, 0.0 ], @@ -35,14 +35,14 @@ "name": "地球", "mass": 5.97237e+24, "init_position": [ + 448793600.0, 0.0, - -448793600.0, 0.0 ], "init_velocity": [ - 0.0, - 38.0, - -1.0 + -38.0, + -1.0, + 0.0 ], "density": 5507.85, "color": [ diff --git a/data/sun_earth.json b/data/sun_earth.json index c75e11365b92a80ec5761344f84064d2e8fe5af5..9cfd096cb7cc6d68fef0026bd8d3916f1820ecb9 100644 --- a/data/sun_earth.json +++ b/data/sun_earth.json @@ -4,12 +4,12 @@ "name": "太阳", "mass": 1.9891e+30, "init_position": [ - 0.0, + -0.0, 0.0, 0.0 ], "init_velocity": [ - 0.0, + -0.0, 0.0, 0.0 ], @@ -35,13 +35,13 @@ "name": "地球", "mass": 5.97237e+24, "init_position": [ - 167549616.0, + -0.0, 0.0, - 0.0 + 167549616.0 ], "init_velocity": [ + -29.790000915527344, 0.0, - 29.790000915527344, 0.0 ], "density": 5507.85, diff --git a/data/sun_earth_moon.json b/data/sun_earth_moon.json index a4e4da29d69034884649857a2789d9d4b8e0d2dc..5c2b13ec3108928e4540203023ccd78490a9a18f 100644 --- a/data/sun_earth_moon.json +++ b/data/sun_earth_moon.json @@ -4,12 +4,12 @@ "name": "太阳", "mass": 1.9891e+30, "init_position": [ - 149597872.0, + -0.0, 0.0, - 0.0 + 149597872.0 ], "init_velocity": [ - 0.0, + -0.0, 0.0, 0.0 ], @@ -24,18 +24,23 @@ "distance_scale": 1.0, "rotation_speed": 0.613, "ignore_mass": true, - "is_fixed_star": true + "is_fixed_star": true, + "trail_color": [ + 170, + 98, + 25 + ] }, { "name": "地球", "mass": 5.97237e+24, "init_position": [ - 0.0, + -0.0, 0.0, 0.0 ], "init_velocity": [ - 0.0, + -0.0, 0.0, 0.0 ], @@ -50,19 +55,24 @@ "distance_scale": 1.0, "rotation_speed": 15, "ignore_mass": false, - "is_fixed_star": false + "is_fixed_star": false, + "trail_color": [ + 1, + 89, + 162 + ] }, { "name": "月球", "mass": 7.342e+22, "init_position": [ - 384400.0, + -0.0, 0.0, - 0.0 + 384400.0 ], "init_velocity": [ + -1.0230000019073486, 0.0, - 1.0230000019073486, 0.0 ], "density": 3344.0, @@ -76,7 +86,12 @@ "distance_scale": 1.0, "rotation_speed": 0.5487, "ignore_mass": false, - "is_fixed_star": false + "is_fixed_star": false, + "trail_color": [ + 162, + 162, + 162 + ] } ], "params": { @@ -85,6 +100,8 @@ 0, 0, 0 - ] + ], + "show_trail": false, + "show_name": false } } \ No newline at end of file diff --git a/data/tri_bodies_perfect_01.json b/data/tri_bodies_perfect_01.json index fe7bdf2686f1b33c2993d1d9e955ef88f572f616..c425ae3b828acb211c23320aa202db67305bc0b7 100644 --- a/data/tri_bodies_perfect_01.json +++ b/data/tri_bodies_perfect_01.json @@ -4,14 +4,14 @@ "name": "红轨太阳A", "mass": 2e+30, "init_position": [ + -518222240.0, 0.0, - 518222240.0, 0.0 ], "init_velocity": [ - -14.890000343322754, + -0.0, 0.0, - 0.0 + -14.890000343322754 ], "density": 1408.0, "color": [ @@ -19,28 +19,30 @@ 98, 25 ], + "texture": "sun2.jpg", + "size_scale": 50.0, + "distance_scale": 1.0, + "rotation_speed": 0.1, + "ignore_mass": false, + "is_fixed_star": true, "trail_color": [ 255, 0, 0 - ], - "texture": "sun2.jpg", - "size_scale": 50.0, - "distance_scale": 1.0, - "is_fixed_star": true + ] }, { "name": "绿轨太阳B", "mass": 2e+30, "init_position": [ - -299195744.0, + -0.0, 0.0, - 0.0 + -299195744.0 ], "init_velocity": [ - 7.445000171661377, - -12.895118713378906, - 0.0 + 12.895118713378906, + 0.0, + 7.445000171661377 ], "density": 1408.0, "color": [ @@ -48,28 +50,30 @@ 98, 25 ], + "texture": "sun2.jpg", + "size_scale": 50.0, + "distance_scale": 1.0, + "rotation_speed": 0.1, + "ignore_mass": false, + "is_fixed_star": true, "trail_color": [ 0, 255, 0 - ], - "texture": "sun2.jpg", - "size_scale": 50.0, - "distance_scale": 1.0, - "is_fixed_star": true + ] }, { "name": "蓝轨太阳C", "mass": 2e+30, "init_position": [ - 299195744.0, + -0.0, 0.0, - 0.0 + 299195744.0 ], "init_velocity": [ - 7.445000171661377, - 12.895118713378906, - 0.0 + -12.895118713378906, + 0.0, + 7.445000171661377 ], "density": 1408.0, "color": [ @@ -77,28 +81,30 @@ 98, 25 ], + "texture": "sun2.jpg", + "size_scale": 50.0, + "distance_scale": 1.0, + "rotation_speed": 0.1, + "ignore_mass": false, + "is_fixed_star": true, "trail_color": [ 0, 0, 255 - ], - "texture": "sun2.jpg", - "size_scale": 50.0, - "distance_scale": 1.0, - "is_fixed_star": true + ] }, { "name": "流浪地球", "mass": 5.97237e+24, "init_position": [ - 0.0, - 86370368.0, - 747989376.0 + -86370368.0, + 747989376.0, + 0.0 ], "init_velocity": [ - 0.0, - 0.0, - -10.0 + -0.0, + -10.0, + 0.0 ], "density": 5507.85, "color": [ @@ -108,7 +114,15 @@ ], "texture": "earth1.jpg", "size_scale": 4000.0, - "distance_scale": 1 + "distance_scale": 1, + "rotation_speed": null, + "ignore_mass": false, + "is_fixed_star": false, + "trail_color": [ + 1, + 89, + 162 + ] } ], "params": { diff --git a/data/tri_bodies_perfect_02.json b/data/tri_bodies_perfect_02.json index fb8348623a29aa6dc6f84a4265adb2f3b87fceac..7d8024fec18580b221a62c8429e25497e6e3368b 100644 --- a/data/tri_bodies_perfect_02.json +++ b/data/tri_bodies_perfect_02.json @@ -4,14 +4,14 @@ "name": "红轨太阳A", "mass": 2e+30, "init_position": [ + -518222240.0, 0.0, - 518222240.0, 0.0 ], "init_velocity": [ - -14.890000343322754, + -0.0, 0.0, - 0.0 + -14.890000343322754 ], "density": 1408.0, "color": [ @@ -19,28 +19,30 @@ 98, 25 ], + "texture": "sun2.jpg", + "size_scale": 50.0, + "distance_scale": 1.0, + "rotation_speed": 0.1, + "ignore_mass": false, + "is_fixed_star": true, "trail_color": [ 255, 0, 0 - ], - "texture": "sun2.jpg", - "size_scale": 50.0, - "distance_scale": 1.0, - "is_fixed_star": true + ] }, { "name": "绿轨太阳B", "mass": 2e+30, "init_position": [ - -299195744.0, + -0.0, 0.0, - 0.0 + -299195744.0 ], "init_velocity": [ - 7.445000171661377, - -12.895118713378906, - 0.0 + 12.895118713378906, + 0.0, + 7.445000171661377 ], "density": 1408.0, "color": [ @@ -48,28 +50,30 @@ 98, 25 ], + "texture": "sun2.jpg", + "size_scale": 50.0, + "distance_scale": 1.0, + "rotation_speed": 0.1, + "ignore_mass": false, + "is_fixed_star": true, "trail_color": [ 0, 255, 0 - ], - "texture": "sun2.jpg", - "size_scale": 50.0, - "distance_scale": 1.0, - "is_fixed_star": true + ] }, { "name": "蓝轨太阳C", "mass": 2e+30, "init_position": [ - 299195744.0, + -0.0, 0.0, - 0.0 + 299195744.0 ], "init_velocity": [ - 7.445000171661377, - 12.895118713378906, - 0.0 + -12.895118713378906, + 0.0, + 7.445000171661377 ], "density": 1408.0, "color": [ @@ -77,15 +81,17 @@ 98, 25 ], + "texture": "sun2.jpg", + "size_scale": 50.0, + "distance_scale": 1.0, + "rotation_speed": 0.1, + "ignore_mass": false, + "is_fixed_star": true, "trail_color": [ 0, 0, 255 - ], - "texture": "sun2.jpg", - "size_scale": 50.0, - "distance_scale": 1.0, - "is_fixed_star": true + ] } ], "params": { diff --git a/data/tri_bodies_perfect_03.json b/data/tri_bodies_perfect_03.json index b56337e4261c6d7734986074c0c8dbd3756a3c02..77841c9acd4f46efb76f83828fc9618c328c2528 100644 --- a/data/tri_bodies_perfect_03.json +++ b/data/tri_bodies_perfect_03.json @@ -4,14 +4,14 @@ "name": "红轨太阳A", "mass": 2e+30, "init_position": [ + -518222240.0, 0.0, - "$exp:math.sqrt(3) * 2 * AU", 0.0 ], "init_velocity": [ - -14.89, + -0.0, 0.0, - 0.0 + -14.890000343322754 ], "density": 1408.0, "color": [ @@ -19,28 +19,30 @@ 98, 25 ], + "texture": "sun2.jpg", + "size_scale": 50.0, + "distance_scale": 1.0, + "rotation_speed": 0.1, + "ignore_mass": false, + "is_fixed_star": true, "trail_color": [ 255, 0, 0 - ], - "texture": "sun2.jpg", - "size_scale": 50.0, - "distance_scale": 1.0, - "is_fixed_star": true + ] }, { "name": "绿轨太阳B", "mass": 2e+30, "init_position": [ - "$exp: -2 * AU", + -0.0, 0.0, - 0.0 + -299195744.0 ], "init_velocity": [ - "$exp: 1/2 * 14.88", - "$exp:-math.sqrt(3) / 2 * 14.88", - 0.0 + 12.886458396911621, + 0.0, + 7.440000057220459 ], "density": 1408.0, "color": [ @@ -48,28 +50,30 @@ 98, 25 ], + "texture": "sun2.jpg", + "size_scale": 50.0, + "distance_scale": 1.0, + "rotation_speed": 0.1, + "ignore_mass": false, + "is_fixed_star": true, "trail_color": [ 0, 255, 0 - ], - "texture": "sun2.jpg", - "size_scale": 50.0, - "distance_scale": 1.0, - "is_fixed_star": true + ] }, { "name": "蓝轨太阳C", "mass": 2e+30, "init_position": [ - "$exp: 2 * AU", + -0.0, 0.0, - 0.0 + 299195744.0 ], "init_velocity": [ - "$exp: 1/2 * 14.88", - "$exp:math.sqrt(3) / 2 * 14.88", - 0.0 + -12.886458396911621, + 0.0, + 7.440000057220459 ], "density": 1408.0, "color": [ @@ -77,15 +81,17 @@ 98, 25 ], + "texture": "sun2.jpg", + "size_scale": 50.0, + "distance_scale": 1.0, + "rotation_speed": 0.1, + "ignore_mass": false, + "is_fixed_star": true, "trail_color": [ 0, 0, 255 - ], - "texture": "sun2.jpg", - "size_scale": 50.0, - "distance_scale": 1.0, - "is_fixed_star": true + ] } ], "params": { diff --git a/data/tri_bodies_perfect_04.json b/data/tri_bodies_perfect_04.json index f1f833ae2a7129c1b04ea3f6106c65c99a6edcf3..d3b923808491976026a18a9c2de91c0d03811b6a 100644 --- a/data/tri_bodies_perfect_04.json +++ b/data/tri_bodies_perfect_04.json @@ -4,14 +4,14 @@ "name": "红轨太阳A", "mass": 2e+30, "init_position": [ + -518222240.0, 0.0, - 518222240.0, 0.0 ], "init_velocity": [ - -12.0, + -0.0, 0.0, - 0.0 + -12.0 ], "density": 1408.0, "color": [ @@ -35,14 +35,14 @@ "name": "绿轨太阳B", "mass": 2e+30, "init_position": [ - -299195744.0, + -0.0, 0.0, - 0.0 + -299195744.0 ], "init_velocity": [ - 6.0, - -10.392304420471191, - 0.0 + 10.392304420471191, + 0.0, + 6.0 ], "density": 1408.0, "color": [ @@ -66,14 +66,14 @@ "name": "蓝轨太阳C", "mass": 2e+30, "init_position": [ - 299195744.0, + -0.0, 0.0, - 0.0 + 299195744.0 ], "init_velocity": [ - 6.0, - 10.392304420471191, - 0.0 + -10.392304420471191, + 0.0, + 6.0 ], "density": 1408.0, "color": [ diff --git a/data/tri_bodies_perfect_05.json b/data/tri_bodies_perfect_05.json index 183bee0bd800694205c8fa2d3b7d0730513d025e..67349725af8c4464c85b5ccdf2d4cbe656b89af6 100644 --- a/data/tri_bodies_perfect_05.json +++ b/data/tri_bodies_perfect_05.json @@ -4,14 +4,14 @@ "name": "红轨太阳A", "mass": 2e+30, "init_position": [ + -518222240.0, 0.0, - 518222240.0, 0.0 ], "init_velocity": [ - -19.0, + -0.0, 0.0, - 0.0 + -19.0 ], "density": 1408.0, "color": [ @@ -35,14 +35,14 @@ "name": "绿轨太阳B", "mass": 2e+30, "init_position": [ - -299195744.0, + -0.0, 0.0, - 0.0 + -299195744.0 ], "init_velocity": [ - 9.5, - -16.454483032226562, - 0.0 + 16.454483032226562, + 0.0, + 9.5 ], "density": 1408.0, "color": [ @@ -66,14 +66,14 @@ "name": "蓝轨太阳C", "mass": 2e+30, "init_position": [ - 299195744.0, + -0.0, 0.0, - 0.0 + 299195744.0 ], "init_velocity": [ - 9.5, - 16.454483032226562, - 0.0 + -16.454483032226562, + 0.0, + 9.5 ], "density": 1408.0, "color": [ diff --git a/sim_scenes/fiction/fixed_stars.py b/sim_scenes/fiction/fixed_stars.py index 6e1bfd941a5e6b09a1e623e9b395032358fe8869..59afafc06a65f9aa71fab7c5a62212c7f0d6797a 100644 --- a/sim_scenes/fiction/fixed_stars.py +++ b/sim_scenes/fiction/fixed_stars.py @@ -48,7 +48,8 @@ if __name__ == '__main__': d = pow((body.raduis + bodies[idx - 1].raduis) * SIZE_SCALE, 1.0) * 1.1 # d = (body.diameter + bodies[idx - 1].diameter) * SIZE_SCALE * 1.1 + D body.init_velocity = [0, 0, 0] - body.init_position = [body.raduis * SIZE_SCALE, (distance_sum + d), AU] + # body.init_position = [body.raduis * SIZE_SCALE, (distance_sum + d), AU] + body.init_position = [-(distance_sum + d), AU, body.raduis * SIZE_SCALE] distance_sum += d # 使用 ursina 查看的运行效果 diff --git a/sim_scenes/fiction/sun_dysen_sphere.py b/sim_scenes/fiction/sun_dysen_sphere.py index 765f22ec58738d01574e70b8a04d187f22cade78..c460ea78218b5673659be8bc507302a78c0be67f 100644 --- a/sim_scenes/fiction/sun_dysen_sphere.py +++ b/sim_scenes/fiction/sun_dysen_sphere.py @@ -15,7 +15,7 @@ if __name__ == '__main__': 太阳、戴森球 """ - sun = Sun(size_scale=5e1, init_velocity=[0, 2, 0]) # 太阳放大 50 倍 + sun = Sun(size_scale=5e1, init_velocity=[-2, 0, 0]) # 太阳放大 50 倍 bodies = [ sun, DysenSphere(size_scale=5e1, parent=sun), # 戴森球放大 50 倍 @@ -28,4 +28,4 @@ if __name__ == '__main__': # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- ursina_run(bodies, SECONDS_PER_WEEK, position=(0, AU / 4, -3 * AU), - bg_music="sounds/universe_02.mp3") + bg_music="sounds/interstellar.mp3") diff --git a/sim_scenes/interest/text_bodies.py b/sim_scenes/interest/text_bodies.py index aabc2c3c33bc57eb7cde37afbcb40a43a754845e..7779550aae48f07a040f18c8c6d607c8b694bdd6 100644 --- a/sim_scenes/interest/text_bodies.py +++ b/sim_scenes/interest/text_bodies.py @@ -26,8 +26,10 @@ def show_text_bodies(): params={"camera_pos": camera_pos}) # 放一个恒星作为背景 bg = FixedStar(name="bg", texture="fixed_star.png", mass=2e32, color=(0xff, 0xf8, 0xd4), - init_position=[6000 * D, 450 * D, 100 * D], # [ 远+近- , 左+右- , 上+下-] + # init_position=[6000 * D, 450 * D, 100 * D], # [ 远+近- , 左+右- , 上+下-] + init_position=[-450 * D, 100 * D, 6000 * D], # [ 远+近- , 左+右- , 上+下-] ignore_mass=True) + bodies.append(bg) # 使用 ursina 查看的运行效果 diff --git a/sim_scenes/interest/the_eye_of_god.py b/sim_scenes/interest/the_eye_of_god.py index 3dae2da0ca9859bf3b2635221fd5c3d4f177b1c9..9cebee838cd3366a1e9860d6a3675c34df3e9e4a 100644 --- a/sim_scenes/interest/the_eye_of_god.py +++ b/sim_scenes/interest/the_eye_of_god.py @@ -25,7 +25,8 @@ def show_eye_of_god(): params={"camera_pos": camera_pos}) # 放一个恒星作为背景 bg = FixedStar(name="bg", texture="fixed_star.png", mass=2e32, color=(0xff, 0xf8, 0xd4), - init_position=[6000 * D, 400 * D, 100 * D], # [ 远+近- , 左+右- , 上+下-] + # init_position=[6000 * D, 400 * D, 100 * D], # [ 远+近- , 左+右- , 上+下-] + init_position=[-400 * D, 100 * D, 6000 * D], # [ 远+近- , 左+右- , 上+下-] ignore_mass=True) bodies.append(bg) diff --git a/sim_scenes/interest/utils/body_utils.py b/sim_scenes/interest/utils/body_utils.py index 1163f9d10d8f3133df0bc40f1ddf999ee979b457..27f6cccb53a0aeb0ce145879ae3e592f223613b5 100644 --- a/sim_scenes/interest/utils/body_utils.py +++ b/sim_scenes/interest/utils/body_utils.py @@ -43,7 +43,11 @@ def gen_bodies_from_image(pixel_image, params, texture="color_body.png"): def get_position(pos, scale): # return get_scaled_body_pos((camera_pos[2], camera_pos[0], camera_pos[1]), pos, scale) - return get_scaled_body_pos((camera_pos[2], camera_pos[1], camera_pos[0]), pos, scale) + # return get_scaled_body_pos((camera_pos[2], camera_pos[1], camera_pos[0]), pos, scale) + return get_scaled_body_pos((camera_pos[0], camera_pos[1], camera_pos[2]), pos, scale) + + # # body.init_position = [body.raduis * SIZE_SCALE, (distance_sum + d), AU] + # body.init_position = [-(distance_sum + d), AU, body.raduis * SIZE_SCALE] # # [ 远+近- , 左+右- , 上+下-] # return pos[0] + (scale - 1.0) * 300 * (random.randint(90, 110)) * D, pos[1], pos[2] @@ -58,7 +62,7 @@ def gen_bodies_from_image(pixel_image, params, texture="color_body.png"): width, height = img.size interval_factor = 20 # 星球间距因子 body_template = 'ColorBody(name="%s", mass=mass, color=(%d, %d, %d), size_scale=%.4f, ' \ - 'init_position=get_position([0, %g * D, %g * D], %.4f), ' \ + 'init_position=get_position([-%g * D, %g * D, 0], %.4f), ' \ f'init_velocity=[0, 0, 0], ignore_mass=True, texture="{texture}").set_light_disable(True)' bodies_str = "[" diff --git a/sim_scenes/science/gravity_slingshot_1.py b/sim_scenes/science/gravity_slingshot_1.py index 07d5830479692eaaa5a0aff4558204f66a9ee612..9a17fcfba165ed6b759776387a6e1f507fad7dc4 100644 --- a/sim_scenes/science/gravity_slingshot_1.py +++ b/sim_scenes/science/gravity_slingshot_1.py @@ -18,10 +18,12 @@ if __name__ == '__main__': bodies = [ Sun(size_scale=2e1), # 太阳放大 20 倍 Earth(size_scale=1e3, # 地球放大 1000 倍 - init_position=[0, -3 * AU, 0], # 地球距离太阳 3 个天文单位 + # init_position=[0, -3 * AU, 0], # 地球距离太阳 3 个天文单位 + init_position=[3 * AU, 0, 0], # 地球距离太阳 3 个天文单位 # TODO: 尝试调整朝向太阳的速度,取值 33、38、50 或者其他 # init_velocity=[0, 33, -1], - init_velocity=[0, 38, -1], # 朝向太阳的速度为 38km/s,-1 km/s 是为了防止地球正面对着太阳冲去 + # init_velocity=[0, 38, -1], # 朝向太阳的速度为 38km/s,-1 km/s 是为了防止地球正面对着太阳冲去 + init_velocity=[-38, -1, 0], # 朝向太阳的速度为 38km/s,-1 km/s 是为了防止地球正面对着太阳冲去 # init_velocity=[0, 50, -1], ), ] diff --git a/sim_scenes/science/gravity_slingshot_2.py b/sim_scenes/science/gravity_slingshot_2.py index 9236fdd22ba7d276545f1ed92d6906f5a2ff8c42..8d2f8d6c5dfd8951468a749cd3ed29461bd3ca5b 100644 --- a/sim_scenes/science/gravity_slingshot_2.py +++ b/sim_scenes/science/gravity_slingshot_2.py @@ -16,12 +16,13 @@ if __name__ == '__main__': 模拟流浪地球经过木星、土星加速 """ bodies = [ - Jupiter(size_scale=1e2, init_position=[0, AU / 4, 0], init_velocity=[0, 0, 0]), # 木星放大 100 倍 - Saturn(size_scale=1e2, init_position=[AU/1.5, 1.5 * AU, 0], init_velocity=[0, 0, 0]), # 土星放大 100 倍 + Jupiter(size_scale=1e2, init_position=[-AU / 4, 0, 0], init_velocity=[0, 0, 0]), # 木星放大 100 倍 + Saturn(size_scale=1e2, init_position=[-1.5 * AU, 0, AU / 1.5], init_velocity=[0, 0, 0]), # 土星放大 100 倍 Earth(size_scale=3e2, # 地球放大 300 倍 init_position=[0, 0, 0], # # init_velocity=[0, 33, -1], - init_velocity=[-1, 10, 0], # 朝向木星的速度为 38km/s,-1 km/s 是为了防止地球正面对着木星冲去 + # init_velocity=[-1, 10, 0], # 朝向木星的速度为 38km/s,-1 km/s 是为了防止地球正面对着木星冲去 + init_velocity=[-10, 0, -1], # 朝向木星的速度为 38km/s,-1 km/s 是为了防止地球正面对着木星冲去 # init_velocity=[0, 50, -1], ), ] diff --git a/sim_scenes/solar_system/earth_at_night.py b/sim_scenes/solar_system/earth_at_night.py index 768c0147f29d960774874bf1ec84aecc20bea0e0..47d54648298f775b381db7375c9e80000520dc4f 100644 --- a/sim_scenes/solar_system/earth_at_night.py +++ b/sim_scenes/solar_system/earth_at_night.py @@ -17,13 +17,14 @@ if __name__ == '__main__': https://www.nasa.gov/mission_pages/NPP/news/earth-at-night.html https://www.nasa.gov/sites/default/files/images/712130main_8246931247_e60f3c09fb_o.jpg """ - resolution = 500 + resolution = 50 + # resolution = 500 bodies = [ Earth(texture="earth_at_night_hd.jpg", init_position=[0, 0, 0], init_velocity=[0, 0, 0], size_scale=100, ignore_mass=True).set_resolution(resolution), Earth(texture="earth_hd.jpg", - init_position=[0, 10, 0], init_velocity=[0, 0, 0], + init_position=[-10, 0, 0], init_velocity=[0, 0, 0], size_scale=100, ignore_mass=True).set_resolution(resolution) ] # 使用 ursina 查看的运行效果 diff --git a/sim_scenes/solar_system/earth_moon.py b/sim_scenes/solar_system/earth_moon.py index 43f0edfa1bba80a86231a75add6f981450780573..64f2457c7f7433b7fdf999ecca15d88e2af6c18a 100644 --- a/sim_scenes/solar_system/earth_moon.py +++ b/sim_scenes/solar_system/earth_moon.py @@ -14,19 +14,23 @@ from bodies.body import AU if __name__ == '__main__': """ 地球、月球 +init_position=[x, y, z], +init_position=[-y, z, x], +init_velocity=[x, y, z], +init_velocity=[-y, z, x], """ # 地球的Y方向初始速度 EARTH_INIT_VELOCITY = 0 bodies = [ # sun, Earth(init_position=[0, 0, 0], - init_velocity=[0, EARTH_INIT_VELOCITY, 0], size_scale=0.5e1), # 地球放大 5 倍,距离保持不变 - Moon(init_position=[363104, 0, 0], # 距地距离约: 363104 至 405696 km - init_velocity=[0, EARTH_INIT_VELOCITY + 1.023, 0], size_scale=1e1) # 月球放大 10 倍,距离保持不变 + init_velocity=[-EARTH_INIT_VELOCITY, 0, 0], size_scale=0.5e1), # 地球放大 5 倍,距离保持不变 + Moon(init_position=[0, 0, 363104], # 距地距离约: 363104 至 405696 km + init_velocity=[-(EARTH_INIT_VELOCITY + 1.023), 0, 0], size_scale=1e1) # 月球放大 10 倍,距离保持不变 ] # mayavi_run(bodies, SECONDS_PER_HALF_DAY / 2, view_azimuth=-45) # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- - ursina_run(bodies, SECONDS_PER_MONTH, position=(-300000, 200000, -1300000), show_trail=True) + ursina_run(bodies, SECONDS_PER_DAY, position=(-300000, 200000, -1300000), show_trail=True) diff --git a/sim_scenes/solar_system/earth_moon6.py b/sim_scenes/solar_system/earth_moon6.py index 666fce214d2a95e80cc1f461b3262286ad3bc644..ecc64c34e367c169367973c06297d6ef64881924 100644 --- a/sim_scenes/solar_system/earth_moon6.py +++ b/sim_scenes/solar_system/earth_moon6.py @@ -32,4 +32,4 @@ if __name__ == '__main__': # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- - ursina_run(bodies, 60, position=(0, 0, 0), show_trail=True, view_closely=0.001) + ursina_run(bodies, 60, position=(0, 0, -4 * e.diameter), show_trail=True, view_closely=0.001) diff --git a/sim_scenes/solar_system/hd_earth.py b/sim_scenes/solar_system/hd_earth.py index 9d92e8eff68c7a1d57df143e709b41f9a3abd899..a2d8af52492041882cee1dccf3b0d90545ef4292 100644 --- a/sim_scenes/solar_system/hd_earth.py +++ b/sim_scenes/solar_system/hd_earth.py @@ -17,11 +17,11 @@ if __name__ == '__main__': bodies = [ Earth(texture="earth_hd.jpg", init_position=[0, 0, 0], init_velocity=[0, 0, 0], - size_scale=100, show_name=True) + size_scale=1, show_name=True) ] # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- - ursina_run(bodies, SECONDS_PER_HOUR, position=(0, 30000, -2000000), + ursina_run(bodies, SECONDS_PER_HOUR, position=(0, 0, -20000), # cosmic_bg="textures/cosmic1.jpg", - view_closely=True) + view_closely=0.001) diff --git a/sim_scenes/solar_system/hd_mercury.py b/sim_scenes/solar_system/hd_mercury.py index 12b2bc43a5afb588aa837137d80b4a181fdf6acf..0213acaf4997cbebaa66a99bbafc916240dce0ba 100644 --- a/sim_scenes/solar_system/hd_mercury.py +++ b/sim_scenes/solar_system/hd_mercury.py @@ -17,11 +17,11 @@ if __name__ == '__main__': bodies = [ Mercury(texture="mercury_hd.tif", init_position=[0, 0, 0], init_velocity=[0, 0, 0], - size_scale=100, show_name=True) + size_scale=1, show_name=True) ] # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- - ursina_run(bodies, SECONDS_PER_DAY, position=(0, 30000, -800000), + ursina_run(bodies, SECONDS_PER_DAY, position=(0, 0, -8000), # cosmic_bg="textures/cosmic1.jpg", - view_closely=True) + view_closely=0.001) diff --git a/sim_scenes/solar_system/hd_pluto.py b/sim_scenes/solar_system/hd_pluto.py index 42838e363ee4a0b202963458c4b863652b95f97c..60762d439310689641e3d0a18752450cec840ccd 100644 --- a/sim_scenes/solar_system/hd_pluto.py +++ b/sim_scenes/solar_system/hd_pluto.py @@ -7,7 +7,7 @@ # python_version :3.8 # ============================================================================== from bodies import Pluto -from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY +from common.consts import SECONDS_PER_HOUR, SECONDS_PER_DAY from sim_scenes.func import ursina_run if __name__ == '__main__': @@ -17,11 +17,11 @@ if __name__ == '__main__': bodies = [ Pluto(texture="pluto_hd.jpg", init_position=[0, 0, 0], init_velocity=[0, 0, 0], - size_scale=100, show_name=True) + size_scale=2, show_name=True) ] # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- - ursina_run(bodies, SECONDS_PER_DAY, position=(0, 10000, -450000), + ursina_run(bodies, SECONDS_PER_HOUR, position=(0, 0, -9000), # cosmic_bg="textures/cosmic1.jpg", - view_closely=True) + view_closely=0.001) diff --git a/sim_scenes/solar_system/hd_venus.py b/sim_scenes/solar_system/hd_venus.py index fd2aa5838ad5f994d1b3f497915483694fad0586..6ed877e7d960d29f6a4321a0b9c6c8ed25736ca9 100644 --- a/sim_scenes/solar_system/hd_venus.py +++ b/sim_scenes/solar_system/hd_venus.py @@ -17,11 +17,11 @@ if __name__ == '__main__': bodies = [ Venus(texture="venus_hd.jpg", init_position=[0, 0, 0], init_velocity=[0, 0, 0], - size_scale=100, show_name=True) + size_scale=1, show_name=True) ] # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- - ursina_run(bodies, SECONDS_PER_DAY, position=(0, 30000, -1500000), + ursina_run(bodies, SECONDS_PER_DAY, position=(0, 0, -20000), # cosmic_bg="textures/cosmic1.jpg", - view_closely=True) + view_closely=0.001) diff --git a/sim_scenes/solar_system/solar_system_1.py b/sim_scenes/solar_system/solar_system_1.py index f2a0731c75c6e0d7ea5d17d98afa5cafc9ffb864..d2e8ad591c9088ccb67d9171023ce6aeae7af178 100644 --- a/sim_scenes/solar_system/solar_system_1.py +++ b/sim_scenes/solar_system/solar_system_1.py @@ -20,7 +20,7 @@ if __name__ == '__main__': # 以下展示的效果为太阳系真实的距离 # 由于宇宙空间尺度非常大,如果按照实际的天体大小,则无法看到天体,因此需要对天体的尺寸进行放大 sun = Sun(name="太阳", size_scale=0.8e2) # 太阳放大 80 倍,距离保持不变 - # sun.init_velocity = [0, 0, 2] # 太阳带着其他行星一起跑 + # sun.init_velocity = [0, 2, 0] # 太阳带着其他行星一起跑 bodies = [ sun, Mercury(name="水星", size_scale=4e3), # 水星放大 4000 倍,距离保持不变 diff --git a/sim_scenes/solar_system/solar_system_3.py b/sim_scenes/solar_system/solar_system_3.py index 3bf30972091229a3933e831ef7049a858310fe26..e99fdd4313bcd1d40289d0f291ebc5fe0a8a4012 100644 --- a/sim_scenes/solar_system/solar_system_3.py +++ b/sim_scenes/solar_system/solar_system_3.py @@ -49,16 +49,16 @@ if __name__ == '__main__': NUM_OF_ASTEROIDS = 10 asteroids = [] angles = np.linspace(0, 100 * np.pi, NUM_OF_ASTEROIDS) - pxs, pys, vxs, vys = get_positions_velocitys(angles, + pxs, pzs, vxs, vzs = 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], vxs[i], vys[i] + pz, fx, fz = pzs[i], vxs[i], vzs[i] asteroids.append(Asteroid(size_scale=3e9, # 小行星放大 5000000000 倍,距离放大 1.4 倍 - init_position=[px, py, 0], - init_velocity=[fx, fy, 0], + init_position=[px, 0, pz], + init_velocity=[fx, 0, fz], distance_scale=1.4)) # endregion 2 diff --git a/sim_scenes/solar_system/sun_earth_moon.py b/sim_scenes/solar_system/sun_earth_moon.py index 139769bdbb946767678c92ebdefba4c5923f3d5b..e5e61415f15eb22316f43b9656fbc62fad48a638 100644 --- a/sim_scenes/solar_system/sun_earth_moon.py +++ b/sim_scenes/solar_system/sun_earth_moon.py @@ -17,18 +17,18 @@ if __name__ == '__main__': """ # 地球的Y方向初始速度 EARTH_INIT_VELOCITY = 0 # 0km/s - sun = Sun(init_position=[AU, 0, 0], size_scale=2e1) # 太阳放大 20 倍 - # 忽略质量的引力 + sun = Sun(init_position=[0, 0, AU], size_scale=2e1) # 太阳放大 20 倍 + # 忽略质量的引力 [x, y, z]->[-y, z, x] sun.ignore_mass = True # 观看月相变化的过程:分别是 新月、蛾眉月、上弦月、盈凸、满月、亏凸、下弦月、残月 # 参考:images/moon/月相变化过程.jpeg # TODO: 月球在摄像机的前方(从 “新月” 开始) - moon_pos, moon_vel = [384400, 0, 0], [0, EARTH_INIT_VELOCITY + 1.023, 0] - # TODO: 月球在摄像机的右方(从 “下弦月” 开始),将会出现 - # moon_pos, moon_vel = [0, -384400, 0], [1.023, EARTH_INIT_VELOCITY, 0] - # TODO: 月月球在摄像机的左方(从 “上弦月” 开始) - # moon_pos, moon_vel = [0, 384400, 0], [-1.023, EARTH_INIT_VELOCITY, 0] + # moon_pos, moon_vel = [0, 0, 384400], [-(EARTH_INIT_VELOCITY + 1.023), 0, 0] + # TODO: 月球在摄像机的右方(从 “下弦月” 开始),将会从右方出现 + # moon_pos, moon_vel = [384400, 0, 0], [-EARTH_INIT_VELOCITY, 0, 1.023] + # TODO: 月球在摄像机的左方(从 “上弦月” 开始) + moon_pos, moon_vel = [-384400, 0, 0], [EARTH_INIT_VELOCITY, 0, -1.023] bodies = [ sun, diff --git a/sim_scenes/tri_bodies/tri_bodies_perfect.py b/sim_scenes/tri_bodies/tri_bodies_perfect.py index 4208479158c64f3c2d37e5225ffa289f310129c1..68c417b9733afbfa03063830fa6eabaa10934415 100644 --- a/sim_scenes/tri_bodies/tri_bodies_perfect.py +++ b/sim_scenes/tri_bodies/tri_bodies_perfect.py @@ -27,6 +27,7 @@ if __name__ == '__main__': # p = 16 # TODO: 三体转圆形花 # p = 18 # TODO: 三体转圆形花 # p = 19 # TODO: 三体转圆形花 + # [x, y, z]->[-y, z, x] bodies = [ Sun(name="红轨太阳A", mass=mass, init_position=[0, math.sqrt(3) * r, 0], diff --git a/sim_scenes/tri_bodies/two_bodies_01.py b/sim_scenes/tri_bodies/two_bodies_01.py index b58e4da6505811749289a79346dbebc2eaea4e6b..9d75ee907205a78a86a157de4ddf38cf1318cf68 100644 --- a/sim_scenes/tri_bodies/two_bodies_01.py +++ b/sim_scenes/tri_bodies/two_bodies_01.py @@ -19,9 +19,9 @@ if __name__ == '__main__': 3、天体质量 mass """ bodies = [ - Sun(mass=1.5e30, init_position=[849597870.700, 0, 0], init_velocity=[0, 7.0, 0], + Sun(mass=1.5e30, init_position=[849597870, 0, 0], init_velocity=[0, 7.0, 0],trail_color=(255,0,0), size_scale=5e1, texture="sun1.jpg"), # 太阳放大 100 倍 - Sun(mass=2e30, init_position=[0, 0, 0], init_velocity=[0, -8.0, 0], + Sun(mass=1.5e30, init_position=[0, 0, 0], init_velocity=[0, -8.0, 0], size_scale=5e1, texture="sun2.jpg"), # 太阳放大 100 倍 Earth(init_position=[0, 349597870.700, 0], init_velocity=[10.50, 0, 0], size_scale=4e3, distance_scale=1), # 地球放大 4000 倍,距离保持不变 @@ -33,4 +33,4 @@ if __name__ == '__main__': # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- - ursina_run(bodies, SECONDS_PER_YEAR, position=(AU, 2 * AU, -7 * AU), show_trail=True) \ No newline at end of file + ursina_run(bodies, SECONDS_PER_YEAR, position=(1.5 * AU, 0, -7 * AU), show_trail=True) \ No newline at end of file diff --git a/sim_scenes/ursina_json_sim.py b/sim_scenes/ursina_json_sim.py index d965f082beb56138cc308f7389c9bc2665e658b2..2138d3941bb0c6d5f5a2e75d3a224d92290c53e9 100644 --- a/sim_scenes/ursina_json_sim.py +++ b/sim_scenes/ursina_json_sim.py @@ -29,7 +29,7 @@ if __name__ == '__main__': # TODO: 去掉注释,完美数据的三体模型的演示05(画大花) # bodies, params = Body.build_bodies_from_json('../data/tri_bodies_perfect_05.json') # TODO: 去掉注释,引力弹弓的演示 - # bodies, params = Body.build_bodies_from_json('../data/gravity_slingshot.json') + bodies, params = Body.build_bodies_from_json('../data/gravity_slingshot.json') dt = params["dt"] if "dt" in params else SECONDS_PER_YEAR position = params["position"] if "position" in params else (0, 0, 0) diff --git a/simulators/ursina/entities/body_trail.py b/simulators/ursina/entities/body_trail.py index fe8fe909601895e19fdbf2dec046c58391973b06..3f4cb06c1a42c26fd7034f35ca68c23dc2ce8608 100644 --- a/simulators/ursina/entities/body_trail.py +++ b/simulators/ursina/entities/body_trail.py @@ -40,5 +40,14 @@ class BodyTrail(Entity): v_arrow, v_line, v_text = create_arrow_line((0, 0, 0), tuple(vel_direction), parent=self, label=vel_info, color=color.red, alpha=0.8, arrow_scale=0.5) + if str(vel_info).startswith("0.00"): + v_text.parent = self + v_arrow.enabled = False + v_line.enabled = False + a_arrow, a_line, a_text = create_arrow_line((0, 0, 0), tuple(acc_direction), parent=self, label=acc_info, color=color.yellow, alpha=0.8, arrow_scale=0.5) + if str(acc_info).startswith("0.00"): + a_text.parent = self + a_arrow.enabled = False + a_line.enabled = False diff --git a/simulators/ursina/entities/entity_utils.py b/simulators/ursina/entities/entity_utils.py index 5d7b57767a9082b8842da555434017f42f81a6b2..afbd643696c51d1766daea38170a36b3b2d3caca 100644 --- a/simulators/ursina/entities/entity_utils.py +++ b/simulators/ursina/entities/entity_utils.py @@ -173,7 +173,7 @@ def clear_trails(self): self.trails.clear() -def create_fixed_star_lights(parent): +def create_fixed_star_lights(fixed_star): """ 创建恒星的发光的效果、并作为灯光源 :param entity: @@ -181,14 +181,14 @@ def create_fixed_star_lights(parent): """ # 如果是恒星(如:太阳),自身会发光,则需要关闭灯光 - parent.set_light_off() + fixed_star.set_light_off() # lights = [] # # 创建多个新的 Entity 对象,作为光晕的容器 # _color = color.rgba(1.0, 0.6, 0.2, 1) - if hasattr(parent.body_view.body, "glows"): + if hasattr(fixed_star.body_view.body, "glows"): # glows = (glow_num:10, glow_scale:1.03 glow_alpha:0.1~1) - glows = parent.body_view.body.glows + glows = fixed_star.body_view.body.glows if glows is not None: if isinstance(glows, tuple): if len(glows) == 3: @@ -210,16 +210,16 @@ def create_fixed_star_lights(parent): glow_alpha = glow_alphas[-1] # _color = color.white - _color = parent.body_view.body.color + _color = fixed_star.body_view.body.color _color = color.rgba(_color[0] / 255, _color[1] / 255, _color[2] / 255, 1) for i in range(glow_num): - glow_entity = Entity(parent=parent, model='sphere', color=_color, + glow_entity = Entity(parent=fixed_star, model='sphere', color=_color, scale=math.pow(glow_scale, i + 1), alpha=glow_alpha) - if hasattr(parent.body_view.body, "light_on"): - if parent.body_view.body.light_on: + if hasattr(fixed_star.body_view.body, "light_on"): + if fixed_star.body_view.body.light_on: for i in range(2): # 创建 PointLight 对象,作为恒星的灯光源 - light = PointLight(parent=parent, intensity=10, range=10, color=color.white) + light = PointLight(parent=fixed_star, intensity=10, range=10, color=color.white) def merge_vectors(vectors): @@ -229,11 +229,11 @@ def merge_vectors(vectors): # 计算速度的方向 direction = (x / value, y / value, z / value) # 返回速度大小和速度方向 - # return value, direction + return value, direction # return value, (direction[1], direction[0], direction[2]) # return value, (direction[1], direction[2], direction[0]) - return value, (-direction[1], direction[2], direction[0]) + # return value, (-direction[1], direction[2], direction[0]) def create_trail_info(body, trail): @@ -256,10 +256,10 @@ def create_trail_info(body, trail): acc_direction = np.array(acc_direction) * 2 vel_position = vel_direction - vel_position = (vel_position[0], vel_position[1], vel_position[2]) + # vel_position = (vel_position[0], vel_position[1], vel_position[2]) acc_position = acc_direction - acc_position = (acc_position[0], acc_position[1], acc_position[2]) + # acc_position = (acc_position[0], acc_position[1], acc_position[2]) trail.entity_infos = {"velocity": [vel_info, vel_direction, vel_position], "acceleration": [acc_info, acc_direction, acc_position]} diff --git a/simulators/ursina/entities/planet.py b/simulators/ursina/entities/planet.py index 1a38e7ead40ed7d3510599009930deca089d7d28..6c12ff95030e18c4d309de0ca3d783bd47a70b99 100644 --- a/simulators/ursina/entities/planet.py +++ b/simulators/ursina/entities/planet.py @@ -100,7 +100,7 @@ class Planet(Entity): # 创建行星环(目前只有土星环) create_rings(self) - def turn(self): + def update(self): if hasattr(self.body, "torus_stars"): # 星环小天体群(主要模拟小行星群,非一个天体)不受 body_size_factor 影响 self.scale = self.init_scale @@ -110,9 +110,12 @@ class Planet(Entity): pos = self.body_view.position * UrsinaConfig.SCALE_FACTOR if self.body.parent is None: # TODO: ???????? - self.x = -pos[1] - self.y = pos[2] - self.z = pos[0] + # self.x = -pos[1] + # self.y = pos[2] + # self.z = pos[0] + self.x = pos[0] + self.y = pos[1] + self.z = pos[2] else: self.follow_parent() @@ -146,12 +149,13 @@ class Planet(Entity): self.rotation_y, self.rotation_z) - if UrsinaConfig.show_trail: - # 有时候第一个位置不正确,所以判断一下有历史记录后在创建 - if len(self.body.his_position()) > 1: - create_trails(self) - else: - clear_trails(self) + if not hasattr(self.body, "show_trail") or self.body.show_trail: + if UrsinaConfig.show_trail: + # 有时候第一个位置不正确,所以判断一下有历史记录后在创建 + if len(self.body.his_position()) > 1: + create_trails(self) + else: + clear_trails(self) if hasattr(self, "name_text"): d = (camera.world_position - self.name_text.world_position).length() @@ -177,9 +181,12 @@ class Planet(Entity): break pos = self.f_parent.position * UrsinaConfig.SCALE_FACTOR # TODO: ???????? - self.x = -pos[1] - self.y = pos[2] - self.z = pos[0] + # self.x = -pos[1] + # self.y = pos[2] + # self.z = pos[0] + self.x = pos[0] + self.y = pos[1] + self.z = pos[2] def destroy_all(self): # 从天体系统中移除自己(TODO:暂时还不能移除) diff --git a/simulators/ursina/ursina_mesh.py b/simulators/ursina/ursina_mesh.py index 1e595c353df342d2e64dddb1a6b9c135755dfb33..1c202bfb7017ad5cc1738dd601347659ac2ca9d4 100644 --- a/simulators/ursina/ursina_mesh.py +++ b/simulators/ursina/ursina_mesh.py @@ -92,7 +92,7 @@ def create_arrow(height=0.5, width=0.1): def create_arrow_line(from_pos, to_pos, parent=None, label=None, - set_light_off=True, alpha=1.0, + set_light_off=True, alpha=1.0, len_scale=0.5, color=color.white, thickness=2, arrow_scale=1, text_scale=50): """ @@ -103,6 +103,7 @@ def create_arrow_line(from_pos, to_pos, parent=None, label=None, @param label: 箭头显示的文字 @param set_light_off: 是否设置为灯光关闭状态 @param alpha: 透明度 + @param len_scale: 长度缩放 @param color: 箭头线颜色 @param thickness: 线段粗细 @param arrow_scale: 箭头缩放 @@ -111,12 +112,13 @@ def create_arrow_line(from_pos, to_pos, parent=None, label=None, height = 0.5 * thickness width = 0.1 * thickness arrow_mesh = create_arrow(height, width) - verts = (Vec3(from_pos), Vec3(to_pos)) - line = Entity(parent=parent, model=Mesh(vertices=verts, mode='line', thickness=thickness), + from_pos, to_pos = (Vec3(from_pos), Vec3(to_pos)) + line = Entity(parent=parent, + model=Mesh(vertices=(from_pos * len_scale, to_pos * len_scale), mode='line', thickness=thickness), color=color, alpha=alpha) - arrow = Entity(parent=line, model=arrow_mesh, position=verts[1], + arrow = Entity(parent=line, model=arrow_mesh, position=to_pos * len_scale, scale=thickness * arrow_scale, color=color, alpha=alpha) - arrow.look_at(Vec3(to_pos) * 100) + arrow.look_at(to_pos * 100) if set_light_off: line.set_light_off() diff --git a/simulators/views/ursina_view.py b/simulators/views/ursina_view.py index 35c0d473c89a18c21aad1a18b13054be43473282..5393c60b97a049b4ee21f8b842f68cace82f5a96 100644 --- a/simulators/views/ursina_view.py +++ b/simulators/views/ursina_view.py @@ -31,7 +31,7 @@ class UrsinaView(BodyView): :return: """ - self.planet.turn() + self.planet.update() def appear(self): pass diff --git a/sounds/interstellar.mp3 b/sounds/interstellar.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..f1d9c4d483d52b6433ec8f4df4e9ccabe91282b4 Binary files /dev/null and b/sounds/interstellar.mp3 differ