1""" 2 kartograph - a svg mapping library 3 Copyright (C) 2011,2012 Gregor Aisch 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU Affero General Public License as 7 published by the Free Software Foundation, either version 3 of the 8 License, or (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU Affero General Public License for more details. 14 15 You should have received a copy of the GNU Affero General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17""" 18 19from azimuthal import Azimuthal 20import math 21 22 23class Orthographic(Azimuthal): 24 """ 25 Orthographic Azimuthal Projection 26 27 implementation taken from http://www.mccarroll.net/snippets/svgworld/ 28 """ 29 def __init__(self, lat0=0, lon0=0): 30 self.r = 1000 31 Azimuthal.__init__(self, lat0, lon0) 32 33 def project(self, lon, lat): 34 lon, lat = self.ll(lon, lat) 35 elevation = self.to_elevation(lat) 36 azimuth = self.to_azimuth(lon) 37 xo = self.r * math.cos(elevation) * math.sin(azimuth - self.azimuth0) 38 yo = -self.r * (math.cos(self.elevation0) * math.sin(elevation) - math.sin(self.elevation0) * math.cos(elevation) * math.cos(azimuth - self.azimuth0)) 39 x = self.r + xo 40 y = self.r + yo 41 return (x, y) 42