Skip to content

Commit 58580f0

Browse files
First Commit in this repository.
1 parent 3aa09cd commit 58580f0

File tree

12 files changed

+371
-0
lines changed

12 files changed

+371
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Controlador:
2+
def __init__(self, simulador, vista):
3+
self.simulador = simulador
4+
self.vista = vista
5+
6+
def ejecutar_simulacion(self):
7+
self.simulador.simular()
8+
self.vista.configurar_grafico()
9+
self.vista.animar()
Binary file not shown.

Simulación orbital/Main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from Models.EulerSimulador import EulerSimulador
2+
from Models.VerletSimulador import VerletSimulador
3+
from Views.VistaOrbital import VistaOrbital
4+
from Controllers.Controlador import Controlador
5+
6+
# Elegir método (EulerSimulador o VerletSimulador)
7+
simulador = VerletSimulador(dt=86400, velocidad_inicial=29783)
8+
vista = VistaOrbital(simulador)
9+
controlador = Controlador(simulador, vista)
10+
11+
controlador.ejecutar_simulacion()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from .SimuladorBase import SimuladorBase
2+
3+
4+
class EulerSimulador(SimuladorBase):
5+
def simular(self):
6+
t = 0
7+
while t < self.t_total:
8+
ax, ay = self.calcular_aceleracion(self.x, self.y)
9+
self.vx += ax * self.dt
10+
self.vy += ay * self.dt
11+
self.x += self.vx * self.dt
12+
self.y += self.vy * self.dt
13+
self.x_vals.append(self.x)
14+
self.y_vals.append(self.y)
15+
t += self.dt
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import math
2+
3+
4+
class SimuladorBase:
5+
G = 6.6748e-11 # Constante gravitacional
6+
M_SOL = 1.989e30 # Masa del Sol (kg)
7+
UA = 1.496e11 # 1 UA en metros
8+
9+
def __init__(self, dt=86400, velocidad_inicial=29783):
10+
self.dt = dt # Paso de tiempo (1 día)
11+
self.x = self.UA # Posición inicial en X
12+
self.y = 0.0 # Posición inicial en Y
13+
self.vx = 0.0 # Velocidad inicial en X
14+
self.vy = velocidad_inicial # Velocidad inicial en Y
15+
self.t_total = dt * 365 # 1 año en segundos
16+
self.x_vals = []
17+
self.y_vals = []
18+
19+
def calcular_aceleracion(self, x, y):
20+
r = math.sqrt(x**2 + y**2)
21+
a_mag = -self.G * self.M_SOL / r**3
22+
ax = a_mag * x
23+
ay = a_mag * y
24+
return ax, ay
25+
26+
def simular(self):
27+
raise NotImplementedError("Método simular debe ser implementado en subclases")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from .SimuladorBase import SimuladorBase
2+
3+
4+
class VerletSimulador(SimuladorBase):
5+
def simular(self):
6+
t = 0
7+
while t < self.t_total:
8+
ax, ay = self.calcular_aceleracion(self.x, self.y)
9+
10+
# Actualizar posiciones
11+
x_nuevo = self.x + self.vx * self.dt + 0.5 * ax * self.dt**2
12+
y_nuevo = self.y + self.vy * self.dt + 0.5 * ay * self.dt**2
13+
14+
# Calcular nueva aceleración
15+
ax_nuevo, ay_nuevo = self.calcular_aceleracion(x_nuevo, y_nuevo)
16+
17+
# Actualizar velocidades
18+
self.vx += 0.5 * (ax + ax_nuevo) * self.dt
19+
self.vy += 0.5 * (ay + ay_nuevo) * self.dt
20+
21+
self.x = x_nuevo
22+
self.y = y_nuevo
23+
self.x_vals.append(self.x)
24+
self.y_vals.append(self.y)
25+
t += self.dt
Binary file not shown.
Binary file not shown.
Binary file not shown.

Simulación orbital/Notebooks/Complejidad.ipynb

Lines changed: 253 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)