?
Solved

Physics with C (Scorched Earth, Worms Gorilla.bas style!)

Posted on 1998-09-15
2
Medium Priority
?
337 Views
Last Modified: 2008-01-16
Disclaimer: This really isan't a C question, but as there is
no Physics question group, i'm not going to get too fussed.

I need some tips on how to plot points like in the games mentiond above. If you are one that doesn't play games, i require some pseudo code to plot a 'bomb' that was fired
from a statonary 'battle tank', the code NEEDS to use
the math functions 'cos' and 'sin' and to take into account wind, gravity etc etc. This is not a uni project, just something i'm slowly working at in my spare time.

And before you ask...
Yes, i skipped Physics when i was young. :-|

Thanks,
Chris.
0
Comment
Question by:ccheek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
JYoungman earned 100 total points
ID: 1252738
The path of a projectile fired from a gun is parabolic in a uniform gravity field with no air resistance.  With air resistance, it's more closely elliptical (iirc not quite but this shouldn't bother you).

Suppose the muzzle velocity of the gun is V, at an angle "h" to the horizontal.

The horizontal speed (Vx) of the projectile will be V*cos(h) and the vertical (upward) speed (Vy) will be V*sin(h).

In every small time interval t, the vertical speed will change in a downward direction by an amount a*t where a is the acceleration due to gravity (9.81 meters per second squared near the surface of the Earth).  Neglecting air resistance, the horizontal speed will remain constant.  At the end of each time interval, the X coordinate will increase by Vx*t and the Y coodinate will increase by Vy*t.  Note that as the projectile finishes rising and starts to fall, Vy will become negative (denoting a change in direction).

This may be the form in which the program is best written, but the actual coordinates of the projectile at time t will be

X = X0 + (V * cos h) * t
Y = Y0 + (V * sin h) * t - a*t*t/2

[alternatively, Y = Y0 + t * (V * sin h - a * t/2)]

Where V is the initial muzzle velocity, (X0,Y0) is the initial position of the projectile (i.e. the gun's position), t is the current time, and a is the acceleration due to gravity (9.81 metres per second squared near the surface of the earth).  Some formulations say that a is (-9.81) and change the sign before the a in the formula to "+" instead of "-".

If you want to take into account the effect of air resistance, there is a decelerating component proportional to v-squared and a component proportional to v.  The former is much larger.  There's no point modelling the component proportional to just v if all you want is visual realism.

To take into account wind drag, add to the horizontal distance moved a small extra distance term proportional to the wind speed at each time step.  Not quite physically realistic, but good enough I expect.

0
 

Author Comment

by:ccheek
ID: 1252739
Thanks for providing an in depth answer JYoungman, i still have a couple of problems with
the program, but your answer has put me onto the right track so im awarding you the points.

Chris.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question