# Having Problem Graphing a projectile motion into C++

1. Apr 26, 2007

Hey. i am having a problem graphing a projectile motion into C++. At the moment im using the program Microsoft Visual C++ at uni. i got a problem here that i cant even start to solve. Well the problem asks me to to ask the user to enter the intial velocity and the angle at which the projectile is leaving and then to sketch the projectile on the screen. it also says that i have to use 2D arrays that will represent the projectile position on the screen, similar to a sin wave. if u can plz help me i would be really appreciated. thank you.

2. Apr 27, 2007

### KTC

People is not going to help unless we can you what you've tried...

3. Apr 27, 2007

sorry, but i dont know how to start the prog. if u can help me plz just to start i will do some progress and try to finish myself and then if im having trouble i will post wat ive done and i will ask for the little problems that r occuring in my program. thanx for ur reply.

4. Apr 27, 2007

### neurocomp2003

might help to post what knowledge you have ..
[0] from MFC
[1] from Math
[2] from PHysics
[3] from C/C++

5. Apr 27, 2007

yes sure. i got knowledge in phyics and maths as im currently studying both at uni and some knowledge of C++.

Last edited: Apr 27, 2007
6. Apr 27, 2007

### neurocomp2003

what graphics package are you required to use?and does the input have to be GUI or command line?

graphics packages: Opengl w/ SDL, Opengl w/glut , MFC, windows API GDI.

command line: use opengl w/glut
GUI: MFC

as for the actual input/output ...

Write on PAPER:

what are your projectile variables: define them in C++ use struct/class where possible.

what are your equations inline or write them as functions with the correct input/output

The 2D array will be a vector of 2D positions. so allocate the 2D array.

Now implement by leaving out the GUI part first work with a defualt answer that you know the answer to.

7. May 3, 2007

Your working on a simulation of a projectile in C++

Hi

The projectile can be solved by using maths formulas or
it can be simulated with simplified maths formulas.

The simulation requires inputs
The initial velocity vector is given with speed and direction (angle)
you resolve the vector along the x and y (height) directions to
start a simulation. High school maths or physics Sin and Cos functions
are involved.

You need to create/store values into a simulation array.
The best way to do that is to have an array of structures.
to the whole concept of C++ ... build your structure like this

struct projectile {
float displacementx,
displacementy,
velocityx,
velocityy;
} myprojectile[64000];

This should then be initialized with your first bits of data
derived from the initial conditions or parameters provided by
the user.

myprojectile[0].displacementx = 0;
myprojectile[0].displacementy = 0;
myprojectile[0].velocityx = .... ; // resolved in the x direction
myprojectile[0].velocityy = .....; // resolved in the y direction

Then you need a loop construct that continues to update
myprjectile. stuff for i = 1 to somevalue based on a condition.
The condition will be true until the projectile hits ground zero.

The time defined by the user for the simulation interval probably has
to be less than 1 second in most normal cases however ...
you still need to use the simulation interval for calculating any new
vales that stuffed into your myprojectile array.

Now you have your data in an array of structures.
You now have to select the ones you wish to plot.
Your assignment is every 1 second. so if the flight time is
16 seconds -- you get 16 values.

What happens if the projectile takes 20 minutes to fly?
What if the user inputs all sorts of funny ha ha input?
make sure you handle things well enough to stop people
from entering things that do not make sense.

Once you have a large array of data
the initial data updated for a simulation interval is deposited into the
next array slot. The x data for velocity is simple just copy it.
the x data for displacement is simple just add the extra distance
covered by the projectile travelling at a velocity (resolved in the x direction)
the y values displacement and velocity are going to change a lot.
the velocity will diminish but the displacement will climb - so to speak.
the climb rate will diminish as gravity affects the velocity and hence the
distance.

march through the simulation until you have the projectile hit the ground
again.

The data has to be sampled before you can plot it. So a second array is
probably required unless you can do the plotting directly from the raw data.

So you then get to do a character plot. Nothing fancy there but remember
to initialize the subset of data to be cout 'd with blank characters
and then update that subset array with a '@' or '*' character using 1 second
data.
Then when plotting the data may be shown upside down. Thats because you forgot to plot the last row first.

Scaling the data is a *****. Some values will scale down to the same thing.
set up a 24 or 25 by 80 display array and work out what you have to do to scale it into that array.

Kind Regards