Random Motion


Here is (or will be when I write this page) a method of generating a slowly and randomly varying waveform. This can be used to drive the random motion of a boat bobbing up and down on the water, data for an ambient motion loop, and many other things, inside and outside of Second Life.

The general method is to start with a sequence of independent random numbers, such as provided by llFrand(). These will not be suitable themselves, as they jump around too fast.

Let the values be x1, x2, x3, …

Define a new sequence y1, y2, y3, … by the rule yn = a yn–1 + b xn. If a is very close to 1 and b is very close to 0, then yn will only vary a little from yn–1. This waveform, however, still has too much jumpiness.

Repeat the process, defining z1, z2, z3, … by the rule zn = c zn–1 + d yn, again choosing c close to 1 and d close to 0.

You can usefully do this a third time: wn = e wn–1 + f zn. Three of these smoothings is enough: if you plot a graph of these waveforms over time, the fourth smoothing looks no different from the third.

Then you need to choose the multipliers af to ensure that the amplitude of the waveform and the speed at which it changes meet your requirements. That involves some mathematics that I haven’t worked out yet. I just tuned them by hand.

The gondola that bobs gently up and down outside the Palazzo Bovolo uses six of these generators, one for each component of position and orientation.