# How do I simulate the path of a river?

In Creating a realistic world map - Waterways, I asked about exactly what processes affect how rivers flow and meander. With some of that knowledge in mind, I'm curious as to how a worldbuilder (like myself, for instance!) could go about creating a river on a map, especially in flat regions. As was the case with coastlines, which I think I've gotten better at, my current method is to draw little squiggly curves based on any existing topology I've figured out. But that's still annoying. Is there a better way that is commonly to simulate this?

Some things I'm looking for:

• Computational efficiency
• No extremely unrealistic features (i.e. a river constantly doubling back and intersecting itself)
• Some semblance of control over the final product

I did go into detail about the fractal algorithm in my answer below. Answers don't have to go into that much detail, or even show a finished product. A simple description of the algorithm is fine.

I can't help you much with coding but I can help with what to look for to tell if you have gotten it right.

Just elevation will take care of a lot, once you know where the basins are you know the direction and size of your river systems. That does mean you need to plot your mountains before the rivers. lets look at a map of river basins in the US.

now compare it to mountain range placement.

notice that outer edge of each basin is defined by either a coastline where the river dumps into the ocean or it is mountains/high lands. Notice that as you get further into the land mass the number of basins drops dramatically while along the coast there are many many small basins (and thus small rivers). You can do a rough plot of a river system by just plotting how to get from from any point to the coast without crossing higher elevation. Water follows the path of least resistance and generally from mountains to ocean. Then you need to add some randomizing effects to account for the local variation you are not modeling. Someone else will have to help you on how to add such more or less variation.

in addition how much a river wanders back and forth is a function of the slope of river, steeper fast moving water cuts a more direct line (although never straight) while shallow sloped (and thus slow moving) water meanders, if the land is flat enough this wandering can become very extreme. .

Completely isolated land-locked basins are rare, only occurring when a a complete ring of mountains exists. These feed in to isolated lakes that become hyper saline(salty). Utah's salt lake is a great example. Normal lakes are created by local lows that fill up and overflow creating an outlet. The vast majority of lakes will have an outlet, that is an exiting river.

Not large rivers often produce deltas when they reach the sea, they are so flat so slow moving they dump sediment blocking themselves creating a branching pattern. these end up looking like fans or dense trees pushing out into the ocean.

• Rivers don't meander because the slope is low. Rivers like the one pictured meander because over time their current paths fill up with silt and then they overflow into a new path. – Shufflepants Mar 14 '17 at 19:09
• The important part about mountain ranges is that, to a first approximation, mountain rangers determine river flow and not the other way around. (Erosion eventually grinds down mountains, hence to a first approximation) Tectonics -> glaciation & geology -> water flow – Yakk Mar 14 '17 at 19:21
• @Shufflepants That is correct, but slope affects this because it affects the speed of flow, which in turn determines the silt carrying capacity. So very steep-grade rivers will tend to be straighter than rivers through flat areas. – Era Mar 14 '17 at 19:55
• One quibble: landlocked (endorheic) basins aren't actually all that rare: much of central Asia and big chunks of North Africa, Australia, and western North America are landlocked: en.wikipedia.org/wiki/File:Ocean_drainage.png – jamesqf Mar 14 '17 at 20:04
• I see a lot of "enter image description here" links in this answer... – Mołot Mar 14 '17 at 20:54

I'm self-answering my question, but please don't let that deter any other answers! I'm definitely curious to see if there are any other common techniques.

# Use fractals!

In the previous question about coastlines, Samuel's answer pointed out that fractal landscape techniques can work very well for simulating coastlines. The degree of self-similarity is often startling. I've implemented an algorithm to do that, and it's produced very good results. It also turns out that rivers, too, exhibit fractal-like patterns, and over areas that are relatively flat, they can be simulated - by fractals! Fractal river modeling is actually a very effective technique, and is often used.

The first step to generate such a river is to determine the terrain. If you want, you can use fractal techniques using the diamond-square algorithm, for instance. You can also figure it out via various other methods; I've used random methods that begin with a circular region, then randomly increase the decrease the elevation while moving inwards - weighted, of course, with a tendency to go upward, rather than downward. After that, you could add even more detail by modeling erosion patterns using, for instance, cellular automata; Jasper McChesney wrote an awesome post on the Worldbuilding blog about this. Even without using Jasper's algorithm, I've already found some results I like. Here are some examples (these are shown as contour maps; green, yellow, orange, and red are above sea level):

