Interesting ways you've used integrals
I've been studying for a math exam right and the main thing I've learned is that integrals suck ass. They'd probably suck less ass if I knew more ways to apply them.
So the question is: have you some found cool applications for integrals?
So the question is: have you some found cool applications for integrals?
Comments
I seem to remember it being used quite a lot in lighting calculations... but that might be offline-rendering as opposed to games.
Check out the others while you're there, especially considering this seems to be one of your interests. They're not _all_ amazing (there are a couple of folks there that I think talked rubbish), but you can draw your own conclusions by comparing their answers to one another. ;)
http://www.youtube.com/user/opcode6?feature=watch
Understanding integrals (and calculus in general) and how they are computed are extremely useful for understanding many algorithms presented in irritatingly terse mathematical form that algorithm designers sometimes use. To give one example, the following is a blurring "algorithm":
F(x, y) = \int_{A(x, y)} a * f(x, y)
Here, f, is an image function, A(x, y) is a point set around (x, y),say a square, for example, and a is a normalising constant, equal to (1/ the area of the square), say.
In an actual application, you will of course not calculate the integral, but merely sum the pixel values in the square for each point.
So if you understand integrals, you have access to much more algorithms that other programmers won't understand.
----
Another useful application of integration comes up in control, which can be used for AI, for instance. (A "control system" is roughly a system that responds "sensibly" to noisy input). PID-control uses a combination of the input (P), the derivative of the input (D), and "integral" of the input (I) to work out its response. A simple example is a steering agent that calculates a steering angle (a) based on the angle turned away from the path (f) with this:
a(t) = A * f(t) + B * f'(t) + C* \int_{x=t - t0..t} f(x) dx //You may need another constant multiplied with everything to scale it and invert it)
where you tweak A, and B, and C based on the desired behaviour and characteristics of the input f. Roughly, the integration term serves as a windowed average, which tends to filter out noise (small bumps in the road). This leads to a delay in the response, which can be reduced by the derrivative term (it serves as a kind of prediction term - remember, it calculates the rate of change).
Mini#37 (Luma Arcade's first game ) used this kind of control for the AI vehicles. This is also useful to implement fast-moving hovercrafts physics, that I have done for another unreleased game at I-Imagine see http://code-spot.co.za/2010/07/27/a-simple-trick-for-moving-objects-in-a-physics-simulation/. Of course, you won't even know that integration is involved here if you don't understand the relationship between displacement, velocity, acceleration and force.
----
Integrarion is also common in AI and advanced statistics (often the same thing). For example, neural nets (PDF), and generating numbers for arbitrary distributions. (This article does not use the concept of integration explicitly, but again, if you know "accumulative probability" is the integral of the distribution function, it is a lot easier to understand).
----
Questions: What would f(t) look like?
What I can understand from that is: Wouldn't you divide both f(t) and f'(t) with F(t)? Also, is t time or position along path?
To see how these values relate to each together, you need to look at an actual implementation. Let's say we limit the window to 10 frames, and for simplicity I will assume a fixed frame rate. To calculate the integration term, we need to "remember" 10 frames of the offset, which I will store in an array. To limit needless copying, the array is used circularly, so each frame we advance the windowIndex, so that the last offset is always at that position in the array, and earlier values before that (wrapped around the array, so position "-1" is actually position 9).
So you see, it is a circular calculation: f(t) depends on (among other things), the forward vector of the agent, and that in turn depends on f(t).
When tweaking, a good way to start off is punching in the formulas in excel, with some test data, and plotting f. (Test data can include smooth curves, extreme curves, etc.).
----
For this application, you would not divide by F(t).
You do that though for "local normalisation" (in effect, scaling values so that different windows can be compared more accurately in certain applications. The only example that I can quickly think of is in image algorithms, where you compute things, and then divide them by the average intensity of the window to cancel out "broad scale" intensity variations, for example to detect edges. You can test this in Gimp: take an image, duplicate it in a new layer. On the bottom layer, run "Filter | Generic | Convolution Matrix" with the central 9 squares set to 1, and divisor 9 [this is a box blur, which adds all the pixels in a 3x3 window (integration) scaled by 1/9 to keep it in visible range]. Then set the top layer mode to "Divide"; the resulting image is the image divided by the (windowed-)integral of the image.
----
t is time, but the two values are obviously related. I may be wrong, but there is possibly an adaption of the algorithm to work on position along path instead, that may be useful...