Having Problem Graphing a projectile motion into C++

Click For Summary

Discussion Overview

The discussion revolves around the challenges of graphing projectile motion in C++ using Microsoft Visual C++. Participants explore how to implement user input for initial velocity and angle, represent projectile positions using 2D arrays, and sketch the projectile's trajectory on the screen.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant expresses difficulty in starting the program and requests initial guidance to make progress.
  • Another participant suggests that sharing prior attempts would facilitate better assistance.
  • A participant asks about the required graphics package and whether the input should be GUI or command line, listing potential graphics options.
  • Suggestions are made to define projectile variables in C++ using structures or classes and to write equations as functions.
  • There is a proposal to create an array of structures to store projectile data, including displacement and velocity components.
  • One participant emphasizes the importance of handling user input carefully to avoid nonsensical values.
  • Discussion includes considerations for scaling data for plotting and the potential need for a second array for sampled data.
  • A participant expresses confusion about creating a GUI in C++.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to implement the program, and multiple competing views on how to handle the graphical representation and data management remain evident.

Contextual Notes

Limitations include uncertainty about the specific graphics package requirements and the handling of various user inputs, which may affect the program's functionality.

Who May Find This Useful

Students and developers interested in programming simulations of projectile motion in C++ or those seeking to understand graphical representation in programming.

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 count '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
19
Views
3K
  • · Replies 25 ·
Replies
25
Views
5K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
15
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 1 ·
Replies
1
Views
11K