Trajectory help :D
Author |
Message |
berrberr
|
Posted: Sun Oct 22, 2006 5:57 pm Post subject: Trajectory help :D |
|
|
Hello everyone. Im currently trying to come up with some formula in turing that will calulate and display the trajectory of an object being shot, given an angle an amount of power and the force of gravity. (Kinda like in pocket tnaks or gunbound I guess). Combining my suckyness in math and physics I havent gotten very far . Ive gotten as far as to tring to use a quadratic, but I dont think that that will work. Thanks for any help! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Ultrahex
|
Posted: Sun Oct 22, 2006 10:04 pm Post subject: (No subject) |
|
|
Its much easier if you seperate the X and Y components,
search up Projectile Motion Online For Physics Formulas,
This Will Probably Help-A-Lot
Basically
d=v1t+1/2at^2
for your y
v1 is equal to initial Vertical Speed
so if the angle is 40 at a power of 100 then v1 is 100*sin(40)
hope this helps a little -- Will Get Back to you tomorrow with better answer. |
|
|
|
|
|
Ultrahex
|
Posted: Mon Oct 23, 2006 3:01 pm Post subject: (No subject) |
|
|
Assuming No Friction!
dy= viy * t + 0.5gt^2
viy = intial vertical velocity
g = gravity (normally -9.8)
dy = distance travelled verticall (or vertical position at time)
t = current time
dx=vix * t
vix = intial horizontal velocity
dx = current horizontal position
t = current time
Use SOH CAH TOA To Get viy, and vix
vix = cos(angle) * power
viy = sin(angle) * power |
|
|
|
|
|
berrberr
|
Posted: Mon Oct 23, 2006 7:45 pm Post subject: (No subject) |
|
|
Ok well I understand the formulas (gr 11 physics ftw ) but what I really want to do is turn this forumla into a turing program. Basically I was the user to input the angle and power and then a shot will be fired in an arc fashion and it will be displayed on the screen. I get the forumulas and have some rough pseudocode but I cant figure out how to translate this into turing Thanks for the help |
|
|
|
|
|
do_pete
|
Posted: Tue Oct 24, 2006 9:45 am Post subject: (No subject) |
|
|
You don't really need physics. Something like this would do:
code: | const GRAVITY := -0.0001
var x, y, xSpeed, ySpeed : real := 0
xSpeed := 0.2
ySpeed := 0.2
loop
x += xSpeed
y += ySpeed
ySpeed += GRAVITY
Draw.FillOval (round (x), round (y), 1, 1, black)
end loop
|
|
|
|
|
|
|
[Gandalf]
|
Posted: Tue Oct 24, 2006 3:30 pm Post subject: (No subject) |
|
|
do_pete wrote: You don't really need physics.
Well, what if you want to specifically set the angle and force? Using simple x and y velocities you are basically going in a random direction hoping for a parabolic trajectory. If you add a bit of trigonometry in there you can precisely set the angle the object is going in, as well as some other stuff. Particularily useful in games, for one. |
|
|
|
|
|
berrberr
|
Posted: Tue Oct 24, 2006 4:49 pm Post subject: (No subject) |
|
|
do_pete wrote: You don't really need physics. Something like this would do:
code: | const GRAVITY := -0.0001
var x, y, xSpeed, ySpeed : real := 0
xSpeed := 0.2
ySpeed := 0.2
loop
x += xSpeed
y += ySpeed
ySpeed += GRAVITY
Draw.FillOval (round (x), round (y), 1, 1, black)
end loop
|
Thanks for the reply! The problem with that code is that the x and y Speed dont controll the speed at all but rather the hight and length of the curve. The code does make a ball travel in an arc and does factor in gravity, but it doesnt include angles and power which is what I am trying to add into the code. Any other ideas ? |
|
|
|
|
|
Cervantes
|
Posted: Tue Oct 24, 2006 5:36 pm Post subject: (No subject) |
|
|
This code will work fine with angles and power. You just need to convert your polar value (length and angle, corresponding to power and angle) into cartesian coordinates (representing x velocity and y velocity). To do that, you need simple grade ten trig. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
do_pete
|
Posted: Wed Oct 25, 2006 8:30 am Post subject: (No subject) |
|
|
Like so:
code: | const GRAVITY := -0.0001
const ANGLE := 10
var x, y, xSpeed, ySpeed : real := 0
xSpeed := cosd(ANGLE)/5
ySpeed := sind(ANGLE)/5
loop
x += xSpeed
y += ySpeed
ySpeed += GRAVITY
Draw.FillOval (round (x), round (y), 1, 1, black)
end loop
|
|
|
|
|
|
|
berrberr
|
Posted: Thu Oct 26, 2006 4:11 pm Post subject: (No subject) |
|
|
Thanks alot do_pete! Exactly what I wanted, and I understand it now. Thanks |
|
|
|
|
|
|
|