TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: How to generate random terrain

31 pointsby alaricspover 15 years ago
When I was a kid in the 1980s, I read a library book on the topic of writing military strategy sim games, and it had an entire chapter on producing random terrain. It started with the usual fractal techniques for producing contours, but then it went on to use weighted random walks to produce roads and rivers, lakes, bridges, and cities.<p>I've tried recreating the algorithms from what little I remember of them, but they never produce anything that looks very good. Online I've found plenty of references to ways of generating the contours, but never realistic-looking roads, rails, and waterways...<p>Does anybody know an online reference to that sort of thing?<p>Thanks!

14 comments

wlievensover 15 years ago
What kind of scale of terrain are you looking for? Continent maps or battlefield scale?<p>I got some stuff I rolled here <a href="http://flywheel.be/examples/" rel="nofollow">http://flywheel.be/examples/</a><p>All random generated. But probably not what you're looking for.
评论 #823438 未加载
评论 #821971 未加载
bigsassyover 15 years ago
Game development websites are a good place to look. Try these links:<p><a href="http://www.gamedev.net/reference/list.asp?categoryid=45#188" rel="nofollow">http://www.gamedev.net/reference/list.asp?categoryid=45#188</a> <a href="http://www.gamasutra.com/search/index.php?search_text=terrain+roads&#38;submit=Search" rel="nofollow">http://www.gamasutra.com/search/index.php?search_text=terrai...</a>
slmbrhrtover 15 years ago
For generating roads or waterways, try coming up with rules similar to the way they're created in real life. For example, water flows downhill and pools when it finds a local minimum. Roads, on the other hand, tend to avoid steep grades when they can, typically moving straight and branching at right angles at regular intervals.<p>Read up on L-Systems, too. They're great for creating organic structures, be they leaves, trees, or river-tributary systems.<p>Oh and this may be useful: <a href="http://roguebasin.roguelikedevelopment.org/index.php?title=Cellular_Automata_Method_for_Generating_Random_Cave-Like_Levels" rel="nofollow">http://roguebasin.roguelikedevelopment.org/index.php?title=C...</a>
评论 #822220 未加载
dovyskiover 15 years ago
You can take a look at my master thesis (Charack: Pseudo-infinite 3D virtual world generation). It's in a pre-alpha stage, but I think you can find something useful (besides the wide range of similar tools and works I found during my research).<p>Project link: <a href="http://code.google.com/p/charack/" rel="nofollow">http://code.google.com/p/charack/</a>
评论 #822947 未加载
评论 #822224 未加载
allenpover 15 years ago
If you have a heightmap, the roads should be fairly easy. Pick start and end points (cities?) and use a pathfinding method like A* to plot the road. If you want something more stylized, you could select a handful of points from that method and then use beizer curves or something between them.
评论 #823431 未加载
jharsmanover 15 years ago
For waterways, just simulate rain and erosion. Let's say you model your terrain as a height field.<p>1. Add rain in random locations 2. Have the rain absorb some of the soil from the square it starts in. 3. Let the water flow in the direction of the gradient. 4. Deposit som e of the picked up soil (maybe only with some probability based on the flow velocity?) 5. Repeat<p>If you just want rivers and lakes you can skip the erosion step and just simulate the water flowing. If you wanted you could add sources manually and have water always flow from there.
afiskeover 15 years ago
Here's an article on adding rivers to procedurally generated terrain - <a href="http://www.gamedev.net/reference/programming/features/randomriver/" rel="nofollow">http://www.gamedev.net/reference/programming/features/random...</a>. Searches for "procedurally generated [roads/rivers/waterways/etc] seemed to be the most promising.
jweckerover 15 years ago
google erosion simulation algorithms (or derivations)- some brilliant stuff mostly developed for geography simulations that would make absolutely amazing terrains.
stevejohnsonover 15 years ago
I did some work on random terrain once. You can see the results here:<p><a href="http://steveasleep.appspot.com/pyworldgen" rel="nofollow">http://steveasleep.appspot.com/pyworldgen</a><p>If this is what you're looking for, I can try to explain it.
评论 #823439 未加载
zeckalphaover 15 years ago
Perchance recall the book? I'm semi-interested in retro approaches to the problem.
评论 #821942 未加载
elcronover 15 years ago
The freeciv map generator is pretty good if your looking for sample code for a world scale map.
julesover 15 years ago
For waterways you could try to place random water sources and follow the gradient from there.
jacquesmover 15 years ago
Search for 'Mandelbrot' or 'Peitgen' and 'fractal landscape'.
bendotcover 15 years ago
<a href="http://lmgtfy.com/?q=terrain+generation&#38;l=1" rel="nofollow">http://lmgtfy.com/?q=terrain+generation&#38;l=1</a><p>Seriously, I'm all for discussion of particular techniques, but your question is way too broad right now. Go read some papers or even just online tutorials or descriptions of how other software does it, and then lets have a discussion.
评论 #821752 未加载