Sunday, July 10, 2016

Q&A - 10/7

TV Character

[from the show The Last Ship, after a group of sailors are kidnapped, blindfolded, and moved somewhere else, one of them goes] you can estimate where you are in the world by using the sun.

Yes you can

This is fascinating "survival math". How can I tell where I am without GPS? It might come in handy you know.. 

Latitude can be calculated using the sun. Longitude, through a clock. First latitude.  The sun will fall at a certain angle  e on the world depending on where we are depending on the equator. That's easy, either through shadows or through an inclinometer app on a smartphone (or sextant!) we can measure it. The only kicker is the season - earth tilts depending on it (well, seasons are the result of that tilt, but anyway), this "declination" can be approximated with, 

where N is the n'th day of the year. Final formula \theta = 90 - e + d (for northern hemisphere).

Longitude, can be calculated trough ... tadaaa .. time zones! A clock is set to London time, we look at the local time - easiest local time lookup is when the sun is highest, noon, 12:00. The difference of that, and the London time is calculated, and each minute means 1/4 degrees in longitude. Presto!

It is January 10, Sun's angle is at 30 degrees. 

def decl(month, day):
    n = (month-1)*30. + day 
    return -23.44 * np.cos( np.radians(360/365. * (n+10.)) )

print decl(1,10)
e = 30; d = decl(1,10)
print  90 - e + d

Result is 38 in latitude. At noon I look at the clock I have with me, it says 5:06 in London. 

print ((5*60)+6) * 0.25


The final coordinates are 38 N, 76.5 W. 

Which City? 

Using a CSV of major cities in the world, 

import pandas as pd
import math

def distance(lat1, long1, lat2, long2):
    degrees_to_radians = math.pi/180.0
    phi1 = (90.0 - lat1)*degrees_to_radians
    phi2 = (90.0 - lat2)*degrees_to_radians
    theta1 = long1*degrees_to_radians
    theta2 = long2*degrees_to_radians
    cos = (math.sin(phi1)*math.sin(phi2)*math.cos(theta1 - theta2) + \
    arc = math.acos( cos )
    return arc
def find_city(lat,lon):
    dist = df.apply(lambda x: distance(lat,lon,x['lat'],x['lng']), axis=1)
    return dist.argmin()

df = pd.read_csv('world_cities.csv',index_col=['city','country','province'])
print find_city(38.0, -76.5)


('St. Charles', 'United States of America', 'Maryland')


The code, with the necessary libraries, an inclinometer, the data file can be packed in a small device; an Arduino or Rasberry Pi based device IMO; and it would tell the geo location, the closest city automagically.

Sources: Video, Wiki

Book (1421)

On 8 March 1421, the largest fleet the world had ever seen set sail from China [..] The Chinese [..] reached America seventy years before Columbus, and Australia three hundred and fifty years before Cook...


Even if they did, it doesn't mean anything if ships are unaware of their location. You can sorta blunder into a location, but if it's not mapped properly, they can't come back to it, and can't trade with that location. And none of that that was possible until longitude was cracked which was way past Galileo's time, well into Newton's. There is a lot of this non-sense coming from "emerging countries" to rewrite their past, in order to create some bullshit nationalist narrative. 

The West had to innovate on exploration, for trading purposes, and on clocks so they could be used for longitude calculation. A lot of people died, were lost, perished in the sea until that happened. The British crown actually created a prize (some say it is the first modern scientific grant), for a portable clock that would not go bad in a voyage, and could be used for longitude. Fella named John Harrison invented one, then a flurry of innovation followed around clocks that would put today's Silicon Valley to shame. Fascinating story (more can be found in the aptly named book Longitude).

Guns and Butter

Peter Schiff "We had a lot of problems that happened in 70s, under Nixon and Ford. But those problems started in the 60s, the great ...