Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP/DBC] Timer based integration function!

Author
Message
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 5th Aug 2008 20:00
After a lot of reading on wikipedia I finally came up with this equation.

If you have an acceleration over a certain amount of time, starting at a certain velocity, it will calculate the distance travelled in that time-step.

Code:


This example program shows that however long each time-step is, as long as the total time is the same it will always return the same distance travelled.

Normally, people use this equation:
distance# = velocity#*time_step#
velocity# = acceleration#*time_step#

However, surprisingly that will give different results with a higher or lower frame-rate! This is because it only approximates the velocity/time graph.

In a velocity/time graph, the area under the line is the distance travelled.

This graph shows how the area is calculated in the normal equation:


And for the same equation on a slower computer:


The green area is what is added up to get the distance, and it is different on different speeds of computer.
My equation calculates it exactly for the whole area under the curve, and so does not change with the frame-rate!

Yuor signutare was aresed by a deslyxic mud...
Curious? CLICK HERE!
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 8th Aug 2008 01:08
it seams very intresting
something i never would think of
cheers
calcyman
16
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 14th Aug 2008 15:14
A useful function. Does that only work for constant acceleration, or could it simulate Simple Harmonic Motion?

The optomist's right, The pessimist's right.
Alfa x
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location: Colombia
Posted: 15th Sep 2008 23:40
hi,
thanks for the tip.

I think darkcoder said something about timers in one of his threads,
something about a more accurate timer than the timer function.

Login to post a reply

Server time is: 2024-05-05 07:18:16
Your offset time is: 2024-05-05 07:18:16