# Thread: Cannonball trajectory issue, I'm completely stumped!

1. ## Cannonball trajectory issue, I'm completely stumped!

I'm currently working on a program that, when a user inputs an angle and muzzle velocity, it outputs the trajectory the cannonball will go (This code does not take in to account wind, only gravity itself).

For some odd reason it just won't seem to work. Seeing as I'm using a different graphics class than most, I should probably mention the coordinates on my graph. X maximum is 2100, Y maximum is 2050, and the cannon is at 0,0 itself.

The big concern is I'm trying to only output points at every one second intervals, and doing the calculation 100 times per second to determine where that point goes. Unfortunately I'll only sometimes end up with no points other than (0,0), or the end point, nothing in between!

If you guys wouldn't mind giving me a hand that would be awesome:

for reference, dT is my delta time, which is 0.01.
Code:
```
#include "ccc_win.h"
#include <cmath>

int ccc_win_main()
{
const double G = 9.81;
const double dT = 0.01;
double anglealpha = 0;
double velocity = 0;
double Vx = 0;
double Vy = 0;
int x = 0;
double Px = 0;
double Py = 0;
double Pxnew = 0;
double Pynew = 0;
double Vynew = 0;

cwin.coord(0, 2050, 2100, 0);

anglealpha = anglealpha * (M_PI / 180);

Vx = velocity * cos(anglealpha);
Vy = velocity * sin(anglealpha);

cwin << Point(Px, Py);

while(Py > 0)
{
x = 0;

while(x <= 100)
{
Vynew = Vy - G * dT;
Vy = Vynew;
Pxnew = Px + Vx + dT;
Px = Pxnew;
Pynew = Py + Vynew * dT;
Py = Pynew;
x++;

}

cwin << Point(Pxnew, Pynew);

}

return 0;
}```

2. I have found one of my errors, it turns out Pxnew should be = Px+vx*dT, not +dT. However now I have a problem where my code will not output the very final point, which is saddening! It will do all other points perfectly (At least, I think so), and then not output the final point.