Skip to content
Snippets Groups Projects
Commit c2a18729 authored by Nicolas Mantilla Molina's avatar Nicolas Mantilla Molina
Browse files

Parcial 2 - Parte 1 - Sim. Movimiento Parabólico

parent 7b7169a7
No related branches found
No related tags found
No related merge requests found
// Incluimos los headers necesarios
#include <iostream>
#include <vector>
#include <cmath>
#include <fstream>
using namespace std;
int main()
{
cout << "Bienvenido al simulador de movimiento parabólico para el todopoderoso parcial de Algoritmos y Arquetipos." << endl;
// Definimos la aceleración por gravedad
double g = 9.8; //[m/s^2]
const double pi = 3.14159265359;
// Ingresamos los valores iniciales de velocidad, posición y ángulo
double v_0, theta, x_0, y_0; //[m/s], [°], [m], [m], respectivamente
cout << "Ingrese el valor de la magnitud de velocidad inicial en m/s^2: ";
cin >> v_0;
cout << "Ingrese el valor del ángulo inicial en grados: ";
cin >> theta;
cout << "Ingrese el valor de posición horizontal inicial en metros: ";
cin >> x_0;
cout << "Ingrese el valor de posición vertical inicial: ";
cin >> y_0;
//Definimos el intervalo temporal sobre el que se hará la simulación
int n, lineas=0;
cout << "Defina la cantidad de intervalos a calcular: ";
cin >> n;
double t_0 = 0, t_f = (sqrt(pow(v_0*sin(theta*(pi/180)), 2)+(2*g*y_0))+v_0*sin(theta*(pi/180)))/g, dt = t_f/n;
//Inicializamos los cálculos
vector <double> tiempos, pos;
vector <vector <double>> posiciones;
tiempos.push_back(t_0);
posiciones.push_back({x_0, y_0});
double v_x = v_0*cos(theta*pi/180), v_y = v_0*sin(theta*pi/180), x = x_0, y = y_0, t = t_0 + dt;
while (t<=t_f)
{
v_y += - g*dt;
x += v_x*dt;
y += v_y*dt;
tiempos.push_back(t);
posiciones.push_back({x,y});
t += dt;
lineas += 1;
}
//Exportamos los datos para verificar su validez
cout << "Escribiendo " << lineas+1 << " registros...";
ofstream archivo;
archivo.open("MovimientoParabolicoC++.csv");
archivo << "t,x,y" << endl;
for (int i = 0; i < lineas; i++)
{
archivo << tiempos[i] << "," << posiciones[i][0] << "," << posiciones[i][1] << endl;
}
}
\ No newline at end of file
File added
This diff is collapsed.
t,x,y
0,0,5
0.0320457,0.453195,5.44313
0.0640915,0.90639,5.8762
0.0961372,1.35959,6.2992
0.128183,1.81278,6.71214
0.160229,2.26598,7.11502
0.192274,2.71917,7.50783
0.22432,3.17237,7.89058
0.256366,3.62556,8.26326
0.288412,4.07876,8.62588
0.320457,4.53195,8.97844
0.352503,4.98515,9.32093
0.384549,5.43834,9.65336
0.416594,5.89154,9.97572
0.44864,6.34473,10.288
0.480686,6.79793,10.5903
0.512732,7.25112,10.8824
0.544777,7.70432,11.1645
0.576823,8.15751,11.4366
0.608869,8.61071,11.6986
0.640915,9.0639,11.9505
0.67296,9.5171,12.1923
0.705006,9.97029,12.4241
0.737052,10.4235,12.6458
0.769097,10.8767,12.8575
0.801143,11.3299,13.0591
0.833189,11.7831,13.2506
0.865235,12.2363,13.4321
0.89728,12.6895,13.6035
0.929326,13.1427,13.7649
0.961372,13.5959,13.9161
0.993418,14.049,14.0574
1.02546,14.5022,14.1885
1.05751,14.9554,14.3096
1.08955,15.4086,14.4206
1.1216,15.8618,14.5216
1.15365,16.315,14.6125
1.18569,16.7682,14.6933
1.21774,17.2214,14.7641
1.24978,17.6746,14.8248
1.28183,18.1278,14.8754
1.31387,18.581,14.916
1.34592,19.0342,14.9465
1.37797,19.4874,14.9669
1.41001,19.9406,14.9773
1.44206,20.3938,14.9776
1.4741,20.847,14.9679
1.50615,21.3002,14.9481
1.53819,21.7534,14.9182
1.57024,22.2066,14.8783
1.60229,22.6598,14.8283
1.63433,23.1129,14.7682
1.66638,23.5661,14.6981
1.69842,24.0193,14.6179
1.73047,24.4725,14.5276
1.76251,24.9257,14.4273
1.79456,25.3789,14.3169
1.82661,25.8321,14.1965
1.85865,26.2853,14.066
1.8907,26.7385,13.9254
1.92274,27.1917,13.7748
1.95479,27.6449,13.6141
1.98684,28.0981,13.4433
2.01888,28.5513,13.2625
2.05093,29.0045,13.0716
2.08297,29.4577,12.8706
2.11502,29.9109,12.6596
2.14706,30.3641,12.4385
2.17911,30.8173,12.2074
2.21116,31.2705,11.9661
2.2432,31.7237,11.7149
2.27525,32.1768,11.4535
2.30729,32.63,11.1821
2.33934,33.0832,10.9006
2.37138,33.5364,10.6091
2.40343,33.9896,10.3075
2.43548,34.4428,9.99585
2.46752,34.896,9.67412
2.49957,35.3492,9.34233
2.53161,35.8024,9.00048
2.56366,36.2556,8.64856
2.5957,36.7088,8.28658
2.62775,37.162,7.91454
2.6598,37.6152,7.53243
2.69184,38.0684,7.14026
2.72389,38.5216,6.73802
2.75593,38.9748,6.32572
2.78798,39.428,5.90336
2.82002,39.8812,5.47093
2.85207,40.3344,5.02844
2.88412,40.7876,4.57588
2.91616,41.2407,4.11326
2.94821,41.6939,3.64058
2.98025,42.1471,3.15783
3.0123,42.6003,2.66502
3.04434,43.0535,2.16214
3.07639,43.5067,1.6492
3.10844,43.9599,1.1262
3.14048,44.4131,0.593131
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment