Monday, January 13, 2020

New Mountain Style (Part 7)

In the previous posting, I created the code to fill a polygon with mountains by putting down some mountain chains and then filling in around them:
I'll now take this routine and use it to fill in mountain areas on a map.  (Small areas will still be filled in with random mountains.)

Here I'm using a black & white map style like the original map.   I've filled the main mountain areas with two mountain chains and filled in around them with some random mountains.  Overall this isn't too bad, but it does have some problems that I need to address.

Looking specifically at the mountain chains I think they're pretty good overall, but I see a couple of problems.  ( I always have outsized expectations for new features, and I'm disappointed when they don't look indistinguishable from the work of a human artist.)  First of all, the mountains in those chains are all fairly close to the same size, and that's not particularly appealing.  Partially this happens because the underlying terrain looks that way; partially it happens because very small mountains don't work well in mountain chains so they've been suppressed.  One possibility to address this is to force the chain to peak in the middle:
I experimented with this during testing, and I think it looks pretty good and helps to better define the mountain chain.  I'm a little concerned that this might become repetitive on a large map with many mountain areas, so that's something to watch out for.

Another problem with the chains is that on the left side of the main mountain chain the slope of the chain is almost the same as the slopes on the right side of the toplines and it creates a clumsy looking progression where all the mountain sides align:
A human artist wouldn't make this mistake.  One way a human would avoid this problem would be not to draw adjacent mountains with the same slopes (so that they couldn't line up).  I can implement something like this by forcing the slopes of the mountains along the chain to alternate between wide and narrow:
I was worried that strict alternation would be obvious, but it doesn't seem to be a problem.  This fix isn't a panacea.  It worked pretty well for the lower mountain chain, but note that the top mountain chain now has some similar problems.

Another approach to eliminating the collinear sides is to detect when this is happening and perturb mountains left or right to break up the visual line.  To detect collinear sides is pretty difficult, but it's fairly easy to tell when the peak of the front mountain is close to the right topline of the back mountain, and this is a good enough indicator.  When this happens, I can move the mountain away from the topline.  Moving the mountain randomly doesn't work very well; it's better to move it along the normal of the topline.
You can see that this has broken up the visual line in the top mountain chain.  The drawback of this approach is that it also tends to break up the visual continuity of the mountain chain (and may in fact require drawing an extra line to connect the ridgeline of the back mountain to the topline of the front mountain) but that's probably better than leaving the toplines aligned.

In the maps above, the angle for the mountain chains has been selected to be the same as the longest chord in the polygon that defines the mountains.  One way to have better mountain chains is to force the mountain ranges to lie at one of the angles that works well for drawing mountain chains.
This creates nice mountain chains, but they tend to be shorter than the other approach because they're not going the long way across the polygon.

The drawback with both of these approaches is that drawing the mountain chains as an angled line doesn't do a good job of defining the shape of the polygon, and creates a bunch of parallel valleys, which is unrealistic.  A better approach might be to draw a mountain chain down the “spine" of the region, and then fill in around it.

The spine of a polygon is usually called the “centerline."  It's hard to find an exact definition for the centerline of a polygon, but as the name suggests it's intended to be the longest line that runs roughly in the center of the polygon.  This page has a nice interactive example of generating the centerline of a polygon for use in labeling.  The short version is that you create a Voronoi diagram based on the points in the polygon and then find the longest path through the Voronoi edges.  This is the result for the map I'm currently using:
This works but you can see that in both polygons the line curves back around at the ends to be longer.  For the purposes of drawing mountain chains I prefer straighter lines, even if they're not the longest possible.  To select straighter lines, I have to incorporate that in the metric for picking the path.  I introduced the idea of sinuosity when placing path labels, so I'll combine that with length to pick a path:
This helps find a more reasonable backbone for the mountains.  Here's what it looks like to put down the centerline as a backbone and then fill in with random mountains:
There's something of a glitch where the line takes a sharp turn in the middle of the larger region.  In general it is difficult for the mountain ranges to follow abrupt changes of direction.  Smoothing the centerline helps with this:
The drawback is that aggressively smoothing the line means it is no longer a very faithful spine for the mountains area.  I like that this is thematically more interesting than a mass of random mountains, or than parallel rows of mountains, but I wonder if it will be problematic for larger mountain areas.

Here are some example maps (reduced in size to fit in the blog) to see how this looks on a full map:
Both of these mountain ranges happen to be almost vertical, an orientation that works well for mountain ranges because the ridgelines can connect to the peaks.
Here we have one long mountain chain with a capital city on the slopes of one of the biggest mountains -- a pretty nice combination.  The chain itself looks pretty good as well.
This is the least successful of the example maps, although all the chains are generally at good angles for mountain chains.

Placing a chain of mountains down the centerline and then filling the region sparsely with other mountains seems to work pretty well.  The centerline gives the mountain area an identifiable structure, and the random mountains define the total area.  At least right at the moment I like this better than filling the area completely with random mountains or filling the area with parallel mountain chains.

Next time I'll take a look at fixing a few lingering problems.  (One of these can be seen in the white spaces under mountains in the last example map.)

No comments:

Post a Comment