#!/usr/bin/env python from math import sin, cos, pi from math import asin, atan2 def normcross (v1, v2): l = [v1[1] * v2[2] - v1[2] * v2[1], v1[2] * v2[0] - v1[0] * v2[2], v1[0] * v2[1] - v1[1] * v2[0]] length = (l[0]*l[0]+l[1]*l[1]+l[2]*l[2])**0.5 return (l[0] / length, l[1] / length, l[2] / length) def co2vec (lat, lon): la = lat / 180. * pi lo = lon / 180. * pi x = cos (lo) * cos (la) y = sin (lo) * cos (la) z = sin (la) return (x, y, z) def vec2co (v1): return (asin (v1[2]) / pi * 180, atan2 (v1[1], v1[0]) / pi * 180) if __name__ == '__main__': london = co2vec (51.505617, -0.075252) # Tower Bridge prag = co2vec (50.087217, 14.406869) # Karlsbruecke paris = co2vec (48.846919,2.33718) # Jardin du Luxembourg paris = co2vec (48.858285, 2.294469) # Eiffelturm berlin = co2vec (52.520765, 13.409457) # Alex berlin = co2vec (52.481761, 13.390274) # Tempelhof berlin = co2vec (52.516221, 13.37785) # Brandenburger Tor c1 = normcross (london, prag) c2 = normcross (paris, berlin) c3 = normcross (c1, c2) print "%6f N, %6f E" % vec2co (c3)