# Calculate UV sphere vertices (altitude)

There is an fantastic answer by DMGregory here where he explains how to calculate and generate the vertices of an UV Sphere: OpenGL calculate UV sphere vertices

Based on his code, how can we change the "altitude" of each individual vertex?

To create something like this:

• Hint: the secret is already in that answer. Look at the radius parameter. That determines the "altitude" from the center of the sphere. Vary that, and you get mountains and valleys. Can you show us how you've tried to vary the radius in your code so far? – DMGregory May 28 '20 at 23:15

## 1 Answer

As DMGregory said, I just had to vary the radius variable.

// You simply have to multiply radius by any kind of random value
// I'm using perlin noise in this example
positions[v] = vec3(
c * cos(theta),
sin(phi),
c * sin(theta)
) * radius * noiseValue(latitude, longitude)