I bring these up in particular because they have interesting features: Valleys and sharp downward gradients, as well as sections of flat land going down to the sea. The valleys mean that I can figure out where a river might go. In places where there is a clear downhill path, it's simple to figure out a river's path. However, some of the valleys are still wide, and they all eventually end, leading to flat areas with no clear path for the rivers to take. How, then, can I simulate where the rivers will go? One answer, of course, is fractals.

Here's a version of the (commonly used) method I've been using for coastlines, adapted and modified for rivers:

1. Pick two points, the places where you want this portion of the river to start and end. Call them $p_1(x_1,y_b)$ and $p_2(x_2,y_b)$, and put them in the set of points, $P$. I give them the same $y$-values, for simplicity's sake; you can rotate the map any angle you choose, and we might as well keep things horizontal. Let's also set $y_b=0$.
2. Draw a line segment between the two points. Divide it into $N$ subintervals, each of length $$l=\frac{|x_2-x_1|}{N}$$
3. At the center of each interval, pick a random length $d$ between $-\frac{l}{a}\frac{1}{j+1}$ and $\frac{l}{a}\frac{1}{j+1}$, where $a$ is some constant and $j$ is the iteration number. We begin with $j=0$ when running this for the first time.
4. Add another point, with the $x$-coordinate at the center of the interval and the $y$-coordinate being $d$.
5. Add all of the new points to $P$, reordering $P$ in terms of how they are connected to each other.
6. Repeat steps 3-5 as many times as desired.
7. If you want, you can then using some sort of spline to make a nice, smooth curve encompassing all of the points.

You now have a segment of a river! Simply insert it onto your map between the desired points, and see how the world evolves. Do this for as many segments and rivers as you desire, although be careful to do this mainly in flat regions, where the topography won't have a major impact.

The bests results I've gotten are actually for $N=1$ and $a=10$, over four iterations. There are, of course, some duds - cases where the river crosses over itself, for instance - but there are also some gems where you get proper, repeated meanders, like a real river:

(The code used to create these is now on GitHub.)

Note that the vertical scale is expanded for effect. The swings aren't really as wild as they appear; they're actually much smaller, and the river doesn't deviate drastically from a straight line - just enough to get some realistic meandering.

I know what some people are thinking right now. "But HDE, couldn't you just use a random walk?" Well, yes, you could use a Gaussian random walk method. That's rather simple, and might actually be computationally simpler. To make it realistic, all you'd have to do is vary the step size randomly. There are, however, a couple issues I have with using a random walk in this case:

• There's no guarantee you'll reach your desired endpoint, which is a problem. I suppose you could start random walks from both endpoints simultaneously, and see where they match, but that could take quite some time. They might never meet.
• It's not very hard for the walk to cross back over itself. If you implement the fractal midpoint algorithm, it's true that you'll have some cases where the river crosses itself, and that can be a little annoying. However, most runs will not have this kind of issue. The same can't be said for the random walk method.

This is why fractals are much better suited for river modeling, coastline creation, and terrain generation than random walks are. You have more control, while still ensuring that there's plenty of healthy variation over the course of the river.

Here's another thought. Perhaps you don't want your river to run perfectly straight. You've generated your terrain already and have determined a general path for the river to follow, in accordance with the elevation. At this point, it might seem that the fractal method is pointless. It isn't. All you have to do is adapt the algorithm to a straight line, replacing $l$ with the arc length along the curve from point $p_i$ to $p_{i+1}$, and the slope of the line perpendicular (and passing through) the midpoint of each (now curved) segment with a line normal to the curve (i.e. perpendicular) at that point. The rest is simple; in fact, after each step, you can redo the spline, creating a new curve each time, with more detail. Alternatively, you can wait until the end and do something similar to what we did before, in effect, just using the initial path as the basis for the first iteration only. I haven't tried any of this myself, but it's a promising method.

There are a couple things to take into account here:

• You'll need a parametric description of the initial curve, i.e. writing the curve $C(t)=(x(t),y(t))$ as a function of $t$.
• You'll also need to know certain values through which the curve goes.
• You'll have to calculate arc length if you want to figure out the exact midpoint of each segment. That shouldn't be too challenging numerically.

You could - if you really want - eyeball these steps, but I'd prefer to compute them.

Here's a case of what I'm talking about, with all parameters and curves estimated by hand (well, by Paint). The river to the west is just a modified straight line, with one iteration of the original algorithm. The river to the east uses an initially curved path dictated by the terrain, with a secondary bend:

