I have created a Grid: enter image description here

At each point along the grid, is a vertex (Intersection Points):

enter image description here

Each of these points has an x,y,z position. Vector3f(x,y,z). In an attempt to animate the grid into a group of ocean waves, I used this formula to adjust the y position of each “Vertex”:

enter image description here

This is my attempt at implementing the formula into java:

private float sineY(int x, int y, float time) {
Vector2f position = new Vector2f(x, y);        
float yPos = (float) ( (2 * amplitude) *Math.pow((Math.sin((wavenumber.dot(position))  + temporal_angular_freq * time +  initiatory_phase) + 1)/2, k));
    return yPos;

This function is running from inside a for loop that is updated every ms:

Time ++;
for (int y = 0; y < sizeY; y++) {
        for (int x = 0; x < sizeX; x++) {
            float xPos = x;
            float yPos = 0;
            float zPos = y;
            xPos += 0; 
            yPos += sineY(x,y,time); 
            zPos += 0;
            waterVertexPos.set(xPos, yPos, zPos); 
            vertBufArray[index++] = waterVertexPos.getX();
            vertBufArray[index++] = waterVertexPos.getY();
            vertBufArray[index++] = waterVertexPos.getZ();

As you can see, for each vertex, along the grid, the yPosition of the vertex is set to whatever value the sineY method returns, which is whatever the above formula returns. Running this code reults in this:

WHEN K = 1.0:

enter image description here

WHEN K = 1.5

enter image description here

As you can see, they both do not follow in accordance with this image here:

enter image description here

All the formulas and graphs have been retrieved from this pdf file. The aim of this program is to simulate water using the presented equations. The pdf is really interesting have a read if you like :)

Source: http://http.developer.nvidia.com/GPUGems/gpugems_ch01.html

Thank you VERY MUCH for all of your time :)


After implementing the fix suggested by msell. It fixed this previous issue, however a new issue arose when the waves peaks still do not look as they did in the above graph:

WHEN K = 2.0:

enter image description here

The pdf specifies:

A common complaint about waves generated by summing sine waves directly is that they have too much "roll," that real waves have sharper peaks and wider troughs. As it turns out, there is a simple variant of the sine function that quite controllably gives this effect. We offset our sine function to be nonnegative and raise it to an exponent k. The function and its partial derivative with respect to x are.

And then refers to the formula mentioned above, and another formula:

enter image description here

Is there something wrong with my implementation?

And again. I cannot thank you enough for your time :)

Sidney de Vries

  • 1
    \$\begingroup\$ There is no + 1 in your function after Math.sin. \$\endgroup\$
    – msell
    Feb 4, 2014 at 6:12
  • \$\begingroup\$ Make it the answer or something so i can Tick it as the answer :) Least i can do \$\endgroup\$
    – user41715
    Feb 4, 2014 at 6:18
  • \$\begingroup\$ Still an excellent question. \$\endgroup\$ Feb 4, 2014 at 10:44

1 Answer 1


You have incorrectly implemented the formula as a function. The function is missing + 1 after the call to Math.sin(), which moves the wave to the range [0, 2].

Regarding your second problem, I don't see anything wrong. In fact the screenshot looks exactly like it should and seems to match the plotted curve. Try with k=10 and you should see the difference clearly.

  • \$\begingroup\$ I've update the question. If no one answers my new issue, ill vote this as the answer and remove part two. \$\endgroup\$
    – user41715
    Feb 4, 2014 at 6:37

You must log in to answer this question.