Wow, this is a weird spot for this chapter, huh? Eh, whatever.
Calculus is *extremely* important to the study of physics. It's foundational to the subject. Unfortunately it's a large and long subject to teach, so we won't really be covering it. If you're interested in learning calculus, there's like a billion sites on the internet that will teach you it, go find one.
Instead, I'm going to be giving a break-neck overview of the important bits for us.
Let's recall the simulation loop we'll be working with:
loop for every instant of time { loop for every object { 1. force = ... 2. dvel = force / mass * dt 3. velocity += dvel 4. dpos = velocity * dt 5. position += dpos } time += dt }
There are 2 important constructs that are studied in calculus: the derivative and the integral. But we're only really going to be talking about integrals.
For us, integrals look like this:
Meaning, summing up, for every timestamp between time T1 and T2, the product of some quantity and the "d" form of some other quantity. The values are subscripted, meaning that, for each timestamp, we're using the quanties as they were *at that timestamp*, and then moving on to the next timestamp.
An example:
Here's another one, this time using "dforce". That isn't present in the loop above but it means the same thing, the change in force between each successive timestamp:
Another one, where I don't subscript dt because it's the same at every timestamp:
We've seen this last integral already, actually. This is just lines 4 and 5 of the simulation loop above! An object's position is just the sum of the velocity at each timestamp, times dt:
There are a few things to know about integrals.
The two integrals that are present in the simulation loop, the one for velocity and the one for position, they both *converge*. Every time you make dt smaller, the values of velocity and position "settle further into" their final value.
dt | position of left ball at t=3.0 |
dt = 1 | -2.875 |
dt = 1/4 | 0.011004274380613504 |
dt = 1/16 | 0.024260614298508315 |
dt = 1/32 | 0.024890049185773932 |
dt = 1/128 | 0.02508617623223446 |
dt = 1/512 | 0.0250984251867963 |
dt = 1/2048 | 0.025099190711406923 |
The other two integrals that I listed above as examples also converge. The conditions for convergence are a bit touchy, but here's the general idea:
There's some more subtlety to it, but this should be good enough for us. If you're interested in learning more, the subject is usually called "Real Analysis" or some variant of "Modern Calculus" in textbooks and college courses.
Another big thing to know about integrals is that they have something called "antiderivatives". Essentially, if an integral is convergent, the exists a function, that we'll call U here, that satisfies:
U here is called an antiderivative. What form exactly U takes is difficult to determine. A large part of a calculus course involves learning tricks to let you figure out what U is given the integrand and differential.
The weird arrow thing is trying to convey that the left-hand side will converge to the right-hand side as dt gets smaller.
One important thing for us to know is that the form that U takes depends ONLY on the choice of integrand and differential, NOT the choice of upper and lower bounds T1 and T2.
The other important property is best shown through an example. If, say, the differential is dvel, and the integrand is some expression involving ONLY velocity, then there exists a form of the antiderivative that can be expressed as the difference between a function evaluated at the velocity at the beginning and end timestamps. So as a concrete example:
I don't really want to get into why they're called antiderivatives.
An important interpretation of integrals is as describing the area under a graph:
The idea is that you can approximate the area under a graph with a bunch of thin rectangles and adding up their area, and it can be made more accurate by making the rectangles thinner. Again, if you don't get this, there are other places online that will teach you calculus.
The integral that we outlined above corresponds to the right-point formulation of the area under the graph. The integrand is the height of the graph at a particular timestamp, and the differential is the distance between that timestamp and the previous one.
Another thing you learn in a calculus class is that other formulations, like the midpoint or trapezoidal formulations, will also converge to the same value. Here's the left-point formulation:
This corresponds to the integral:
Something that's rarely taught in school is that it's perfectly fine to offset in the other direction:
Which corresponds to the integral:
I'm not sure if this one has a name. But we'll be using it in a couple lessons, so I guess I'll call this one the double-right-point formulation. It's sort of offset from the actual graph by a little bit, but as dt get smaller the difference converges to 0.
Changelog:
© by Daniel Taylor