## Ripples

*This post is part of a course on geometric modeling at the Summer Liberal Arts Institute for Computer Science held at Carleton College in 2021.*

When you drop a rock in a lake, a ripple emanates from the point where the rock breaks the water’s surface. That ripple is up there on the list of most beautiful things found in nature, along with butterflies and naked mole rats. Let’s recreate one of those beautiful ripples in a 3D model.

This shape will have a lot in common with the terrain.

### Function

Add a function named `generateRipples`

. Have it accept the following parameters:

`nlatitudes`

, which is the number of lines of latitude.`nlongitudes`

, which is the number of lines of longitude.`width`

, which measures the horizontal span of the terrain.`height`

, which measures the vertical span of the terrain.`frequency`

, which controls how many ripples appear in the surface.`amplitude`

, which controls the height of the ripples.

Create your empty positions and triangles arrays. Return them in an object.

### Vertex Positions

Generate the positions of the grid with a structure much like you did in `generateTerrain`

. However, instead of setting the z-coordinates to random values, assign each a value that goes up and down based on how far the point is from the center of the surface, which is the origin.

The distance of a point from the origin is calculated using the Pythagorean theorem:

Plug this distance into the wave equation to determine the z-coordinate:

The reasonableness of your ripples will depend on the values that you send in for parameters. Try lots of different combinations values in order to find one that’s aesthetically pleasing.

### Triangles

The vertices connect up into triangles in the exact same was as the terrain. You can copy the code directly from that function into this one.

When you render the ripples as a solid, shaded surface, you should see waves undulating outward from the surface’s center.

## Leave a Reply