Comp Sci Having Problem Graphing a projectile motion into C++

AI Thread Summary
The discussion revolves around a user seeking help with graphing projectile motion in C++ using Microsoft Visual C++. Key points include the need to gather user inputs for initial velocity and angle, and to represent projectile positions using a 2D array. Suggestions include defining projectile variables using structures and employing basic physics equations to simulate motion. The importance of handling user input and ensuring the program can manage various scenarios is emphasized. Additionally, there are inquiries about implementing a graphical user interface (GUI) for the project.
Badboy
Messages
6
Reaction score
0
Hey. i am having a problem graphing a projectile motion into C++. At the moment I am using the program Microsoft Visual C++ at uni. i got a problem here that i can't 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 please help me i would be really appreciated. thank you.
 
Physics news on Phys.org
People is not going to help unless we can you what you've tried...
 
sorry, but i don't know how to start the prog. if u can help me please just to start i will do some progress and try to finish myself and then if I am having trouble i will post wat I've done and i will ask for the little problems that r occurring in my program. thanks for ur reply.
 
might help to post what knowledge you have ..
[0] from MFC
[1] from Math
[2] from PHysics
[3] from C/C++
 
yes sure. i got knowledge in phyics and maths as I am currently studying both at uni and some knowledge of C++.
 
Last edited:
what graphics package are you required to use?and does the input have to be GUI or command line?

assuming your working with windows(MSVC)
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 run your simulation.

Now implement by leaving out the GUI part first work with a defualt answer that you know the answer to.
 
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.
Advanced C++ users might use <vector> but since your new
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 traveling 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
Helpful
 
i still don't understand
how can we make the GUI on c++ ??
 

Similar threads

Replies
25
Views
4K
Replies
17
Views
3K
Replies
8
Views
2K
Replies
12
Views
2K
Replies
3
Views
1K
Back
Top