I should add one final note, because some people reading this may be confused by now. Fractals and self-similarity are also often applied to rivers, but in terms of the generation of tributaries, i.e. how a river branches off. These are two different things, and absolutely should not be confused. I apologized if I have anyone puzzled by this; the coincidence is not ideal.

• I thought fractals were just for looking cool. – Noah Cristino Mar 14 '17 at 14:46
• I have to admit that I read past much of the mathematics here (not my strong point at all). Something that is fairly important in river evolution though is geology, or more specifically how soft the ground is and how easily it erodes away. Periodic ebbing and flowing of the current will expose and take advantage of weaknesses, this is how oxbow curves and lakes develop. – Snow Mar 14 '17 at 14:47
• @NoahCristino Well, they work for that, too. But they have plenty of applications, because many phenomena exhibit fractal-like behavior. You can model Brownian motion, natural patterns (rivers, blood vessels), ferns, enzymes, and much more. It's quite surprising what they can do. – HDE 226868 Mar 14 '17 at 14:48
• @HDE226868 Cool! I'm going to do some more research on that. – Noah Cristino Mar 14 '17 at 14:49
• @HDE226868 A project I work on involves planet scale generation and, very long story short, fractal rivers break down at a relatively small scale (i.e. as mentioned in your answer, anything beyond relatively flat terrain). From ~5 years of experimentation, we found that it's vital the terrain has more variance beyond what noise can provide for realistic planet scale hydrology. Essentially, the best results come from a 'hinted' hybrid - we draw a tagging map which broadly states where feature zones are, then the engine 'seeds' rivers. – Luke Briggs Mar 14 '17 at 20:44

For the coding side you could just use Perlin Noise. Just search it up if you don't know what it is. It also offers nearly full control over your final product.

• Hello and welcome to WorldBuilding. It would be nice if you could provide a link to a good source for readers who are interested in the topic. By explaining the basic concept you could also enlarge your answer a bit. Right now it's a bit short. If you got questions about the site please take the tour and visit the help center. Have fun! – Secespitus Mar 14 '17 at 21:39

Okay, I'm not into the code side, but I did work on several roadway/bikeway projects that included coordination with hydraulic analyses. These were on a local level, however, so I'm going to try to ramp it up for your world.

From your contoured map, since we don't know your soil situation (don't need to, if we're just doing a snapshot).

Information you want to know ("input"? I know nothing about computer modeling) These are the variables that our water guys would use in their models and if you know more about computing than I do - I already know you do HDE - then maybe they're the considerations you want to use, too.

• Flow Distribution - there are apparently algorithms for modeling this, but how I would do it by hand or by a lesser involved practice is using your depth (below) and width you can have the spread out.

• Velocity Distribution - see above. This is affected as well by volume and cartography. If you know a way to combine the two types of distribution, you begin to see a two-dimensional map of a river.

• Water Surface Elevation! - most important, as water flows downhill. This will affect distribution.

• Velocity magnitude - should be self explanatory.

• Velocity direction - should be self explanatory.

• Flow depth - Depth is important when calculating how much volume you can get at once. You can use a polynomial to get a cross-section of your desired river, and then multiply that along the river: somehow a computer can do that quickly for a complex river.

• Shear stress - These were for bridges, so I don't think you need to model that to make a map, unless you're getting really intense on the land features your rivers come up against; for example if you have igneous rock that is very tough, more likely a river is diverted around it or over it like a waterfall; this is found in areas that had tectonic activity.

So you have your contour map, now do your computer magic with the first input being volume. Rainwater on the mountains, artesian wells from aquifers, and don't forget human wastewater (that's actually significant) will get it started in the headwaters, and then the variables above, modeled from your contour map, will define generically the route the rivers take. This is just a snapshot in time as @shufflepants noted.

Your rivers conclude in a delta in flat, sedimentary areas or a gorge straight into the ocean in areas that have steep, deep, rivers.

River types are explained in depth in the accepted answer to your Realistic World Map - Waterways question.

This leaves me at the end of what little experience and knowledge I have. The next step is the hard part.

What i tend to do when practicing my fantasy map making skills, is to draw out layers of elevation, and then use a filter to give the impression that the land isn't flat, before drawing the river using the path of least resistance from it's origin towards the sea.

Snippet from one of my maps: Not sure if you can see the differences in elevation, as the colour makes it a bit difficult to tell, but i hope you get the gist of it.

To expand on what John said (I love the river map BTW), very little is actually flat. Any plain that does not end up being a lake has a slope and the water travels through that plain to the lowest point. The plain generally has high and low spots (from less than a meter to 10s of meters) and the rivers tend to follow those. So, the slope and the terrain and the "bumpiness" will determine the shape of the river.

