How can I move the beginning of a parabolic shot to the right?

0

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.

    
asked by Julio Moreno Canul 08.10.2018 в 03:22
source

1 answer

0

Remember it as vectors.

You need 2 distances in this case, a distance for projectile 1, which starts at 0 and a distance for projectile 2 that starts at "d" (which is the distance that separates them) and decreases with the displacement proper to the projectile (d2 = d-vx2 * t)

This makes it easier for you, for example, at time 0, projectile 1 is located at 0 and projectile 2 is located at 20 -for example- then at those time increments, for example 5s later, the projectile 1 with a velocity = v1 angle alpha = alpha and a time t = 5s is moved 5mts (it is an example taking only the displacement), it is located in d1 = 5 ... likewise the projectile 2 with a velocity = v2 angle theta = Theta and time t = 5s moves 6mts ie this at a point d2 = 20 - 6 = 14 and at t = 6 d2 = 20 - 7 = 13 and successively, Thus forces the displacement vector to go back starting from the point that separates them.

And then you evaluate when d1 = d2 what happens, that is, if the h are the same they collide, if they are different, one goes up and so, I do not go into this because you only asked for the positions.

I hope you understand me and serve you, Regards.

    
answered by 08.10.2018 в 03:47