/home/martin/workspace/OpenStreetNav/src/projection/OrthoProjection.cpp
Go to the documentation of this file.
00001 /*
00002  * OrthoProjection.cpp
00003  *
00004  *  Created on: Nov 12, 2011
00005  *      Author: martin
00006  */
00007 
00008 #include "OrthoProjection.h"
00009 #include <cmath>
00010 
00011 namespace proj
00012 {
00013 
00014 OrthoProjection::OrthoProjection(geo::Point center, double radius):
00015     lt(rad(center.lat)),
00016     ln(rad(center.lon)),
00017     r(radius)
00018 {
00019 }
00020 
00021 FlatPoint OrthoProjection::project(double lat, double lon)
00022 {
00023     lat = rad(lat);
00024     lon = rad(lon);
00025     double x = r * cos(lat) * sin(lon - ln);
00026     double y = r * (cos(lt) * sin(lat) - sin(lt) * cos(lat) * cos(lon - ln));
00027     return FlatPoint(x, y);
00028 }
00029 
00030 geo::Point OrthoProjection::unproject(double x, double y)
00031 {
00032     double ro = sqrt(x * x + y * y);
00033     if (ro == 0)
00034         return geo::Point(deg(lt), deg(ln));
00035     double c = asin(ro / r);
00036     double lat = asin(cos(c) * sin(lt) + (y * sin(c) * cos(lt)) / ro);
00037     double lon = ln + atan2(x * sin(c), ro * cos(lt) * cos(c) - y * sin(lt) * sin(c));
00038     return geo::Point(deg(lat), deg(lon));
00039 }
00040 
00041 OrthoProjection::~OrthoProjection()
00042 {
00043 }
00044 
00045 double OrthoProjection::deg(double rad)
00046 {
00047     return rad * 180.0 / M_PI;
00048 }
00049 
00050 FlatPoint OrthoProjection::project(const geo::Point& p)
00051 {
00052     return MapProjection::project(p);
00053 }
00054 
00055 geo::Point OrthoProjection::unproject(const FlatPoint& p)
00056 {
00057     return MapProjection::unproject(p);
00058 }
00059 
00060 double OrthoProjection::rad(double deg)
00061 {
00062     return deg * M_PI / 180.0;
00063 }
00064 
00065 } /* namespace geo */
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines