/* -*- C++ -*- * Copyright ©2004 Hugo Mills * * This software is distributed under the terms of the GNU GPL v3 * For more information on the GPL, see the file COPYING or * visit http://www.gnu.org/ * * This software is distributed without warranty */ #include "xfmap_pointprojected.h" extern "C" PluginInfo* getmodules(int i) { if(i==0) { PluginInfo_Map* pi = new PluginInfo_Map(); pi->name = "Point Projected Planar (Stereographic and Gnomonic)"; pi->author = "Hugo Mills"; pi->copyright = "©2005 Hugo Mills"; pi->version = 0x10000; pi->parser = XfMap_PointProjected::parser; return pi; } else return NULL; } XfMap* XfMap_PointProjected::parser( ConfigLexer* lex, const std::string& type, const std::string& subtype ) { if(type == "planar" && subtype == "stereographic") return new XfMap_PointProjected(1.0); if(type == "planar" && subtype == "gnomonic") return new XfMap_PointProjected(0.0); if(type == "planar" && subtype == "point-projected") { double pos = 0.0; while(!lex->eos()) { if(!readkeyedvalue(lex, "projection-centre", &pos)) throw(UnknownConfigToken(lex)); } return new XfMap_PointProjected(pos); } else return NULL; } bool XfMap_PointProjected::f(dvec2& result, const dvec3& pos) const { double m = (proj+1) / (proj+pos[2]); result[0] = pos[0] * m; result[1] = pos[1] * m; return true; } bool XfMap_PointProjected::g(dvec3& result, const dvec2& pos) const { // Ouch // Radius on the projection surface double r2 = pos[0]*pos[0] + pos[1]*pos[1]; double r = sqrt(r2); // Radius from the z-axis on the sphere double s = pp1 + sqrt(r2*q + p12); s /= p12 + r2; // s *= r; -- This is in the equations to give the correct value of s, // however note that you would have to multiply by r to get // the appropriate multiplier for result[0] and [1], so... result[2] = sqrt(1-s*s*r2); result[0] = pos[0] * s; result[1] = pos[1] * s; return true; }