Around The World, Part 6: Wind hacks

In the previous post, I described a failed attempt to solve this problem of converging winds:

Wind streamlines all converging to a single point

The problem with the pressure-based approach (apart from a slew of tricky mathematical issues) was that it gives me very little control over the resulting wind patterns. So let’s fix that!

I also realized that, because we’re talking about prevailing winds here, not actual winds at some point in time, we wouldn’t actually expect the vector field to have any curls, eddies or vortices. That makes life easier. Technically, it should probably still be divergence-free because it’s the average of divergence-free vector fields, but I’m not going to care about that today.

Coastal distance

Basically, what we were trying to do is make wind bend away from the coast instead of slamming into it. So instead of coming up with some roundabout physics-based way to make that happen, can we just code it up directly?

I already had some Dijkstra code to compute a sort of distance transform, so I applied that to coastlines:

Distance transform to coastlines

The white regions represent land. The bluer the colour, the farther away the coast is. Now it’s a simple matter to compute the gradient of this field (hey, last week’s code is good for something after all!), which gives us a vector pointing away from the coast, wherever it is.

Now, for each point, we can check whether the wind is going towards the coast or away from it, by taking the dot product between the wind vector and the coastal distance gradient. If the wind is blowing towards the coast, we divert it; and the closer to the coast it is, the stronger this diversion effect. This seems to work pretty well:

Wind streamlines avoiding land

I like that this causes the wind to snake its way between islands. It’s not great that it still results in streamlines merging, but at least they don’t merge into a single point anymore. Especially at shallow angles, I think it looks fairly convincing:

Wind streamlines avoiding land


Over sea, away from any coastlines, the wind pattern still looks too smooth and regular:

Wind streamlines being too regular at sea

To fix that, let’s turn to our trusty old friend, simplex noise. In particular, let’s use it to do some domain warping before we even generate the base wind strength, so that the 0°, 30° and 60° lines get pleasantly wobbly:

Wind streamlines with noise

Much better. Note that in this image, I also tweaked the wind bearing so that it doesn’t go straight north, south, east or west anymore, but stays at a bit of an angle throughout. I don’t have any hard statistics on whether this is more realistic, but I think it looks a bit more convincing.

Any way the wind blows

That’s it for dominant wind patterns! In the next post, we’ll use these winds to calculate precipitation, which, combined with temperature, should give us an idea of what the local climate and vegetation is like in our world.