Advertisement

Help me understanding the diamond square algorithm

Started by January 22, 2018 10:13 AM
5 comments, last by alx119 6 years, 10 months ago

Hello,

I'm trying to implement in opencv The Diamond Square algorithm, but something is not working. I think I didn't understand exactly the algorithm.
https://en.wikipedia.org/wiki/Diamond-square_algorithm

1. When I initialize first the four corners, they must have the same color ? Or different ones ? In my algorithm they have different colors.
2. Then I calculate the midpoint of the square by averaging the square corners(The diamond step). So the midpoint will have a color...let's say red.
3. After this, the corners from the square step (the third image from the link) will be averaged and the value will be contained by the midpoint. But the midpoint will not be the same for the square and for the diamond ? So the final color will be that one from the square step ? What is the point by performing the diamond step ? I'm very confused to be honestly.

I tried to search on the internet, but I didn't understand from other websites. It would be nice if someone would explain more clearly, what the colors of the pixels would be.

Thank you!

The diamond-square algorithm is not about coloring but about height: It generates a height-map. I.e. it adds the 3rd (height) component in a semi-random fashion to a given 2D grid. You can, of course, do colorization by mapping height values into colors, but currently I don't see a meaning in "inheriting" color from the corners.

So, what exactly is the goal of your attempt? What are the colors you mentioned good for?

E.g., if you want to colorize the heigh-map like a terrain (white for snow on the mountains and such): Make a color ramp, take the resulting height of a grid point, normalize the height, and use the normalized height to address a color in the ramp. 

Advertisement

My goal is to create clouds, gases, or nebulas for skyboxes. And I don't want to use any softwares.  I would like to code them by myself. :P

For terrain a possible outline to start:

1) compute the height field
2) perhaps clamp heights below sea-level to the height of the sea-level
3) use a color ramp

For clouds a possible outline to start:

1) compute the height field
2) clamp the heights below "blue sky level" to that level
3) colorize the sky level to blue and blend other heights with a dark gray, using the blend factor proportional to the relative height

Nevertheless, I don't understand why to inherit colors from corners somehow. I think because the entire area is the first square, using inherited colors would ever give a much too smooth colorization. There may be a sophisticated way I'm currently not aware of, so if you have a reference why inheriting colors please tell us...

You may want to finish implementing the diamond-square algorithm, since you have started it. But you should also consider using Perlin noise instead.

 

That's what I want to do. I wrote a part from algorithm, but like I said, I'm not sure if I understood it. :P
About Perlin noise, maybe after this I will try it :).

This topic is closed to new replies.

Advertisement