Codigo Python Ruta Ranger-7 2D
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Arc
# Configuración de estilos
plt.style.use('dark_background')
fig, ax = plt.subplots(figsize=(14, 10))
# Cuerpos (posiciones originales)
cuerpos = {
'Sol': {'pos': [0, 0], 'color': 'yellow', 'size': 200},
'Tierra': {'pos': [-150, 0], 'color': 'dodgerblue', 'size': 80},
'Luna': {'pos': [-149.6, 15], 'color': 'lightgray', 'size': 20},
'Marte': {'pos': [-220, 100], 'color': 'tomato', 'size': 60},
'Vesta': {'pos': [250, 150], 'color': 'orange', 'size': 70},
'LISA': {'pos': [325, 195], 'color': 'violet', 'size': 50}
}
# Dibujar cuerpos
for nombre, datos in cuerpos.items():
ax.scatter(*datos['pos'], color=datos['color'], s=datos['size'], label=nombre)
# --- Etiquetas personalizadas ---
# 1. Sol
ax.annotate('Sol', xy=cuerpos['Sol']['pos'], xytext=(0, 20),
textcoords='offset points', color='white', fontsize=10, ha='center')
# 2. Luna
ax.annotate('Luna', xy=cuerpos['Luna']['pos'], xytext=(-150, 30),
textcoords='data', color='white', fontsize=10, ha='center', va='center')
ax.annotate('9 Feb 2042', xy=cuerpos['Luna']['pos'], xytext=(-150, 45),
textcoords='data', color='white', fontsize=9, ha='center', va='center', style='italic')
# 3. Tierra
ax.annotate('Tierra', xy=cuerpos['Tierra']['pos'], xytext=(-140, -10),
textcoords='data', color='white', fontsize=10, ha='center', va='center')
ax.annotate('9 Feb 2042', xy=cuerpos['Tierra']['pos'], xytext=(-140, -25),
textcoords='data', color='white', fontsize=9, ha='center', va='center', style='italic')
# 4. Vesta (Y=140)
ax.annotate('Vesta', xy=cuerpos['Vesta']['pos'], xytext=(250, 140),
textcoords='data', color='white', fontsize=10, ha='center', va='center')
ax.annotate('21 Mar 2042', xy=cuerpos['Vesta']['pos'], xytext=(250, 125),
textcoords='data', color='white', fontsize=9, ha='center', va='center', style='italic')
# 5. LISA
ax.annotate('LISA', xy=cuerpos['LISA']['pos'], xytext=(300, 210),
textcoords='data', color='white', fontsize=10, ha='center', va='center')
ax.annotate('26 Mar 2042', xy=cuerpos['LISA']['pos'], xytext=(300, 225),
textcoords='data', color='white', fontsize=9, ha='center', va='center', style='italic')
# 6. Marte
ax.annotate('Marte', xy=cuerpos['Marte']['pos'], xytext=(10, 10),
textcoords='offset points', color='white', fontsize=10)
# --- Cinturón de asteroides ---
# 1. Banda (entre 2.1 y 3.3 UA)
cinturon_inner = 2.1 * 150 # 315M km
cinturon_outer = 3.3 * 150 # 495M km
ax.add_patch(Arc((0, 0), width=cinturon_outer*2, height=cinturon_outer*2,
theta1=30, theta2=150, color='dimgray', alpha=0.15, lw=1,
label='Cinturón de asteroides'))
ax.add_patch(Arc((0, 0), width=cinturon_inner*2, height=cinturon_inner*2,
theta1=30, theta2=150, color='dimgray', alpha=0.15, lw=1))
# 2. Asteroides aleatorios
np.random.seed(42)
num_asteroides = 80
angles = np.random.uniform(30, 150, num_asteroides)
radii = np.random.uniform(cinturon_inner, cinturon_outer, num_asteroides)
x_ast = radii * np.cos(np.deg2rad(angles))
y_ast = radii * np.sin(np.deg2rad(angles))
ax.scatter(x_ast, y_ast, color='lightgray', s=3, alpha=0.6)
# --- Trayectorias ---
trayectoria_ranger = np.array([cuerpos['Tierra']['pos'], cuerpos['Vesta']['pos']])
trayectoria_hunter = np.array([cuerpos['Vesta']['pos'], cuerpos['LISA']['pos']])
# Ranger-7 (verde claro discontinuo)
ax.plot(trayectoria_ranger[:, 0], trayectoria_ranger[:, 1], 'limegreen',
linestyle='--', linewidth=2, label='Ranger-7 (73.8 km/s)')
# Hunter-X (verde oscuro discontinuo)
ax.plot(trayectoria_hunter[:, 0], trayectoria_hunter[:, 1], 'darkgreen',
linestyle='--', linewidth=2, label='Hunter-X (antimateria)')
# --- Ajustes finales ---
ax.set_xlim(-350, 350)
ax.set_ylim(-50, 250)
ax.set_xlabel('Distancia desde el Sol (millones de km)')
ax.set_ylabel('Distancia desde el Sol (millones de km)')
ax.set_title('Trayectorias Ranger-7 y Hunter-X (Vista eclíptica)', pad=20, fontsize=14)
ax.legend(loc='upper left', bbox_to_anchor=(1.05, 1), framealpha=0.3)
ax.grid(True, linestyle=':', alpha=0.2)
ax.set_aspect('equal')
plt.tight_layout()
plt.savefig('trayectorias_con_cinturon.png', dpi=300, bbox_inches='tight', transparent=True)
plt.show()
Codigo Python Ruta Ranger-7 3D
!pip install astropy matplotlib numpy --quiet
import matplotlib.pyplot as plt
import numpy as np
from astropy.time import Time
from astropy import units as u
import warnings
warnings.filterwarnings("ignore")
# Configuración de fechas
fecha_lanzamiento = Time("2042-02-09")
fecha_llegada_vesta = Time("2042-03-21")
# Posiciones manuales (convertidas a arrays de NumPy)
def posicion_cuerpo(fecha, cuerpo):
if cuerpo == 'sun':
return np.array([0, 0, 0])
elif cuerpo == 'earth':
return np.array([-1.5e8, 0, 0]) # Tierra en febrero
elif cuerpo == 'moon':
return np.array([-1.5e8 + 3.84e5, 0, 0]) # Luna cerca de la Tierra
elif cuerpo == 'mars':
return np.array([-2.2e8, 1e8, 0]) # Marte en posición desfavorable
elif cuerpo == 'vesta':
return np.array([2.5e8, 1.5e8, 0]) # Vesta en Virgo (marzo 2042)
else:
raise ValueError(f"Cuerpo '{cuerpo}' no reconocido")
# Generar gráfico
def plot_sistema_solar():
fig = plt.figure(figsize=(14, 10))
ax = fig.add_subplot(111, projection='3d')
# Cuerpos principales
cuerpos = {
'sun': ('Sol', 'yellow', 300),
'earth': ('Tierra (9 Feb)', 'blue', 100),
'moon': ('Luna (Shackleton)', 'gray', 30),
'mars': ('Marte', 'red', 80),
'vesta': ('Vesta (21 Mar)', 'orange', 60)
}
# Dibujar cuerpos
for cuerpo, (label, color, size) in cuerpos.items():
pos = posicion_cuerpo(fecha_lanzamiento if cuerpo != 'vesta' else fecha_llegada_vesta, cuerpo)
ax.scatter(*pos, color=color, s=size, label=label)
# LISA (0.7 UA más allá de Vesta ~1.05e8 km)
vesta_pos = posicion_cuerpo(fecha_llegada_vesta, 'vesta')
lisa_pos = vesta_pos * 1.3 # Factor simplificado
ax.scatter(*lisa_pos, color='purple', s=40, label='LISA (26 Mar)')
# Trayectoria Ranger-7 (Luna → Tierra → Vesta)
tierra_pos = posicion_cuerpo(fecha_lanzamiento, 'earth')
t = np.linspace(0, 1, 100)
trayectoria = np.array([tierra_pos * (1 - ti) + vesta_pos * ti for ti in t]) # ¡Ahora funciona!
ax.plot(trayectoria[:,0], trayectoria[:,1], trayectoria[:,2], 'g--', label='Ranger-7 (73.8 km/s)')
# Trayectoria Hunter-X (Vesta → LISA)
ax.plot([vesta_pos[0], lisa_pos[0]],
[vesta_pos[1], lisa_pos[1]],
[vesta_pos[2], lisa_pos[2]], 'm-', label='Hunter-X (antimateria)')
# Ajustes visuales
ax.set_xlim(-3e8, 3e8)
ax.set_ylim(-3e8, 3e8)
ax.set_zlim(-1e8, 1e8)
ax.set_xlabel('X (km)')
ax.set_ylabel('Y (km)')
ax.set_zlabel('Z (km)')
ax.set_title('Sistema Solar - Febrero/Marzo 2042\nTrayectorias Ranger-7 y Hunter-X', pad=20)
ax.legend(loc='upper left', bbox_to_anchor=(1, 1))
plt.tight_layout()
plt.show()
plot_sistema_solar()