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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

projectile simulation 2

Status
Not open for further replies.

Oak

Programmer
Aug 6, 2000
77
CA
Hi,

I am working on a project that requires projectile simulation. I've searched a lot on the internet but i'm still out of the way because it requires a lot of mathematical knowledge.

I want to build a game about two artillery batteries firering at each other. A classic, but a case of headhack. Fires should be like parabolic motions that, at least, seem real.

I've founded something about the Euler's method. It looks good but pretty hard to include within a project.

Anybody knows somethong about projectile simulation?

Thanks,
Oak
 
Use vectors

Start with a veritcal and horizontal vector.
The horizontal vector will not change. Now you know that gravity on earth is 9.8 meters per second. So:

SCREEN 12
horzvector% = 10
vertvector% = -35
x% = 10
y% = 10
DO
x% = x% + horzvecotr%
y% = y% + vertvector
vertvector% = vertvector% + 10
PSET (x%, y%)
SLEEP 1
LOOP UNTIL y% =< 0

This will map the exact positions of a projectile fires at 10m/s horizontally and 35m/s vertically.
 
Thanks. That's pretty amazing how simple it is. It solved a part of my problem.

I suppose that I have to set those vectors now. I try to set the projectile tragectory upon angle and velocity. Is there a way to set those vectors base on angle and velocity?
I'm poor in maths :(
 
Its simple trig.

First take the sine of the angle (in radians) then divide it by the velocity to get the vertical vector.
Then take the cosine of the angle and divide it by the velocity to get the horizontal vector.

horzvector% = (SIN(angle))\velocity
vertvector% = (COS(angle))\velocity
 
Close...

But, wouldn't you multiply it by the velosity? ;-)

Also, if the angle is from horizon, where 0 degrees is east, you need to flip you Sin & Cos...

If
X = Cos(a)
and
Y = Sin(a)
- or -
Y = Sin(-a)

*Note: due to the fact that QBasic graphics exist in the 4th quadrant, where (0,0) is at the top-left of the screen...
If you want to have ccw (normal) rotation as the degree increases, you can replace Y = Sin(a) with Y = Sin(-a) , assuming that the (a) and/or (-a) is converted to radians before it is plugged into the Sin function.


X and Y become the 2 legs of a right trianle where the hypotenuse is always equal to 1 (in a perfect world ;-))

45 degree angle will result in a vector 1 unit in the direction of 45 degrees

using the rules of SCALING...

you MULTIPLY X and Y by the length to set the hypotenuse which is the distance in the given direction...

so if you want to project an object 45 degrees as 10 m/s

'Set the Rad Constant (to in crease speed of calculations)
'Rad = 3.14159265# / 180
Const Rad = 0.01745329#

Ang = 45 * Rad
Vel = 10
DX = Cos(Ang) * Vel
DY = Sin(Ang) * Vel


See the image I created below for more details...
mysincos.JPG


Good Luck,
- Josh S -

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif

 
thanks a lot for both of you. it helped me a lot :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top