import math import sys class globeplotter(object): def __init__(self,latitude0,longitude0,r): self.latitude0 = latitude0 self.elevation0 = self.to_elevation(latitude0) self.longitude0 = longitude0 self.azimuth0 = self.to_azimuth(longitude0) self.r = r def to_elevation(self,latitude): return ((latitude + 90.0) / 180.0) * math.pi - math.pi/2 def to_azimuth(self,longitude): return ((longitude + 180.0) / 360.0) * math.pi*2 - math.pi def plot(self,region): points = [] ignore = True for (latitude,longitude) in region: elevation = self.to_elevation(latitude) azimuth = self.to_azimuth(longitude) # work out if the point is visible cosc = math.sin(elevation)*math.sin(self.elevation0)+math.cos(self.elevation0)*math.cos(elevation)*math.cos(azimuth-self.azimuth0) if cosc >= 0.0: # this point is visible, so do not ignore this region ignore = False # orthographic projection xo = self.r*math.cos(elevation)*math.sin(azimuth-self.azimuth0) yo = -self.r*(math.cos(self.elevation0)*math.sin(elevation)-math.sin(self.elevation0)*math.cos(elevation)*math.cos(azimuth-self.azimuth0)) x = self.r + xo y = self.r + yo if cosc < 0: # this point is on the far side of the globe. Truncate it to lie on the rim. theta = math.atan2(yo,xo) x1 = self.r + self.r * math.cos(theta) y1 = self.r + self.r * math.sin(theta) points.append((x1,y1)) else: points.append((x,y)) if ignore: return None return points