Skip to main content
GameDev.net gamedev.net
🔒 Locked

Basic Kinematics confusion

Started by Knuckler Jun 28, 2008 at 1:41 PM 2 replies 750+ views
Original Post
Knuckler
Knuckler
I tried to write a program to test my knowledge of kinematics. It does what I wanted it to do (somewhat), but the way it's implemented makes me wonder if I have the idea of kinematics down. What I was trying to do was have a single particle simulate the water of fountain. It has a initial velocity, it goes up for a while, then comes down due to gravity. I used the formula x = v0xt + (axt^2)/2 y = v0yt + (ayt^2)/2 I was under the impression that x and y in formula was "displacement" and I could "+=" (C++) the value to my game object's position. Doing this resulted int the particle shooting off the screen. If I just use "=", then I get the correct results, but that means my object can't have a initial position. I would post some code, but I'm at work at the moment.
rufus74
rufus74
your equation is correct, don't use the += !
if you want an initial position, just use the full formula:

x = v0xt + (axt^2)/2 + x0
y = v0yt + (ayt^2)/2 + y0

cheers.
Knuckler
Knuckler
Sorry for the double post.

And thank you. I wasn't sure if I was going about it the right way.
johnstanp
johnstanp
There's a way to use the "+=" operator. It's simply less "efficient" and requires one more variable( actually, no... ) and more computing( actually one addition per equation )

So, computing x(t+dt) yields:

x(t+dt) = vox.(t+dt) + (ax.(t+dt)^2)/2
<=> x(t+dt) = vox.t + vox.dt + (ax.t^2)/2 + ax(t.dt+(dt^2)/2)

=> x(t+dt) - x(t) = vox.dt + ax.t.dt + (ax.dt^2)/2
<=> x(t+dt) = x(t) + vox.t + ax.t.dt + (ax.dt^2)/2

or using operator+=

x += vox.dt + ax.t.dt + (ax.dt^2)/2
<=> x += vox.dt + ax.dt( t + dt/2 )
<=> x += ( vox + ax( t + dt/2 ) )dt

You'll need the initial position only once.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.