August 8, 2018

Currents I: Current Events

While I'm on a vector kick, I figured I'd tackle currents again. To really, truly model precipitation, I want a better model of where the hot or cold water is. I didn't actually spend that much work on it to begin with.

Most current modeling guides start off the same way. Head west along the equator, split north and south when you get to a coastline. When the current reaches about 45$^\circ$ latitude, it heads back west. If it originates from a pole, it's cold; if from the equator, it's hot. Warm and cold water meeting creates mild currents.

Theoretically that shouldn't be too hard to model. Unlike the wind model, I don't care about current strength, only direction. So I can start off with a set of vectors and propagate them out until the basics are modeled.

Keeping track of each vector is not the hard part; I just have a dictionary to store the angles. So each hex pushes water along its angle to the new target, which does the same on the next loop. The question is, what happens when I hit a coast? As mentioned before, it should split.

But, of course, this is not as simple as it seems at first. This is one of those problems where it's easy to visualize, but harder to implement in code (for me, at least). The code needs to be able to "see" the local coastline (or at least the coastal hexes) so that it can split the current in the correct directions.

For now, I've got the water moving a bit, but it won't split, and it can get trapped in a bay. The algorithm needs a way to "back out" and find an optimal path up the coast. I'm looking through a few options for classical algorithms to solve this problem (like Marching Squares or a walking algorithm).

Good

Not good
This stuff will also be useful once I extend the route finding code to the sea. It will be cheaper/easier to follow a current than to fight against it.

No comments:

Post a Comment