## projectile simulation

## projectile simulation

(OP)

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

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

## RE: projectile simulation

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.

## RE: projectile simulation

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 :(

## RE: projectile simulation

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

## RE: projectile simulation

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 * RadVel = 10

DX = Cos(Ang) * Vel

DY = Sin(Ang) * Vel

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

Good Luck,

- Josh S -

Have Fun, Be Young... Code BASIC

-Josh

http://cubee.topcities.com

## RE: projectile simulation

## RE: projectile simulation