2100 Year Old Geek

or

A tale of Two Cities

or

Carry a Big Stick

So part of my mandate in developing the order process for WineShopper is to find the nearest retailer to a customer's location so that they can pick up the wine there. We do this by finding the global latitude and longitude for each of the retailers, and for the customer. We then use Oracle Spatial functionality to list the points nearest to a given point and to tell us the distance between those points. The trouble is that until the next release of Oracle in December, we can only get the distance back in degrees.

Once upon a time I was enough of a dork to call this good enough, to insist that those unable to manage a simple calculation of degrees to miles would be driving in circles anyway. But since I don't actually know how to do that myself, I decided I'd better find out. Turns out that on our planet a degree is roughly 69 miles if you are heading north or south and anywhere between 0 and 69 miles if you go east or west. I majored in math, so I ought to be able to work this up into something useful, but I'm also pretty lazy, and something told me it might be easier to take the two points and find the distance myself. Pythagoras can't help us because he doesn't account for the curvature of the Earth <*>, but my net search turned up this 2100 year old geek that was a bit of a help. His name was Erastothenes, and he was so cool that I'm gonna take a moment and write about him.

Erastothenes was the director of the library in Alexandria, Mecca to all the geeks at that time. Alexandria is north of a city called Syene (now Aswan) where it was said that the sun cast no shadows at noon on the summer Solstice (June 21st). So Erastothenes takes a big stick, and during the summer Solstice, holds it upright and notices that in Alexandria, it casts a shadow and that the angle seems to be about 1/50th of a circle. Talking to camel drivers, he learns that Alexandria is about 500 miles north of Syene. Figuring the suns rays to be parallel, he decides that the angle of the shadow formed by his stick must be the same as the angle at the center of the earth between the two cities. If the angle itself is 1/50th of a circle than the circumference must be about 50 times the distance between Syene and Alexandria. Dividing by 2Pi (they knew about Pi then), he gets a radius for the Earth of about 4212 miles. The actual radius is about 3963 miles -- he was roughly 5% off. I think that's pretty cool.

Of course my problem is a little different, Erastothenes wanted to know the radius given the distance btween two points whereas I want to know the opposite. Luckily, I found an equation for the arc tangent during my search that will do that. Actually I've never expicetly been told to find the distance between the customer and the retailers at all.

I'm doing it for the same reason as Erastothenes -- because I want to.

--M!chael

<*> Since we're only searching for Retailers within 100 miles or so, the Pythagorean theorem probably WOULD be fine, but I was on a roll.