If the terrain is flat and the slope is low, you tend to get "squigglier" rivers. In the first photo in John's post, the force of the water overcomes the terrain features. Since the water on the outer side of a curve travels faster than the water on the inner side, the river erodes the outer bank faster than the inner bank. That causes the loops to extend outward over time. Then they can get pinched off by the water finding a more direct path and you end up with those "arc lakes" around the river.

If you are writing an algorithm, I'd have the brownian motion biased by the slope and the bumpiness of the terrain. If the water ends up somewhere without an outlet, make a lake and raise the water level to the lowest outlet and begin a new river. Using this method, the water will eventually get to sea level. However, if you factor in evaporation, the water may never reach the sea in dry areas.

there was an article written about 40 or 45 years ago in the Scientific American about sin generated curves. it is the process that rivers, train wrecks and blood vessels use to collapse while spreading the energy evenly over the process. this is why river meander can look like blood vessels. I just found the article is was referring to: ers. Scientific American, 214, 60-70. http://dx.doi.org/10.1038/scientificamerican0666-60

I think it is on point for you. there are other good papers on the subject of sin-generated curves as well.

• Hello and welcome to WorldBuilding.SE! Interesting addition to the existing answers. Can you find and link the source you are refering to? – Secespitus Mar 14 '17 at 21:30

A fitting response for Pi Day. As a river flows it meanders through the landscape, it traces a curved path. If you take length of the river, and divide it by the direct route from the start to the end of the river, you will get the "sinuosity" of the river. This is a measure of how bent the river is. Any given river can have a range of sinuosities, however you can demonstrate that the average sinuosity of all rivers in the world should be... Pi. Seriously. Watch this awesome video from Numberphile to learn more. It is a curious fact that is the result of how rivers form oxbow lakes, straightening themselves in the process. In practice, you don't find sinuosities greater than 3.5, and not really below 2.7.

Remember that pi is the expected average of all rivers, and this is under ideal conditions. Real world topography will cause this to vary, but this serves as a good approximation as to how straight or bent a given river should be.

IMHO, neither of your graphs appear to be plausible rivers.

For one (obvious) thing, their length is minuscule. Sea level is an arbitrary artifact of global temperature and available surface water. Continents, on the other hand are the result (on this planet, at least) of the creation, collision, and subduction of tectonic plates. A river system is what drains an aquifer. If an area were created flat, then there'd be little reason to expect one river to form.

The river system would most likely be formed highly branched at all levels of length. As a recreational biker, I can tell you that there are few areas on Earth which are "flat" (salt flats being the exception).

The problem with your assumption of flatness, is that there isn't going to be any drainage, which means no reason for a river to exist.

So, the way I would create a world would be:

• Next pick a sea level. You should be left with some islands and some bigger chunks.
• Once you have that, figure out rainfall - wind and mountains, as well as large, dense forests have great influence there.
• Once you've got rainfall, you need a drainage system (known as a river) which will take roughly one unit of water (temperature, wind of course impact that) to the sea. Feel free to (randomly) vary the unit by a factor of 2 or so.
• So, now that you have an area to drain, you know for sure that the drainage has to start at the highest point (I'd exclude mountain peaks, say above the timberline) and end at one or more of the lowest points. You're either going to get a lake, or flow into an adjacent area.

The difference between this approach and yours is pretty profound, imho. You want to connect two points. I say, drain the whole country, starting with the highlands, working towards the lowlands. Not from point 1 to 2, 3 to 4. But from areas A,B,C,... to points α,ß,Γ,... simultaneously working your way down in elevation.

By the way, you should include both meanders, braids, and anastomoses (see https://en.wikipedia.org/wiki/Channel_types) - at least in some cases.

• Hi, Li Zhi. I noticed you've made a few different accounts to post different answers. There's nothing wrong with that, assuming you don't use them to circumvent rules, but there are benefits to creating one registered account. It's a lot easier to keep track of your posts, and to go back an edit them. This is just some advice; I hope it's useful. – HDE 226868 Mar 14 '17 at 17:07

First of all, go to YouTube and search why do rivers curve, and click on the fist one. I found this video very helpful. Most of what I can tell you is from that video, so here are some key points:

The length of one "s" in a river is roughly six times the width of the river.

If any disturbances are in the way, the river will simply go around the disturbance.

A meander can be caused by nearly anything, so they ate quite common. Sometimes the s will be thinner than others because it has formed an oxbow lake.