# Determining Nearby Waterfalls

Finding geographic proximity is nothing new for me. While I've played with the Google Distance Matrix API before I've also had some fun using alternative (Warning: Mathematical!) methods for measuring distance with flat planes, spherical approximations, and tunnels. When I looked at adding a simple feature to the upcoming waterfall site, the ability to view the 'n' closest waterfalls to a given location, I felt like I had more than enough tools at my disposal to deal with that calculation.

Unfortunately, though, thinking got in the way. What is the 'closest' waterfall(s)? What does that mean to an adventurer? The information could be helpful if someone wanted to view similar drops. If there are multiple waterfalls clustered along a ridge or a single river there's a good chance that each one would have some commonalities, flowing over the same type rocks and terrain. What seems more likely, though, is that a visitor wants to plan a trip and wouldn't mind a few short side destinations. And this complicates everything.

There are three main methods I looked at for the 'nearby waterfalls' problem& hellip;

A mainstay, the Distance Matrix API is a dandy way to find driving directions between two points (yes, I know they do alternative travel methods too, but I'm looking at the Upper Peninsula of Michigan here). If someone else has done all of the hard work of figuring out where the roads are and how navigable each one is, plus the algorithms to tie everything together, why not just use it? Simple - people can walk to a waterfall, and sometimes a mile walk can cut out miles of driving in some of the more wild stretches of the Upper Peninsula. So the Distance Matrix is out.

The shorter, obvious route

#### Shortest Distance Calculation

Whether I used tunnels, a perfectly spherical earth, or Flatland, calculating distance based on the coordinates would be fairly easy at this point. I have the formulas and exact geolocation - it would take minutes to whip up a quick script and calculate proximity for the 160 unique waterfalls. There a problem with this, though.

#### Smart Calculations

Lakes. Mountains. Bogs. Private Property. Simply put, the shortest distance between two points is not always a reasonable route. Little Falls on Interior Creek is only 2.64 miles from Bond Falls as the bird flies, but without a boat the trek it is 2.89 miles. That distance doesn't make a terribly big difference in knowing that the two waterfalls are relatively close together, close enough to hit up both in one visit to Paulding, but it's still a difference. And it gets bigger with other Upper Peninsula waterfalls.

This is where things start to get fun. Is there a way to programmatically determine the closest distance while respecting various obstacles? And if there is, can you calculate damping factors and different shapes?

Example of smart path logic

I'd imagine that the easiest thing to tackle initially would be the hard obstacles, like lakes and private property, that you cannot cross. One way to approach this calculation would be to find the points of intersection, find the midpoint, and then look for the most direct route around, and then repeat. There may be more elegant ways to do this, though I feel like this may be one of the quickest.

After this is built out you could start working on damping factors. There are two main types of damping factors - ones that can be assumed as consistent (like a marshy stretch or thick woods) and ones that vary throughout (like a tall hill). The latter may get a bit hairy, as curves would start to enter the equations.

With these built in you could start some 'easy path' logic. Sure, lakes and mountains complicate routes, but roads, paths, and open fields can make a hike easy. It's worth a small detour off the most direct route to save time and stroll along a convenient footpath. This wouldn't be terribly difficult to work in, not after the initial obstacle logic (you'd just have to tweak the factors a bit).

So, why do all this? Hikers who pick locations based on their appeal and not ease of access spend a decent amount of time planning a good approach. If you knew a start point, the end point, and lakes/rivers/roads were already defined, this system could literally pick the most appropriate route. You could tweak the factors by the time of the year - lakes covered in ice can be walked upon - or by your specific hiking habits. Given network access this route could be updated in real time, during the hike, giving you a perpetual hiking advisor.

Will I be doing this for the waterfall site, automatically determining ideal routes and proximity based on geography and biology? Probably not. I'd like to get the site live at some point this year ;) However, this would make an interesting future project, a functional route planner that make Google's Distance Matrix API and their direction algorithms look downright antiquated.