Algorithm to generate water flow map, given a terrain
An answer to this question on the Scientific Computing Stack Exchange.
Question
I've posted the same question at GameDev Stack Exchange, but unfortunately I am not getting any response. So I am going to post ( and reword) it here. Hopefully I can get an answer!
I have a terrain ( in the form of mesh/element), and I want to indicate how the water flows in the terrain, subjected to gravity force and the terrain condition ( of course).
A crude way of doing this is to take every single mesh element, then draw the water flow direction from the highest point to the lowest, but I think this will result in a lot of ugly arrows that although can roughly point towards the correct directions, but really don't look nice when view as a whole.
Is there an algorithm, or even better, an existing code implementation ( in the form of well-documented APIs with Windows DLLs, or open source soure code), that allows me to generate the water "flow map" in an elegant, intuitive, look-nice way?
Answer
This is a well-studied problem in geomorphological and hydrological modeling, as well as the fields of geomorphometry and terrain analysis.
For visualization, flow accumulation is usually calculated. If every element of your terrain is taken as contributing a value of 1 to the flow, then flow accumulation is the sum of all the flow that passes through a given element. A depiction of this for a landscape might look like this:
There are several different flow routing methods. The one you describe is known as D8. A few additional ones are depicted below.
Algorithms for performing the above, along with citations to appropriate references, are available in my library, RichDEM.
