Anyone ever used the diamond-square algorithm for generating fractals?

cchen

Diamond Member
Oct 12, 1999
6,062
0
76
I'm trying to implement this algorithm in opengl to draw a fractal but i'm confused....

The pseudocode that I found is:


<<
Square Step:
1. Given four points in a square shape.
2. Find the centre (midpoint) point of the square.
3. Calculate this midpoints height value by averaging the heights of the four corners.
4. Displace the midpoint by a random value in the range (-sigma, sigma).
5. Proceed to Diamond Step, for each of the diamonds created by this step, with the same sigma value. Diamond Step:
1. Given four points in a diamond shape.
2. Find the midpoint of the square.
3. Calculate the height value of the midpoint by averaging the four corners.
4. Displace the midpoint by a random value in the range (-sigma, sigma).
5. Proceed to Square Step, for each of the diamonds created by this step, with a new sigma value.
sigma(new) = sigma * 2^roughness

Diamond Step:
1. Given four points in a diamond shape.
2. Find the midpoint of the square.
3. Calculate the height value of the midpoint by averaging the four corners.
4. Displace the midpoint by a random value in the range (-sigma, sigma).
5. Proceed to Square Step, for each of the diamonds created by this step, with a new sigma value.
sigma(new) = sigma * 2^roughness
>>




If i start with four points in a square shape, how does it have height? and how does the midpoint have height? Can anyone show me a quick example?
 

gopunk

Lifer
Jul 7, 2001
29,239
2
0
If i start with four points in a square shape, how does it have height? and how does the midpoint have height? Can anyone show me a quick example?

maybe i'm misreading your question, but you have height because you have a square. you just take the height of the square... y1 - y2.
 

cchen

Diamond Member
Oct 12, 1999
6,062
0
76
If so... when you calculate the midpoint, won't you already have the "height?" Then why is there a step 3 for calculating the height?
 

gopunk

Lifer
Jul 7, 2001
29,239
2
0


<< If so... when you calculate the midpoint, won't you already have the "height?" Then why is there a step 3 for calculating the height? >>



not necessarily, if your bottom two points are not y=0, then you'd have to have a step 3 for height. bottom line, i don't think it really matters how you get there, as long as you do.
 

cchen

Diamond Member
Oct 12, 1999
6,062
0
76
It says displace the midpoint... would that be both x and y or just x or just y? And what is sigma?