## Ripple algorithm?

### Ripple algorithm?

Quote:> : :    Now Im pondering algorithms to make ripples in water that are not
> : : unlike the the result of tossing a pepple into a still pond, or
> : : rain-drops falling into a puddle.

I've had an idea for a ripple engine, I've tried it in assembler
and it's got _troubles_!  I think it's just a small part of the
algorithm that's playing up.  Here's the idea:

Say you've got the 100x100 'ripples', you keep 3 tables, one for
the up/down displacement, one for the up/down velocity and one for
the up/down acceleration.  To make any single ripple oscillate
sinusoidally, you need to use Hookes little equation:
'F = kx'
where:
F = Force
x = extension (change in displacement)
k = spring constant

and Newton lends a hand too:
'F = ma'
F = Force
m = mass
a = acceleration

from these two we get ma = kx, which can be taken to a = kx if we
take 'm' to be a unit value.

General laws of motion (or whatever) will give:
'v = v + at'
'd = d + vt'
where:
v = velocity
a = acceleration
d = displacement
t = a constant value relating to change in time

I'll jump the gun a bit and shove this straight into a little
loop:

do  {
v = v + a;      //add on velocity(taking time t as 1)
d = d + v;      //add on displacement
a = a + kd;     //Do hookes shmoo
_PlotAPixelSomwhereWithColour(d);
}   while (U want to);

Hang on a minute ... hmm, that could be wrong ... this should do
it otherwise:

do  {
v = v + a;      //velocity
x = d;          //remember x for extension
d = d + v;      //displacement
x = x - d;      //x = old disp - new disp
a = a + kx;     //hookes
_PlotAPixelSomwhereWithColour(d);
}   while (U want to);

Right, as far as I remember that's the code to get on point
oscillating happily.  The actual ripple effect takes place by passing
the Force of the adjacent spring.  Consider this:

Here's my spring(spring const. k):

O       -   ^   ^
/       ^   |   ^
/       |   |   |--acceleration
/       |   |
/       |   |---velocity
/       |
/       |---displacement
/       |
/       V
O       -

And I want to transfer the energy in this spring to the next, the
best way to do this would be to say there was another spring beween
this and the next which is used to carry on the energy:

(join)
O------O
^   /      /
^   /      /
acc |   /      /
|   /      /
/      O    ^
/           | motion
/
/
O

Hmm, these diagrams don't make much sence do they?  :)
Anyway, for this I go back to Mr Hookes eqn.  F=kx, we can say
that the force exerted by that spring is proportional to it's
displacement.
As there will be 4 springs around the one in question, each
spring recieves F/4 of the centre one, as m is a unit value here, we
can say each springs new acceleration is a/4.  This value will appear
next in the main loop and be oscillated & passd on etc etc.
I think it's this bit that made my code go wierd.

Hope this makes some sense, it's totally ad-libbed so sorry for
If it's no use at all, hope it's at least inspiring!

Cheerio!
Alex

---------------
wE fEaR (HaNgE!          Don't blame me ... my brain did it.
---------------

### Ripple algorithm?

This may be a gross simplification of things, but couldn't you just
just define a "ripple" by:
z = a*cos(r-t)*0.5^(r/hd)*0.5^(t/hl)
Where z is the vertical displacement,a is the amplitude, t is the time,
hd is the "half distance" (i.e., z should halve every hd units), hl is the
halflife, and r is defined by ((x-h)^2+(y-k)^2)^0.5. You could then
just calculate this over a certain range of r, which moves further out
with time.I suppose you could multiply t by something to change
the speed at wich the ripple moves out. Adding more ripples would simply
involve creating new ripples with different a, h, and k values. For a
given (x, y), z would be the algebraic sum of the different ripples.
The only real problem here is that reflections aren't taken into
account, so it wouldn't accurately model ripples in a small space.
However, for large regions it should look fine.
Vince

----------------------------------------------------------------------
Flaming Carrot: "Come here and look in the window!"
Herbie: "GADZOOKS! Shakespeare is an AEROBICS INSTRUCTOR!!!"

Vince Tourangeau
Carleton University

ie. when a drop of water hits a bed of water and a ripple is sent through
the water-bed.