Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2D Projectile Motion Program 1

Status
Not open for further replies.

Stainnd

Programmer
Joined
Jul 9, 2001
Messages
65
Location
US
I'm a junior in high school and we're studying 2d projectile motion right now in physics. Like, for example, a ball being shot out of a cannon. If the initial speed and angle are known, one can calculate the height(Y) and distance(x) of the projectile from the origin. Anyway, I decided to write a program that, when given the initial speed and angle of the projectile, would move the projectile across the screen much like it would in real life. I tried making a timer, and then every hundreth of a second, the timer would do the math, figure out where the ball should be at that given time, and then put it there. This didn't work however. I would really appreciate it if someone could help. Here are the formulas:

Initial Speed = v angle = a time = t

X = (V * Cos(a)) * t

Y = ((V * Sin(a)) * t) - (4.9 * t * t)

Please help me if you can.

-Mike -Mike
 
Does it matter what the measurement of time is? Minutes, seconds, milliseconds? What kind of values are normally in this- and then what is the measurement for the distance.

If I fire a projectile at 100 m.p.h. at 30 degrees- what kind of output do I get from these functions?

(obviously math is not my strong point but I am curious about this)
 
the only reason the measurement matters is that 4.9 refers to the speed of gravity divded by 2 in meters/sec. If you input 100 mph, then you would have to convert 9.8 meters/sec to miles per hour. If you set it to 100 meters/sec and 30 degrees...well you would have to know the time too. But lets say you wanted to know what the x and y values were at 2 sec, then you would do the math and get 173.205 meters travelled horizontally, and 80.4 meters travelled vertically. In visual basic terms...if the user entered 100 for speed and 30 for angle, after 2 seconds the ball would be at point 173.205 left, and the form's height - 80.4 meter top. The reason you subtract the vertical distance travelled from the form's height is because the highest "top" of a form in visual basic is actually the bottom for whatever reason. Anyway, I hope that helped
If not, i can try to explain it again...thanks for the help

-Mike -Mike
 
I wouldn't try doing it in real time. Do a calc, draw the position, wait a bit, do a calc etc. So you would have a loop continuously calculating with a delay in it. You can figure out the scaling easily cos you know the range and max height.
I did this stuff for a living for a bit, working on artillery trainers (not exactly my choice, all that was around at the time) and it gets very complicated. We had to take into account varying atmospheric pressure and temperature and wind with altitude. Peter Meachem
peter@accuflight.com
 
Within all of the above, I do not see where you strate the area you are having difficulty". You appear to have the math, and appear to be satisified with the simplistic / 'ideal' soloution, so I would GUESS that it is the screen display / graphics, that is the issue.

IF that is the case, I have some suggestions.

1)[tab]Do all of the (path) calcs as soon as the "problem is entered. Store the positions in an UDT array (Time, XPos, YPos, Angle, Speed / Momentum, ...). Make sure that all of hte info ou need for the remainder of the 'problem' is in the array for each time step.

2)[tab]As soon as the loop calculation of position is complete, DRAW the path on you image control. For this path, use a small contrast color (lt blue on dark blue, or yellow on white).

3)[tab]add a Horz. Scroll bar to the form. This will be used to show the "projectile" along the path. I would also add some text boxes / labels to give the "instaneous" or point data along the path. Show the UDT point values as selected / sselected by the scroll bar.

4)[tab]use the H. Scroll to "pick" the point (from the UDT array) and draw a highly contrasting filled circle on the image control -at the point selected.

If this is all put together, you should be able to use the h. Scroll Slider to "walk" the projectile across the path on the image control. You could also stop it at any point to "examine" the various attributes at the point. Finally, since all or the calcs are done, you could add a command button to simply do the sliding - at any desired "speed" by setting the H. Scroll position in a loop with a timer.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top