×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

projectile simulation
2

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

RE: projectile simulation

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.

RE: projectile simulation

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

RE: projectile simulation

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

RE: projectile simulation

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...


Good Luck,
- Josh S -

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

http://cubee.topcities.com

RE: projectile simulation

my mistake, yes multiply by velocity

RE: projectile simulation

(OP)
thanks a lot for both of you. it helped me a lot :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close