# FFT Water - Maths confusion!

This topic is 5475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, I'm currently trying to implement the first part (FFT) of this article for a water surface (a 16x16 grid of points): http://www.gamasutra.com/gdce/2001/jensen/jensen_01.htm I just can't seem to get my head around the math, and it doesn't help that it's really hard to see some of the small text in certain formulas. Has anyone managed to get a working version of this up and running? If so, i'd really appreciate some help. If anyone is able to translate what exactly you are supposed to do with the formulas into some nice pseudocode that would be awesome! I just can't figure out how to use it to give me the correct height values I can plug in to my grid.

##### Share on other sites
I guess i'll expand a bit on the problem then:

Firstly, in the first formula, can anyone make out what the end part says?

I think it might be e^(iK - X)....? If so, what does the small 'i' in front of the 'K' signify? Can't seem to find that out.

The small 'i' also appears in the fourth formula with no explanation, and then again in the 7th formula.. what does it mean?

That's just the start of the problem, but getting that part worked figured out should help me get further.

##### Share on other sites
Yep, it's an i. i is the iteration number, so if the sum goes from 0 to K, each iteration will have i equal to 0,1,2,3,...,K

##### Share on other sites
That's a start! Thanks!

##### Share on other sites
Hi,

sorry to correct you but i is not the iteration variable. The i is a the complex i, since the k is under the sum, k is the iteration variable.
So look up Fourie Transformations (FT).
Sorry for my bad english but it'n not my motherlanguage.

##### Share on other sites
Oops, you're absolutely right dragongame. That'll teach me for only glancing at it quickly.

##### Share on other sites
yes
e^(i*theta) = cos(theta) + i * sin(theta)

i^2 = i*i = -1 (yes !!)

its all about complex numbers. You should see that in high school i think. (In france, we see it when we are about 16/17 year old)

neyna

##### Share on other sites
Sorry was me last poster.

hope i helped u.

neyna

##### Share on other sites
Getting somewhere now, thanks for the additional input guys. Still not sure i'm ever gonna get my head around this. Has anyone out there managed to implement this and would like to offer advice?

##### Share on other sites
well, as i don't have enough time, i just quickly go thru some important points.

Firstly, calculate Ph(K), using the fifth formula. this is pretty straight forward.(the Philips spectrum)

Secondly, calculate h0, which is the amplitudes and phases at time zero, by using the result from above step and the 7th formula.( or u can simply use ordinary noise for it) And remeber h0 is a complex number.

the 1st and 2nd steps are done in preprocessing stage.

Thirdly, in the runtime, u calculate the ~h(K, t).(formula 8). Here the e term is not e^(iK - X), it should be e^(i * dot(K,X))
dot stands for dot product.

Then the ~h(K,t) will be applied to the 1st formula. There are sth need to be mentioned that for the 1st formula, u can actually simplify the e term to just 1.

K = (2*PI*n/s, 2*PI*m/s), X = (n*s/r, m*s/r)
so dot(K, X) = (2*PI*n^2/r) + (2*PI*m^2/r) ------(1)
substitute (1) into the e term in the 1st formula, and using some formulas, the e term will be turned into 1.( The key is PI and 2*n^2/r, as e^(i*PI) = -1, so the whole e term can be
-1^(2*(n^2 + m^2)/r) = -1^((2n^2 + 2m^2)/ -1^r) = 1, since r is power of 2, and 2n^2 + 2m^2 is always even.

so, finally the 1st formula becomes h(X, t) = SUM_K ~h(K,t)

Lastly, u use FFTW or whatever to get h(X, t)[still complex number], and the real part of it is the height value u long for. :D

[Edited by - wanzi on September 22, 2004 5:36:24 PM]

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 16
• 13
• 14