提交 a1947921 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 7387b622
......@@ -14,6 +14,7 @@ from astropy.coordinates import get_body_barycentric_posvel
from astropy.time import Time
from bodies import Body, Sun, Asteroids, Moon, Earth
from common.consts import G, AU, SECONDS_PER_DAY
from simulators.ursina.ursina_config import UrsinaConfig
def calc_solar_acceleration(body_or_pos, big_body):
......@@ -362,6 +363,24 @@ def init_bodies_pos_vels(bodies):
body.init_velocity = pos_vels['vel']
def get_reality_orbit_points(body_name, start_time=None, days=365, segments=100, scale_factor=1):
if start_time is None:
start_time = Time.now()
if days < segments:
s = 1
else:
s = int(round(days / segments))
points = []
for d in range(0, days, s):
dt = d + start_time
pos, vel = get_body_barycentric_posvel(body_name, dt)
x, y, z = pos.x.value * AU * scale_factor, pos.z.value * AU * scale_factor, pos.y.value * AU * scale_factor
points.append((x, y, z))
return points
def init_bodies_reality_pos_vels(bodies, dt=None):
from astropy.coordinates import solar_system_ephemeris as sse
if dt is None:
......@@ -398,6 +417,7 @@ def init_bodies_reality_pos_vels(bodies, dt=None):
body.init_position = pos
body.init_velocity = vel
if __name__ == '__main__':
from astropy.time import Time # 时间
......@@ -421,5 +441,5 @@ if __name__ == '__main__':
# # show_bodies_posvels(dt)
# bs = gen_real_pos_vel_bodies('sun,Mercury,Venus,Earth,Mars,Jupiter,Saturn,Uranus,Neptune',dt)
# print(bs)
print(get_init_pos_vels()['sun'])
print(get_reality_orbit_points('earth'))
# print(get_init_pos_vels()['sun'])
......@@ -11,7 +11,7 @@ import math
from ursina import camera, application
from bodies import Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto
from common.celestial_data_service import get_init_pos_vels, init_bodies_reality_pos_vels
from common.celestial_data_service import get_init_pos_vels, init_bodies_reality_pos_vels, get_reality_orbit_points
from common.color_utils import trail_color_brightest
from common.consts import SECONDS_PER_YEAR, AU
from common.func import calculate_distance
......@@ -21,7 +21,7 @@ from sim_scenes.func import ursina_run, create_sphere_sky
from simulators.ursina.entities.world_grid import WorldGrid
from simulators.ursina.ursina_config import UrsinaConfig
from simulators.ursina.ursina_event import UrsinaEvent
from simulators.ursina.ursina_mesh import create_orbit_line
from simulators.ursina.ursina_mesh import create_orbit_line, create_orbit_by_points
class HalleyCometSim:
......@@ -34,7 +34,7 @@ class HalleyCometSim:
def build_solar_system(self):
# region 构建太阳系
show_trail = True
show_trail = False
self.sun = Sun(size_scale=0.8e2, show_trail=show_trail)
self.mercury = Mercury(size_scale=5e3, show_trail=show_trail)
self.venus = Venus(size_scale=5e3, show_trail=show_trail)
......@@ -57,11 +57,20 @@ class HalleyCometSim:
self.neptune, # 海王星
# self.pluto, # 冥王星
]
self.bodies = [
self.sun, # 太阳
self.mars, # 火星
self.neptune, # 海王星
]
self.mercury.orbital_days = 87.9691
self.venus.orbital_days = 224.701
self.earth.orbital_days = 365.24219
self.mars.orbital_days = 686.971
self.jupiter.orbital_days = 11.862 * 365.24219
self.saturn.orbital_days = 29.4571 * 365.24219
self.uranus.orbital_days = 84.0205 * 365.24219
self.neptune.orbital_days = 164.8 * 365.24219
# self.bodies = [
# self.sun, # 太阳
# self.mars, # 火星
# self.neptune, # 海王星
# ]
# endregion
trail_color_brightest(self.bodies)
init_bodies_reality_pos_vels(self.bodies)
......@@ -88,40 +97,48 @@ class HalleyCometSim:
def build(self):
self.build_solar_system()
# self.build_halley_comet()
self.build_halley_comet()
def calculate_rotation_angles(self, point1, point2):
def calculate_angles(self, point1, point2):
dx = point2.x - point1.x
dy = point2.y - point1.y
dz = point2.z - point1.z
roll = math.atan2(dy, dz)
pitch = math.atan2(dx, math.sqrt(dy ** 2 + dz ** 2))
yaw = math.atan2(math.sin(roll), math.cos(roll))
roll = math.degrees(math.atan2(dy, dz))
pitch = math.degrees(math.atan2(dx, math.sqrt(dy ** 2 + dz ** 2)))
yaw = math.degrees(math.atan2(math.sin(roll), math.cos(roll)))
return roll, pitch, yaw
def calculate_angles(self, point1, point2):
import numpy as np
# 计算向量AB
AB = point1 - point2
# 计算向量AB与x轴、y轴和z轴之间的夹角
angle_x = np.arctan2(AB.y, AB.x) * 180 / np.pi
angle_y = np.arctan2(AB.z, np.sqrt(AB.x ** 2 + AB.y ** 2)) * 180 / np.pi
angle_z = np.arctan2(np.sqrt(AB.x ** 2 + AB.y ** 2), AB.z) * 180 / np.pi
return angle_x, angle_y, angle_z
def calculate_angles(self, point1, point2):
#
# def calculate_angles(self, point1, point2):
# import numpy as np
# # 计算向量AB
# AB = point1 - point2
#
# # 计算向量AB与x轴、y轴和z轴之间的夹角
# angle_x = np.arctan2(AB.y, AB.x) * 180 / np.pi
# angle_y = np.arctan2(AB.z, np.sqrt(AB.x ** 2 + AB.y ** 2)) * 180 / np.pi
# angle_z = np.arctan2(np.sqrt(AB.x ** 2 + AB.y ** 2), AB.z) * 180 / np.pi
#
# return angle_x, angle_y, angle_z
# 计算向量AB
AB = point2 - point1
# 计算向量AB与x轴、y轴和z轴之间的夹角
angle_x = math.degrees(math.atan2(AB.z, AB.y))
angle_y = math.degrees(math.atan2(AB.z, AB.x))
angle_z = math.degrees(math.atan2(AB.y, AB.x))
return angle_x, angle_y, angle_z
# def calculate_angles(self, point1, point2):
#
# # 计算向量AB
# AB = point2 - point1
# # 计算向量AB与x轴、y轴和z轴之间的夹角
# angle_x = -math.degrees(-math.atan2(AB.z, AB.y))
# angle_y = -math.degrees(-math.atan2(AB.z, AB.x))
# angle_z = math.degrees(math.atan2(AB.y, AB.x))
# return angle_x, angle_y, angle_z
def create_orbit_line(self, center_body, body):
orbital_days = int(math.ceil(body.orbital_days * 1.02))
points = get_reality_orbit_points(type(body).__name__.lower(), days=orbital_days, segments=100)
# print(points)
orbit_line = create_orbit_by_points(center_body.position, points, line_color=body.trail_color)
return orbit_line
def on_ready(self):
"""
......@@ -132,16 +149,16 @@ class HalleyCometSim:
from ursina import scene
UrsinaConfig.trail_type = "line"
UrsinaConfig.trail_length = 91
UrsinaConfig.trail_length = 1000
# UrsinaConfig.trail_length = 1000
UrsinaConfig.trail_thickness_factor = 3
# camera.clip_plane_near = 0.1
camera.clip_plane_far = 1000000
create_sphere_sky(scale=200000)
WorldGrid().draw_axises(10)
# WorldGrid().draw_axises(10)
application.time_scale = 5
self.orbit_lines = []
# self.orbit_lines = []
for body in self.bodies[1:]:
if isinstance(body, HalleComet):
continue
......@@ -160,28 +177,42 @@ body.position - sun.position
"""
orbit_line = create_orbit_line(self.sun, body)
angle_x, angle_y, angle_z = self.calculate_angles(self.sun.planet.position,body.planet.position)
# # 获取body相对于self.sun的位置向量
# relative_position = body.planet.position - self.sun.planet.position
#
# rotation_x = -math.degrees(
# math.atan2(relative_position.y, math.sqrt(relative_position.x ** 2 + relative_position.z ** 2)))
# rotation_y = math.degrees(math.atan2(relative_position.x, relative_position.z))
# # 计算旋转角度
# orbit_line.rotation_x = rotation_x + 90
# orbit_line.rotation_z = 0
# orbit_line.rotation_y = rotation_y + 120
orbit_line = self.create_orbit_line(self.sun, body)
# # orbit_line.enabled = False
# angle_x, angle_y, angle_z = self.calculate_angles(self.sun.planet.position, body.planet.position)
# # # 获取body相对于self.sun的位置向量
# # relative_position = body.planet.position - self.sun.planet.position
# #
# angle = math.atan2(relative_position.y, relative_position.x)
orbit_line.rotation_x = angle_x
orbit_line.rotation_y = angle_y # - 50
orbit_line.rotation_z = -angle_z
# # rotation_x = -math.degrees(
# # math.atan2(relative_position.y, math.sqrt(relative_position.x ** 2 + relative_position.z ** 2)))
# # rotation_y = math.degrees(math.atan2(relative_position.x, relative_position.z))
# # # 计算旋转角度
# # orbit_line.rotation_x = rotation_x + 90
# # orbit_line.rotation_z = 0
# # orbit_line.rotation_y = rotation_y + 120
# # #
# # angle = math.atan2(relative_position.y, relative_position.x)
# #
# # orbit_line.rotation_x = angle_x - 110 # angle_x+90 # angle_x # angle_x
# # orbit_line.rotation_y = angle_y # angle_y+90 # angle_y # - 50
# # orbit_line.rotation_z = angle_z - 90 # angle_z# angle_z # angle_z
#
# # print(body.name,angle_x,angle_y,angle_z)
# # print(body.name, orbit_line.rotation_x, orbit_line.rotation_y, orbit_line.rotation_z)
# # orbit_line.look_at(body.planet)
# # print(body.name, orbit_line.rotation_x, orbit_line.rotation_y, orbit_line.rotation_z)
# # 火星 -90.0 -90.0 0.0
# # 火星 -0.0 -0.0 0.0
# # 火星 113.2222958819701 137.6691000401162 -158.65250912389882
# # 火星 16.115840911865234 -132.33090209960938 104.18995666503906
#
# # 海王星 -90.0 -90.0 0.0
# # 海王星 -0.0 -0.0 0.0
# # 海王星 131.3906379192235 3.0188762268681826 -2.6611704409164667
# # 海王星 2.6574795246124268 93.01887512207031 -90.14009857177734
orbit_line.body = body
self.orbit_lines.append(orbit_line)
# orbit_line.body = body
# self.orbit_lines.append(orbit_line)
self.text_panel = create_text_panel()
......@@ -191,7 +222,7 @@ body.position - sun.position
@param time_data:
@return:
"""
if hasattr(self, "self.halley_comet"):
if hasattr(self, "halley_comet"):
# 哈雷彗星飞行的翻转效果
if self.halley_comet.planet.enabled:
self.halley_comet.planet.rotation_x += 0.1
......@@ -201,13 +232,13 @@ body.position - sun.position
d = calculate_distance(self.halley_comet.position, self.sun.position)
self.text_panel.text = "哈雷彗星距离太阳:%.3f AU" % (d / AU)
for i, orbit_line in enumerate(self.orbit_lines):
if i < 4:
adj_scale = False
else:
adj_scale = True
# 由于天体运行不是标准的圆形,则需要动态调整轨道的大小,保证轨道线始终在天体的中心位置
orbit_line.auto_adjust(adj_scale=adj_scale)
# for i, orbit_line in enumerate(self.orbit_lines):
# if i < 4:
# adj_scale = False
# else:
# adj_scale = True
# # 由于天体运行不是标准的圆形,则需要动态调整轨道的大小,保证轨道线始终在天体的中心位置
# orbit_line.auto_adjust(adj_scale=adj_scale)
if __name__ == '__main__':
......@@ -217,8 +248,6 @@ if __name__ == '__main__':
sim = HalleyCometSim()
sim.build()
# 订阅事件后,上面2个函数功能才会起作用
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent.on_timer_changed_subscription(sim.on_timer_changed)
......
# -*- coding:utf-8 -*-
# title :创建一个圆圈
# description :创建一个圆圈
# author :Python超人
# date :2023-06-24
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
from ursina import *
import math
class OrbitLine(Entity):
def __init__(self, points, position=[0, 0, 0], thickness=0.1, color=color.white, alpha=1):
super().__init__()
self.points = points
self.thickness = thickness
self.color = color
self.alpha = alpha
if position is None:
position = (0, 0, 0)
self.position = position
self.create_orbit_line()
# self.scale = 1
def create_orbit_line(self):
first_point = self.points[0]
last_point = self.points[-1]
x, y, z = self.position[0], self.position[1], self.position[2]
for i, point in enumerate(self.points):
pos_x, pos_y, pos_z = point[0], point[1], point[2]
if i == 0:
next_pos = last_point
continue
elif i == len(self.points) - 1:
next_pos = first_point
# continue
else:
next_pos = self.points[i + 1]
next_x, next_y, next_z = next_pos[0], next_pos[1], next_pos[2]
line = Entity(parent=self,
model=Mesh(vertices=((pos_x + x, pos_y + y, pos_z + z), (next_x + x, next_y + y, next_z + z)),
mode='line',
thickness=self.thickness),
color=self.color, alpha=self.alpha)
line.set_light_off(True)
# angle_step = 360 / self.segments
# r = self.radius # * 1.4363
# for i in range(self.segments):
# angle = math.radians(i * angle_step)
# next_angle = math.radians((i + 1) * angle_step)
#
# # print(i/self.segments)
# #
# # if i/self.segments < 0.5:
# # continue
#
# x = r * math.cos(angle)
# y = r * math.sin(angle)
# next_x = r * math.cos(next_angle)
# next_y = r * math.sin(next_angle)
# pos_x, pos_y, pos_z = self.position
# line = Entity(parent=self,
# model=Mesh(vertices=((pos_x + x, pos_y + y, pos_z), (pos_x + next_x, pos_y + next_y, pos_z)),
# mode='line',
# thickness=self.thickness),
# color=self.color, alpha=self.alpha)
if __name__ == '__main__':
app = Ursina()
window.borderless = False
window.fullscreen = False
window.title = "Circle Line"
window.color = color.black
points = [(-21.94488100961654, -24.37979762447657, -10.77849304138368),
(-20.69949684741718, -25.3794063092057, -11.441480487068922),
(-19.39182354309401, -26.300852969859726, -12.069169771638345),
(-18.02674048253467, -27.142426945109925, -12.660141327813111),
(-16.60907867415109, -27.902574020255674, -13.213064176389562),
(-15.14362861113562, -28.579882998788193, -13.726687937876116),
(-13.635148960039274, -29.17307421068511, -14.199835793087948),
(-12.088375946965746, -29.68098983779498, -14.631398342127286),
(-10.508033342708808, -30.102585956714165, -15.02032831877129),
(-8.89884297148763, -30.436926220426948, -15.365636126019467),
(-7.265535687141621, -30.683177120707214, -15.666386167634117),
(-5.6128627748491144, -30.840604794444, -15.921693960342393),
(-3.9456077473908135, -30.908573358343435, -16.130724021604074),
(-2.2685985115160583, -30.886544778289252, -16.292688538835176),
(-0.586719883821686, -30.77408030196499, -16.406846837500602),
(1.0950735651642898, -30.57084350649222, -16.47250567793171),
(2.771744363581749, -30.276605036937724, -16.489020423968835),
(4.438158721007912, -29.891249136809293, -16.45579714091797),
(6.08907288771184, -29.41478209828403, -16.372295695862626),
(7.719119355782047, -28.84734278786997, -16.23803395028385),
(9.322792992713207, -28.189215432695672, -16.05259315330845),
(10.894437232000922, -27.440844883239368, -15.815624663781122),
(12.428230488715087, -26.602854599886534, -15.526858150725593),
(13.918173023497674, -25.67606764250662, -15.186111444498174),
(15.358074548664657, -24.661530972958428, -14.793302234626063),
(16.741542957357876, -23.56054340870636, -14.348461834471822),
(18.061974665504962, -22.37468758836479, -13.851751256233962),
(19.312547189010015, -21.10586632426604, -13.303479861171981),
(20.48621474123325, -19.756343716467363, -12.704126866436606),
(21.575707830201477, -18.32879138168197, -12.054365998852784),
(22.573538067098934, -16.82634009805203, -11.355093581977755),
(23.47200966805035, -15.252637071656174, -10.607460320026666),
(24.263239441641613, -13.611908875707691, -9.81290699166583),
(24.93918740029395, -11.909029879517561, -8.973204177561405),
(25.491700505087035, -10.149595646121947, -8.090496003419563),
(25.912572430486158, -8.340000307804578, -7.167347668417841),
(26.193622584555193, -6.487516296022832, -6.206796227110711),
(26.326797888611907, -4.600373977132903, -5.212403679933729),
(26.30430093090024, -2.6878377045393194, -4.188310882914239),
(26.11874795525543, -0.7602735327107313, -3.1392900954155394),
(25.76335958923175, 1.170797628173282, -2.070793143561363),
(25.23218608955924, 3.092669239410753, -0.9889912048413321),
(24.520367003293426, 4.99145015975521, 0.09919882718125834),
(23.624422340882834, 6.8521082470857415, 1.1861074560535447),
(22.54256852675394, 8.658568096402977, 2.2633320472008704),
(21.275047562449068, 10.39387424333678, 3.321789894998355),
(19.82445226238634, 12.040429405016774, 4.351811781917988),
(18.196024669622055, 13.580313566260228, 5.343281505089151),
(16.39789975826046, 14.99568363788025, 6.285824115359243),
(14.441263529685058, 16.269245076045834, 7.169041470726426),
(12.340395001250481, 17.384776878812648, 7.982788337958673),
(10.11256655526105, 18.327681062054772, 8.717476251490464),
(7.777787196905585, 19.08551894715255, 9.364386608977702),
(5.358387910330151, 19.648491512186265, 9.915970251400221),
(2.8784656633315953, 20.00982150168267, 10.366109212984883),
(0.36321976864786865, 20.166001835774956, 10.71031820495936),
(-2.1617720937171296, 20.11688756001358, 10.945868772481012),
(-4.6712837019570586, 19.865625109039684, 11.071827150603035),
(-7.1411221649785706, 19.418429991745754, 11.089006176758769),
(-9.548716240292915, 18.784238948433018, 10.999840449542353),
(-11.87357917516475, 17.974272713460227, 10.808200727732686),
(-14.097630306706685, 17.001549591305498, 10.519167414757419),
(-16.205375234826104, 15.880388399598262, 10.138783704649164),
(-18.183957027457616, 14.62593332115373, 9.673807064840286),
(-20.023099378046236, 13.253724729127423, 9.131474079133424),
(-21.714966750734394, 11.779330950905965, 8.519289240311833),
(-23.25396695782603, 10.218047637885025, 7.844843891210241),
(-24.636519368670594, 8.584664752406985, 7.115667724763344),
(-25.860808163667656, 6.893296474882457, 6.339112346052557),
(-26.92653567371258, 5.157266482432186, 5.522264422716854),
(-27.834686570557604, 3.389039737054159, 4.671884805439541),
(-28.587309911931857, 1.6001917433840749, 3.794369515292248),
(-29.18732298633967, -0.1985931957588598, 2.8957284811644475),
(-29.638338578231778, -1.9975022098882875, 1.9815781973802875),
(-29.944515620242278, -3.7875588950254255, 1.0571449231856562),
(-30.110432106478633, -5.560578290263954, 0.12727556228497394),
(-30.140978486956822, -7.309115841477003, -0.8035461227619651),
(-30.041269434221846, -9.026413439984076, -1.731179829382695),
(-29.816571771259866, -10.706344820595417, -2.651807016561835),
(-29.47224639777052, -12.343361951692902, -3.5619082854845048),
(-29.013702191152564, -13.932443536007113, -4.458240646585258),
(-28.446360047139304, -15.46904634504916, -5.337815249404152),
(-27.775625434129118, -16.949059812806492, -6.197875971134596),
(-27.00686804578578, -18.368764096793043, -7.0358791217280485),
(-26.145407336973662, -19.724791659320704, -7.84947441972057),
(-25.19650291220216, -21.014092314854846, -8.636487316701892),
(-24.165348900192242, -22.233901619374436, -9.394902693941335),
(-23.057071592644412, -23.381712434623584, -10.122849916722984),
(-21.876729749979507, -24.45524947753456, -10.81858920694202),
(-20.629317083774875, -25.45244665649841, -11.480499278832571),
(-19.31976651579737, -26.371426998272472, -12.107066174480224),
(-17.952955890017147, -27.210484977825015, -12.696873232390855),
(-16.533714877244847, -27.9680710773236, -13.24859212326067),
(-15.066832865234222, -28.64277841685554, -13.760974890328718),
(-13.55706767086893, -29.2333313180628, -14.23284693708925),
(-12.009154946728776, -29.738575681668195, -14.663100912017619),
(-10.42781818406783, -30.157471079956984, -15.05069144761191),
(-8.817779237553646, -30.48908448609274, -15.39463071975492),
(-7.183769316055346, -30.732585582922045, -15.693984802536873),
(-5.530540397926251, -30.88724361506492, -15.94787080350579),
(-3.8628770400430756, -30.952425769390544, -16.155454774571528),
(-2.18560855627794, -30.92759709082886, -16.31595040479727),
(-0.5036215448234908, -30.812321962783727, -16.428618512845357),
(1.1781272570405819, -30.606267204598176, -16.492767369315498),
(2.854597815692511, -30.309206862654143, -16.507753892472227),
(4.520653375436303, -29.921028796977673, -16.47298577530617),
(6.171046810994123, -29.44174319188224, -16.387924617431697),
(7.800406824200331, -28.87149314721803, -16.25209015229856),
(9.403224076541365, -28.21056753625436, -16.065065678591232),
(10.973837383082055, -27.45941634694761, -15.826504824617844),
(12.506420137195818, -26.618668754945496, -15.536139795916995),
(13.994967191539224, -25.689154208377893, -15.193791279051903),
(15.433282491070607, -24.671926835326747, -14.799380198329342),
(16.814967842163394, -23.568293512819064, -14.352941546259308),
(18.133413310863354, -22.379845958930975, -13.85464053201861),
(19.38178987739886, -21.1084972231426, -13.304791313315457),
(20.553045137048162, -19.756522949307815, -12.703878593531268),
(21.639903033301973, -18.326607763642453, -12.052582374581782),
(22.634868842347245, -16.82189708662963, -11.35180615151596),
(23.530240899674414, -15.246054571112873, -10.602708811420014),
(24.31813087113227, -13.603325211982156, -9.806740447684136),
(24.990494717521393, -11.898603936125157, -8.965682210167165),
(25.539176873780104, -10.137509139796, -8.081690167906071),
(25.955970540624772, -8.32646016617523, -7.157342946657811),
(26.23269733404947, -6.472757078039512, -6.195692598839064),
(26.3613098031624, -4.584660249079574, -5.200317746778991),
(26.334020431382253, -2.671466249544952, -4.175377491267205),
(26.14346057254827, -0.7435752305332493, -3.125663881274313),
(25.782872202586347, 1.18745646166574, -2.056649894721359),
(25.246334220867677, 3.1088863127409017, -0.9745289050304365),
(24.529023130392066, 5.00678777299953, 0.11375943990850972),
(23.627505093847407, 6.866095307272919, 1.2005230132706488),
(22.540052500118392, 8.670703934941352, 2.2773375731288716),
(21.266973317201355, 10.40363456320212, 3.335100947868034),
(19.810935916244492, 12.047274605856346, 4.364127908609831),
(18.177266304805254, 13.583699549366544, 5.354291143416605),
(16.374189746179955, 14.995074974949148, 6.295210975317589),
(14.412985822879385, 16.264130144979195, 7.1764922811678185),
(12.30802651541831, 17.374684255125604, 7.988001669494753),
(10.076671987896901, 18.31219615395574, 8.720171942691843),
(7.739009005234556, 19.06429963986386, 9.364315165062925),
(5.317431664931192, 19.621281505777347, 9.912921489992307),
(2.836081531671903, 19.97646013112301, 10.359919431553406),
(0.3201813654872296, 20.126429459449593, 10.700875253485295),
(-2.204689922986222, 20.071146054304588, 10.933114621912363),
(-4.713326493038292, 19.813853532609677, 11.055757817732077),
(-7.181575304255377, 19.36085598555883, 11.069669148544705),
(-9.586921093991878, 18.72116682677589, 10.977329993000684),
(-11.908945142448367, 17.906069420351642, 10.782651636553934),
(-14.129642551906253, 16.928629732838303, 10.49074781403587),
(-16.233598289452026, 15.803199442368225, 10.107687515934249),
(-18.208034775489025, 14.544941822163866, 9.640246647122032),
(-20.042752129272664, 13.16940419121137, 9.095673436239364),
(-21.729986173214698, 11.69215163109899, 8.48147804962687),
(-23.26420961032611, 10.128468408076436, 7.805252483637207),
(-24.64189948044275, 8.493126939132871, 7.07452304399873),
(-25.861290183495758, 6.80021949146178, 6.296634841521143),
(-26.922126978651644, 5.063045004166385, 5.478665783487524),
(-27.825430602701644, 3.2940421486850697, 4.627366418280784),
(-28.573279908711037, 1.5047595941533065, 3.749121522643523),
(-29.16861638858044, -0.2941449700716349, 2.849929319209709),
(-29.615072140458935, -2.092884506013642, 1.935394505604362),
(-29.916821206439725, -3.882507275071369, 1.0107317313905146),
(-30.0784531282681, -5.6548515668692625, 0.08077667662413653),
(-30.10486692637688, -7.4024945229839245, -0.8499975982862481),
(-30.001183386739708, -9.118698116892686, -1.777460886052639),
(-29.772673443768234, -10.797354552651113, -2.697804087186791),
(-29.424700499018265, -12.432932697672031, -3.6075165727175382),
(-28.962674656862212, -14.020426654393145, -4.503363454368126),
(-28.392017047994376, -15.555307183270559, -5.382363332359457),
(-27.718132620939905, -17.033476395251995, -6.241766912105139),
(-26.94638999231876, -18.451225915835927, -7.0790367438258555),
(-26.08210714660992, -19.805198569751624, -7.891828236610946),
(-25.130541959803278, -21.09235352935445, -8.677972022828728),
(-24.09688668516151, -22.309934800908128, -9.435457694986546),
(-22.98626568318689, -23.455442880617845, -10.162418899630222),
(-21.803735802071813, -24.526609390138525, -10.857119748173542),
(-20.55428892132058, -25.52137449310772, -11.517942489153198),
(-19.242856260969532, -26.43786689661808, -12.143376378366822),
(-17.874314134861976, -27.274386250273903, -12.732007680135089),
(-16.453490889472032, -28.029387769407826, -13.282510733837487),
(-14.985174822607998, -28.701468925584816, -13.7936400232368),
(-13.474122919646003, -29.289358066230015, -14.264223191611748),
(-11.925070280947274, -29.791904844785776, -14.693154952439626),
(-10.342740142934185, -30.20807236326696, -15.07939185331486),
(-8.731854419112032, -30.536930949597302, -15.42194785928068),
(-7.097144705647395, -30.77765351309863, -15.71989073106301),
(-5.44336371051937, -30.929512442537348, -15.972339183439676),
(-3.7752970755462387, -30.991878032538366, -16.178460819345627),
(-2.0977755674068037, -30.964218445960192, -16.337470846246234),
(-0.41568761673621024, -30.84610124223122, -16.44863159297245),
(1.2660078156820496, -30.63719652480965, -16.51125285759214),
(2.942268071292068, -30.33728178512029, -16.524693130298893),
(4.60795335864535, -29.946248545647894, -16.488361749687922),
(6.2578130982208116, -29.46411093155174, -16.40172206644218),
(7.886472113749149, -28.891016328264538, -16.264295705444646),
(9.488416762603253, -28.227258312030553, -16.075668035782382),
(11.057981131982856, -27.47329207110799, -15.835494978085835),
(12.58933347185152, -26.629752566957766, -15.543511300110904),
(14.076463091952341, -25.69747571646506, -15.199540574260645),
(15.51316802115217, -24.677522907002764, -14.80350699452719),
(16.893043816157988, -23.571209183999045, -14.3554492744177),
(18.20947401636866, -22.380135473202184, -13.855536870835001),
(19.455622876491415, -21.106225213071653, -13.304088799932837),
(20.62443117255558, -19.75176577137886, -12.701595327244778),
(21.708616073862952, -18.319454997366396, -12.048742822649002),
(22.700676307693726, -16.812453206166982, -11.346442065820469),
(23.592904116514664, -15.234440794151977, -10.595860263740303),
(24.377405820373912, -13.589681524604838, -9.798456989182457),
(25.04613314475705, -11.883091283791883, -8.956024157275777),
(25.59092784678037, -10.120311762255119, -8.070730011426932),
(26.00358254915857, -8.30778803724571, -7.145166873084488),
(26.27592103741464, -6.452848388667978, -6.182402101904724),
(26.39990153726024, -4.563783843403656, -5.186031292584043),
(26.367746587339177, -2.649923887665426, -4.160232181107273),
(26.172102948790442, -0.7217035092076534, -3.109817032540067),
(25.8062344072354, 1.2092847475214568, -2.0402804318262584),
(25.26424915570592, 3.1302616354846386, -0.9578384205441786),
(24.541361515813833, 5.027264479778774, 0.13054612651704203),
(23.63418489154242, 6.885193720189724, 1.2171580014398702),
(22.54104895504181, 8.687914305671535, 2.293550953735472),
(21.262329176901044, 10.418423215351922, 3.350603026361399),
(19.800771205951765, 12.059092514902552, 4.3786127766700025),
(18.161786864439183, 13.591993457735564, 5.367441733541845),
(16.353693604916987, 14.999300914248975, 6.306705625768824),
(14.387866440364883, 16.263768948611055, 7.186012689229037),
(12.278771998360162, 17.369258321947953, 7.995241930414798),
(10.043859625173821, 18.301286418259075, 8.724848184197105),
(7.703294854560048, 19.047561479505113, 9.366175127547685),
(5.27953543247004, 19.598458243352095, 9.911753308669718),
(2.796767535883519, 19.947392897316654, 10.355558880892692),
(0.2802368662790735, 20.09106249884588, 10.69321082971422),
(-2.2444774194851647, 20.029527020186453, 10.922090054339895),
(-4.752191244011166, 19.766128856530347, 11.041371877406402),
(-7.218793091517313, 19.307261918869536, 11.051972911291042),
(-9.621825527270794, 18.66201714395288, 10.956421960237465),
(-11.940939771347658, 17.841740991296138, 10.758671282812875),
(-14.1582085557003, 16.85954720141226, 10.463868198284665),
(-16.258297955702016, 15.729820120032691, 10.078107571021551),
(-18.22851130466336, 14.467741672172536, 9.608183670786095),
(-20.058726492589894, 13.088865500328295, 9.061356178046829),
(-21.74125181489532, 11.6087526932619, 8.445140649231032),
(-23.27062575087321, 10.042675312734024, 7.767129388377437),
(-24.64338367958625, 8.405387382775379, 7.0348449306279015),
(-25.85781069235312, 6.710958416360196, 6.255625492286006),
(-26.913695275488926, 4.972661806612817, 5.436539819792117),
(-27.81209438242012, 3.2029091779774976, 4.584327771028205),
(-28.55511669114883, 1.4132216714362453, 3.705362511660376),
(-29.14572782856216, -0.3857702591447405, 2.805630218913448),
(-29.587579061925226, -2.1843059569390517, 1.8907234858936488),
(-29.884859341405505, -3.973458824273209, 0.9658450778411328),
(-30.042169515002602, -5.745090806260923, 0.03581921011002458),
(-30.06441690650605, -7.491801078674849, -0.8948919672300807),
(-29.95672813455267, -9.206871974175113, -1.8221685189278902),
(-29.724377960345482, -10.884214387418222, -2.7422109344181154),
(-29.372732006737802, -12.518314256303269, -3.651517474871953),
(-28.90720133488792, -14.104181210474502, -4.546861449026946),
(-28.33320705543823, -15.637300088795035, -5.425268981601892),
(-27.656153360851725, -17.11358573597095, -6.28399766063232),
(-26.881407575849455, -18.529341274945708, -7.120516314180275),
(-26.014286022714273, -19.881219899708324, -7.9324860649758895),
(-25.060044681097946, -21.16619012912206, -8.717742737018279),
(-24.023873785305867, -22.381504394110646, -9.474280634763627),
(-22.91089564534744, -23.52467078895981, -10.200237678464209),
(-21.726165101642177, -24.593427795952962, -10.893881854903926),
(-20.47467212897231, -25.585721784919176, -11.553598927740033),
(-19.16134619496576, -26.499687091504953, -12.177881343556779),
(-17.7910620534659, -27.33362848741607, -12.765318266996347),
(-16.36864671645597, -28.0860058694152, -13.314586679003115),
(-14.898887399984265, -28.755421011033505, -13.824443476024236),
(-13.386540283475277, -29.34060623915545, -14.29371851317865),
(-11.836339956700572, -29.8404149177624, -14.72130854154207),
(-10.253009458070018, -30.25381364120463, -15.106171997378192),
(-8.641270830922831, -30.57987606017589, -15.447324609875391),
(-7.0058561432262705, -30.817778284364316, -15.743835803117149),
(-5.3515189298508465, -30.966795826954453, -15.99482587791421),
(-3.6830460271536367, -31.026302077456265, -16.199463969411475),
(-2.005269776034576, -30.995768311203587, -16.356966787395894),
(-0.3230805727303798, -30.87476526626488, -16.466598157877183),
(1.3585602540179265, -30.662966341701605, -16.527669396968705),
(3.0346072650023688, -30.36015249532571, -16.539540561467142),
(4.69991746624465, -29.966218944487377, -16.501622635009248),
(6.3492366464488015, -29.481183800093383, -16.413380724343806),
(7.977185563268204, -28.90519879227949, -16.274338357298717),
(9.578246072151726, -28.238562275593573, -16.08408299251564),
(11.146747325625084, -27.481734732424652, -15.842272871051813),
(12.676852215741931, -26.635357024909716, -15.548645361427047),
(14.162544288809121, -25.700271677442487, -15.203026972572209),
(15.597615433499238, -24.67754750231404, -14.805345232842257),
(16.975654732142488, -23.568507909130457, -14.35564265746664),
(18.29003897618526, -22.374763260499684, -13.854093050005721),
(19.5339254819013, -21.098247649698198, -13.301020404444913),
(20.70024800763803, -19.741260474038338, -12.696920690616993),
(21.781716772063245, -18.306513153850574, -12.042486813466091),
(22.77082380789144, -16.797181291667222, -11.338637031467934),
(23.659855160268933, -15.216962465913648, -10.586547094422269),
(24.440911752602442, -13.570139692551153, -9.787686307403222),
(25.105941091502064, -11.861650345454521, -8.94385763418386),
(25.646782355417173, -10.097159977554108, -8.057241805795318),
(26.055227787782034, -8.283140001116326, -7.130445180506149),
(26.323103659753, -6.426947536447216, -6.16655079044336),
(26.44237432531076, -4.5369048941560965, -5.169171585839343),
(26.40527298297386, -2.6223750943226616, -4.142504330157472),
(26.204462574096812, -0.6938285407526031, -3.0913818937157687),
(25.83322964630002, 1.2371055148685677, -2.0213208386725046),
(25.28571282247306, 3.1576106918890767, -0.9385602062208114),
(24.55716555776763, 5.053687940820556, 0.14991363290562287),
(23.644249973035517, 6.910203625299165, 1.2363622099185467),
(22.54535462566689, 8.710992818314221, 2.312317204072807),
(21.260924164168873, 10.439029054394306, 3.3686369579948643),
(19.793783190704396, 12.076669857223878, 4.395604072707328),
(18.149430926531615, 13.605983392795327, 5.3830693661736015),
(16.336278400523177, 15.009155298940406, 6.320644619348313),
(14.365797134404106, 16.26896621563744, 7.197942263534556),
(12.252549066968841, 17.369320469630356, 8.004854703314017),
(10.01407289180563, 18.295796105678775, 8.73185992473207),
(7.670612527679701, 19.036177934374482, 9.370334392862148),
(5.24468843233358, 19.580930625536453, 9.912850209896536),
(2.7605299524653812, 19.923569891501337, 10.353432235389079),
(0.24340387730282564, 20.060897237864815, 10.687753081808165),
(-2.28111252300855, 19.99307692105629, 10.91324957046932),
(-4.7878591955332706, 19.723550498973253, 11.029152505693107),
(-7.252768386526647, 19.258801608545713, 11.036430986556523),
(-9.653442568466271, 18.60799818939644, 10.93766118060082),
(-11.969604718139925, 17.782548929908582, 10.736836044961459),
(-14.18340668355668, 16.79561422683218, 10.43913604033054),
(-16.27959677290355, 15.661609822230423, 10.05068134238044),
(-18.245559995576258, 14.39573495815452, 9.578283951785922),
(-20.071252439305017, 13.01354827816581, 9.02921433857036),
(-21.74905500444579, 11.530605626690779, 8.41099279426736),
(-23.27357183346558, 9.962165721269072, 7.731211309915596),
(-24.641396338632553, 8.322963190005758, 6.997388082433197),
(-25.850863853906407, 6.627043936922913, 6.216853930359744),
(-26.901805546366287, 4.887655103956426, 5.396668005776613),
(-27.795313980748645, 3.1171807067150885, 4.54355911301341),
(-28.53352702750502, 1.327113928618621, 3.6638885115247213),
(-29.119433814026227, -0.4719423227943447, 2.7636301011115783),
(-29.55670415927588, -2.2702539790909495, 1.848364195439651),
(-29.84954133499103, -4.058919702302065, 0.9232815509524747),
(-30.00255694933961, -5.829825137977894, -0.006805162559097177),
(-30.020666129727775, -7.575591480598035, -0.9374447491539986),
(-29.909000877225726, -9.28952135826367, -1.8645275585168035),
(-29.672839380125986, -10.965544254929299, -2.7842636566202468),
(-29.317549132815664, -12.598163049467013, -3.6931601621658285),
(-28.848541851673705, -14.182402748888308, -4.587998532458493),
(-28.271238371391888, -15.713762106949055, -5.465812356249192),
(-27.591041915018312, -17.188168530577812, -6.323866035054244),
(-26.81331834129269, -18.601936464873805, -7.159634599580472),
(-25.943382171906006, -19.951729297848157, -7.970784807350811),
(-24.98648738394169, -21.234524722488594, -8.755157593357792),
(-23.947822115289576, -22.447583426958268, -9.510751893058032),
(-22.832506573478728, -23.588420942815024, -10.235709820373627),
(-21.64559356145595, -24.654782460010765, -10.928303159324216),
# (-20.392071139114123, -25.644620410102693, -11.586921113086897),
# (-19.076867028233274, -26.556074621937885, -12.210059246583814),
# (-17.704854443684653, -27.387454863193295, -12.796309555776181),
# (-16.280859096103654, -28.137225595328914, -13.344351597953759),
# (-14.809667163258837, -28.803992786319675, -13.85294462089545),
# (-13.296034070562884, -29.38649264411157, -14.320920634223222),
# (-11.744693956167277, -29.88358215368191, -14.747178373292922),
# (-10.160369724956372, -30.294231320839895, -15.130678113794152),
# (-8.547783619061688, -30.617517046551036, -15.470437303845863),
# (-6.91166825041581, -30.85261857658755, -15.765526989747054),
# (-5.256778055250306, -30.998814492288478, -16.015069021259926),
# (-3.587901140281036, -31.055481229693438, -16.218234032757472)
]
orbit_line = OrbitLine(points, thickness=10, color=color.yellow, alpha=0.1)
EditorCamera()
app.run()
......@@ -17,6 +17,7 @@ import math
from common.color_utils import conv_to_vec4_color
from common.func import calculate_distance
from simulators.ursina.entities.circle_line import CircleLine
from simulators.ursina.entities.orbit_line import OrbitLine
from simulators.ursina.ursina_config import UrsinaConfig
......@@ -136,6 +137,22 @@ def create_circle_line(parent=None, radius=1, position=None, segments=100, thick
return circle_line
def create_orbit_line(parent=None, position=None, points=100, thickness=0.1, color=color.white, alpha=1):
if isinstance(color, tuple) or isinstance(color, list):
color = conv_to_vec4_color(color)
if alpha < 1:
color[3] = alpha
orbit_line = OrbitLine(position=position, points=points, thickness=thickness, color=color,
alpha=alpha)
orbit_line.set_light_off(True)
if parent is not None:
if hasattr(parent, "planet"):
parent = parent.planet
orbit_line.parent = parent
return orbit_line
def create_arrow_line(from_pos, to_pos, parent=None, label=None,
set_light_off=True, alpha=1.0, len_scale=0.5,
color=color.white, thickness=2,
......@@ -263,6 +280,32 @@ def create_orbit_line(center_obj, orbiting_obj, thickness=5, line_color=None, al
return orbit_line
def create_orbit_by_points(center_pos, orbiting_points, thickness=5, line_color=color.white, alpha=0.6,
scale_factor=None):
if isinstance(line_color, tuple) or isinstance(line_color, list):
line_color = conv_to_vec4_color(line_color)
if alpha < 1:
line_color[3] = alpha
if scale_factor is None:
scale_factor = UrsinaConfig.SCALE_FACTOR
if scale_factor != 1:
center_pos = center_pos * scale_factor
for i, point in enumerate(orbiting_points):
orbiting_points[i] = np.array([point[0] * scale_factor, point[1] * scale_factor, point[2] * scale_factor])
orbit_line = OrbitLine(points=orbiting_points, position=center_pos, thickness=thickness, color=line_color,
alpha=alpha)
orbit_line.set_light_off(True)
# if parent is not None:
# if hasattr(parent, "planet"):
# parent = parent.planet
# circle_line.parent = parent
return orbit_line
def create_orbit_line2(center_obj, orbiting_obj, line_color=color.white, alpha=0.3):
if isinstance(line_color, tuple) or isinstance(line_color, list):
line_color = color.rgba(line_color[0] / 255, line_color[1] / 255, line_color[2] / 255, alpha)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册