7.Integrated Knowledge: changing acceleration to speed and speed to distance — an example of integra
2012-08-01 11:00
573 查看
This post is about acceleration, speed and distance, or: a little calculus.
In our last post, we dealt with speed and acceleration. There is a strong relation between these two things, and distance:
Distance: the amount travelled over time.
Speed: the rate at whichdistance increases over time.
Acceleration: the rate at whichspeed increases over time.
It can often be useful to change between the different levels on this scale. Moving downwards (distance->speed->acceleration) can be done with differentiation and moving upwards (acceleration->speed->distance) can be done with
integration. Together these two things make up most of calculus. Calculus has achieved a reputation of being one of the most difficult areas of maths, but this post will try to convince you otherwise, by looking at the principles of integration. (Technical
note: integration operates on a continuous scale, and what I’m doing here is actually summation ofdiscrete series, but it’s close enough to explain the gist.)
first frame the speed was 0.4, on the second frame it was 0.8, on the third frame it was 1.2, on the fourth frame it was 1.6 and so on. It doesn’t take a genius to see that if we call the frame number t (for time), the speed on any given frame is
.
That’s the principle behind the simplest form of integration: if acceleration is some constant acc, then the speed after a given time t is
.
Note that this is not specific to acceleration: if, instead, speed is some constant speed, then distance after a given time t is
.
This generalises to any other situation: if you have something that changes at a constant rate (read that carefully!), the value at any given time is the starting value, plus the constant change multiplied by the given time.
The complications in integration come when you inevitably need to integrate something more complicated than a constant. Let’s return to our example of having acceleration 0.4, which means a speed of
(0.4, 0.8, 1.2, 1.6 etc as the frames progress). So the distance travelled on the 0th frame is 0, the distance is 0.4 on the first frame, then 1.2 (0.4+0.8), then 2.4 (1.2+1.2), then 4.0 (2.4+1.6). To avoid making this blog post humongous, I’m going to skip
the explanation, and just tell you that the pattern here is that if speed is
(where acc is constant),
then distance travelled is
(so for the apple:
).
You can verify this by feeding in values of t and checked it against the distance values I mentioned earlier in the paragraph. (Technical note: this is the rule for a discrete series, the rule for continous data is different.)
could get a good idea of the different falling behaviours, without either apple having travelled faster than the other. I got the apples to arrive at the same time, not by guess-work or trial and error, but by using these calculations.
The green apple on the left-hand side was easy. Both apples started 500 pixels above the bottom of the world, so they had 500 pixels to travel. The green apple fell at 10 pixels per frame, so it would take
frames to reach the bottom.
The red apple was accelerating at a rate that I could then choose. We’ve already seen that a constant acceleration means that distance travelled is
.
We know that t here must be 50, because we are interested in the distance travelled after 50 frames (when the green apple will hit the bottom), and we know that we want the red apple to have travelled 500 pixels after 50 frames, to match the green apple,
giving us this equation:
Working through a couple of steps:
The right hand side comes out to 0.392 (to 3dp), but I decided that 0.4 was close enough for our purposes. So by making the red apple accelerate at 0.4, I made it reach the bottom of the screen at about the same time as the green
apple.
In our last post, we dealt with speed and acceleration. There is a strong relation between these two things, and distance:
Distance: the amount travelled over time.
Speed: the rate at whichdistance increases over time.
Acceleration: the rate at whichspeed increases over time.
It can often be useful to change between the different levels on this scale. Moving downwards (distance->speed->acceleration) can be done with differentiation and moving upwards (acceleration->speed->distance) can be done with
integration. Together these two things make up most of calculus. Calculus has achieved a reputation of being one of the most difficult areas of maths, but this post will try to convince you otherwise, by looking at the principles of integration. (Technical
note: integration operates on a continuous scale, and what I’m doing here is actually summation ofdiscrete series, but it’s close enough to explain the gist.)
Basic Integration
Our example last time had an apple which accelerated downwards under gravity. The acceleration was 0.4 each frame. The speed to begin with (the 0th frame, if you like) was 0. Each frame, we added on the acceleration, so on thefirst frame the speed was 0.4, on the second frame it was 0.8, on the third frame it was 1.2, on the fourth frame it was 1.6 and so on. It doesn’t take a genius to see that if we call the frame number t (for time), the speed on any given frame is
.
That’s the principle behind the simplest form of integration: if acceleration is some constant acc, then the speed after a given time t is
.
Note that this is not specific to acceleration: if, instead, speed is some constant speed, then distance after a given time t is
.
This generalises to any other situation: if you have something that changes at a constant rate (read that carefully!), the value at any given time is the starting value, plus the constant change multiplied by the given time.
The complications in integration come when you inevitably need to integrate something more complicated than a constant. Let’s return to our example of having acceleration 0.4, which means a speed of
(0.4, 0.8, 1.2, 1.6 etc as the frames progress). So the distance travelled on the 0th frame is 0, the distance is 0.4 on the first frame, then 1.2 (0.4+0.8), then 2.4 (1.2+1.2), then 4.0 (2.4+1.6). To avoid making this blog post humongous, I’m going to skip
the explanation, and just tell you that the pattern here is that if speed is
(where acc is constant),
then distance travelled is
(so for the apple:
).
You can verify this by feeding in values of t and checked it against the distance values I mentioned earlier in the paragraph. (Technical note: this is the rule for a discrete series, the rule for continous data is different.)
Meet You at the Bottom
Let’s look at an example of actually using this. Did you notice in the previous post with the apples, thatthe apples started at the same place, and arrived at the bottom at the same time? I wanted that to happen, so that youcould get a good idea of the different falling behaviours, without either apple having travelled faster than the other. I got the apples to arrive at the same time, not by guess-work or trial and error, but by using these calculations.
The green apple on the left-hand side was easy. Both apples started 500 pixels above the bottom of the world, so they had 500 pixels to travel. The green apple fell at 10 pixels per frame, so it would take
frames to reach the bottom.
The red apple was accelerating at a rate that I could then choose. We’ve already seen that a constant acceleration means that distance travelled is
.
We know that t here must be 50, because we are interested in the distance travelled after 50 frames (when the green apple will hit the bottom), and we know that we want the red apple to have travelled 500 pixels after 50 frames, to match the green apple,
giving us this equation:
Working through a couple of steps:
The right hand side comes out to 0.392 (to 3dp), but I decided that 0.4 was close enough for our purposes. So by making the red apple accelerate at 0.4, I made it reach the bottom of the screen at about the same time as the green
apple.
相关文章推荐
- An Example of Pre-Query and Post-Query Triggers in Oracle Forms With Using Display_Item to Highlight Dynamically
- Given two strings s and t, write a function to determine if t is an anagram of s.
- An Introduction to Language Processing with Perl and Prolog: An Outline of Theories, Implementation,
- An Extensive Examination of LINQ: Querying and Searching XML Documents Using LINQ to XML
- An example of using libexif to set JPEG Orientation Tag
- 【HTTP】Speed and Mobility: An Approach for HTTP 2.0 to Make Mobile Apps and the Web Faster
- Linux change the speed and duplex settings of an Ethernet card
- How to get Full Rom Dump / Stock ROM of MT6572 MediaTek Smartphones using SPFT and MTK Droid Root an
- How To Build Multi-control Components when Inheriting from an Existing Control (Intro and TextBox Example)
- Scene is unreachable due to lack of entry points and does not have an identifier for runtime access
- An example of delegate Command to yet another Command.
- An example of Integrating Spark and Cassandra
- Minds and Computers: An Introduction to the Philosophy of Artificial Intelligence
- How to use Fiddler and HTTP replay to have an offline copy of your site
- Question 12: In C++, which of the following is the best declaration for an overloaded operator[] to allow read-only access (and
- An instance of “(null)” is already running. Choose “Stop” to terminate and launch a new instance.
- 警告: Scene is unreachable due to lack of entry points and does not have an identifier for runtime acc
- Allow user to scroll and maintain position with "Scroll To Bottom of the Div" example
- An example of how to do a simulation by LAMMPS