Created
October 25, 2019 01:11
-
-
Save mrbitsdcf/0cfbe53ffca2a3c738069b0a0b90a2d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CONSTANTES | |
G = 6.67408 * 10**(-11) # Constante Universal de Gravitação | |
M = 5.972 * 10**(24) # Massa da Terra | |
# ---------------------------------------------------------------------------------------------------------------------------- | |
# VARIÁVEIS | |
# Obs.: Este programa utiliza um sistema de coordenadas cartesiano de duas dimensões, com a origem no centro da Terra | |
import math | |
# Espaço [m] | |
x = 6371000 + 408000 # Posição inicial na direção X | |
y = 0 # Posição inicial na direção Y | |
d = math.hypot(x, y) # Distância em módulo / Raio | |
# Velocidade [m/s] | |
vx = 0 # Velocidade inicial na direção X / Componente X da velocidade inicial | |
vy = 7.66 * 1000 # Velocidade inicial na direção Y / Componente Y da velocidade inicial | |
v = math.hypot(vx, vy) # Velocidade inicial resultante | |
# Aceleração [m/s²] | |
a = (G * M) / (d**2) # Aceleração Gravitacional (Lei da Gravitação Universal de Newton) | |
ax = a * math.cos(math.atan(y/x)) # Componente X da Aceleração Gravitacional | |
ay = a * math.sin(math.atan(y/x)) # Componente Y da Aceleração Gravitacional | |
# Outros | |
t = 60 # Intervalo de tempo entre um instante e outro [em segundos] | |
n = 84 # Número de iterações | |
p = 2 # Precisão numérica: número de casas decimais para espaço e velocidade | |
pa = 4 # Precisão numérica: número de casas decimais para aceleração | |
# ---------------------------------------------------------------------------------------------------------------------------- | |
# TÍTULO DA TABELA | |
print("t (s)".rjust(5)+ | |
"x (km)".rjust(15)+ | |
"y (km)".rjust(15)+ | |
"d (km)".rjust(15)+ | |
"vx (km/h)".rjust(15)+ | |
"vy (km/h)".rjust(15)+ | |
"ax (m/s²)".rjust(15)+ | |
"ay (m/s²)".rjust(15)+ | |
"a (m/s²)".rjust(15)) | |
# ---------------------------------------------------------------------------------------------------------------------------- | |
# VALORES INICIAIS | |
print(str(round(float(t*(0)),2)).rjust(5)+ | |
str(round(float(x * 0.001),2)).rjust(15)+ | |
str(round(float(y * 0.001),2)).rjust(15)+ | |
str(round(float(d * 0.001),2)).rjust(15)+ | |
str(round(float(vx * 3.6),2)).rjust(15)+ | |
str(round(float(vy * 3.6),2)).rjust(15)+ | |
str(round(float(ax),pa)).rjust(15)+ | |
str(round(float(ay),pa)).rjust(15)+ | |
str(round(float(a),pa)).rjust(15)) | |
# ---------------------------------------------------------------------------------------------------------------------------- | |
# ROTINA DE CÁLCULO | |
for i in range(n): | |
# Posição no espaço | |
x = x + vx * t + 0.5 * ax * t**2 | |
y = y + vy * t + 0.5 * ay * t**2 | |
d = math.hypot(x, y) | |
# Velocidade | |
vx = vx + ax * t | |
vy = vy + ay * t | |
# Aceleração | |
a = (G * M) / (d**2) | |
ax = a * math.cos(math.atan(y/x)) | |
ay = a * math.sin(math.atan(y/x)) | |
print(str(round(float(t*(i+1)),p)).rjust(5)+ | |
str(round(float(x * 0.001),p)).rjust(15)+ | |
str(round(float(y * 0.001),p)).rjust(15)+ | |
str(round(float(d * 0.001),p)).rjust(15)+ | |
str(round(float(vx * 3.6),p)).rjust(15)+ | |
str(round(float(vy * 3.6),p)).rjust(15)+ | |
str(round(float(ax),pa)).rjust(15)+ | |
str(round(float(ay),pa)).rjust(15)+ | |
str(round(float(a),pa)).rjust(15)) | |
# FIM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment