# diamond square (midpoint displacement) seeding woes

## Recommended Posts

FOR ANSWER SEEKERS Even if you can't solve my problem I am more than willing to help anyone needing to implement a midpoint displacement algorithm or the diamond square algorithm. Just reading stuff online is one thing, but actually getting it to work is a small miracle if it's your first time. Please contact me for help, as it's quite easy with a guiding hand (kevinfishburne [AT] eightvirtues.com). THE ROAD SO FAR I have (apparently) successfully implemented the famed diamond square algorithm to iteratively create a "plasma cloud fractal"-like height field. I even got it to seamlessly wrap with a little effort. Here's an example: http://www.eightvirtues.com/littoral/littoral_01.png MY GOAL While I can seed hard values all day long (skip the algorithm and just stick some value in for a midpoint), I need to seed it more intelligently. Ideally I'd like to use an elevation "template" that would influence the value of the midpoint being created. The template is an image-based height field, though primitive, that defines the littoral (coastline) and general elevation ranges (sea beds, continental shelf, beaches, plains/foothills and mountains) for the map. The influence of the template would manifest in two distinct controls over the result of the midpoint calculation, being (1) whether or not the midpoint is above or below sea level (apply the littoral) and (2) the midpoint would be moved toward sea level based on the template's proximity to sea level. A deeper explanation of (2) is that the closer the template midpoint is to sea level, the more the midpoint will abandon its original value and be pushed toward sea level. Two examples would be that if the template midpoint is as far from sea level as possible (sea bed or mountain top), the midpoint calculation would not be influenced (m*1). If the template midpoint is at sea level, the midpoint calculation would be sea level, regardless of its original value (m*0). VARIABLES USED TO IMPLEMENT GOAL This is the data I've set up to work with: eouter - average elevation value of four points surrounding the midpoint touter - average elevation value of four points surrounding the midpoint in the template tcenter - elevation value of the midpoint in the template rmod - random modifier reduced by 1/2 each iteration iclamp - reduced by half each iteration, multiplied by rmod (1.0, 0.5, 0.25, etc.) tclamp - reduces the value of anything multiplied by it based on proximity to template sea level (between 0 and 1) ULTIMATE QUESTIONS I need to both "clamp" the generated midpoints to the template sea level as well as to control whether or not they should be above or below sea level. How do I do this without generating artifacts and other problems? Here are some example images of my issues for your consideration: http://www.eightvirtues.com/littoral/littoral_02.png The inorganic/circular "islands" are control structures I drew into the template image, not errors or anomalies. You can see that the littoral is not properly clamped, and that some points in shallow areas of water (the rivers) are nearly at sea-floor level. Some small islands also drop to sea-floor level nearly immediately. Here is the relevant code: ' Create random variation that is: ' (1) Reduced by proximity to template sea level ' (2) Constrained to above/below template sea level IF tcenter < 0 THEN ' Template is below sea level. DO etemp = eouter + rmod * tclamp - increment increment = increment + 1 LOOP UNTIL etemp < 0 ELSE ' Template is above sea level. DO etemp = eouter + rmod * tclamp + increment increment = increment + 1 LOOP UNTIL etemp >= 0 ENDIF I've tried countless strategies and variations of code for weeks now, so I'll spare you the variations. If anyone has any insight into what I'm trying to do please let me know. I can post additional code if other failures warrant inspection. Thanks so much.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628354
• Total Posts
2982229

• 10
• 9
• 11
• 24
• 11