I am a beginner in C ++ and I have a doubt. They left us a shock exercise between parabolic projectiles, Instructions:
Create a program where there are 2 cannons, one is fired at an initial velocity v1 and a theta angle, another is fired at an initial velocity v2 and alpha angle. the 2 guns are separated by a distance d. all data is given by the user.
The projectiles are squares of 10 cm in increments of time of 0.001 seconds, say:
at what time they collide, at what time one passes on top of the other or if projectiles are never hit.
I just want to know how I could move the second shot so that it starts from the end of the distance and the calculation can be made. I enclose what I have:
#include "pch.h"
#include <iostream>
#include <math.h>
using namespace std;
const float gravedad = -9.81;
const float Pi = 3.14159;
int main() {
float t = 0, Vix1, Vix2, Viy1, Viy2, h1 = 0, h2 = 0, DistanciaP;
int v1, v2, alfa, teta, d;
cout << "Dame la velocidad del canion 1\n";
cin >> v1;
cout << "Dame el angulo del canion 1\n";
cin >> alfa;
cout << "Dame la velocidad del canion 2\n";
cin >> v2;
cout << "Dame el angulo del canion 2\n";
cin >> teta;
cout << "Dame la distancia que los separa\n";
cin >> d;
teta = 180 - teta;
Vix1 = v1 * cos(alfa * Pi / 180);
Vix2 = v2 * cos(teta * Pi / 180);
Viy1 = v1 * sin(alfa * Pi / 180);
Viy2 = v2 * sin(teta * Pi / 180);
do {
t = t + 0.001;
h1 = Viy1 * t + 0.5 * gravedad * pow(t, 2);
h2 = Viy2 * t + 0.5 * gravedad * pow(t, 2);
DistanciaP = d - ((v1 * t) + (v2 * t));
} while (DistanciaP > 0);
system("pause");
return 0;
}
I only have 2 hours to deliver the work, I hope one of you can solve my doubt.