00001 /* 00002 * This file is part of libcxxsupport. 00003 * 00004 * libcxxsupport is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * libcxxsupport is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with libcxxsupport; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00017 */ 00018 00019 /* 00020 * libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik 00021 * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt 00022 * (DLR). 00023 */ 00024 00025 /*! \file pointing.cc 00026 * Class representing a direction in 3D space 00027 * 00028 * Copyright (C) 2003-2012 Max-Planck-Society 00029 * \author Martin Reinecke 00030 */ 00031 00032 #include "pointing.h" 00033 #include "lsconstants.h" 00034 #include "math_utils.h" 00035 00036 using namespace std; 00037 00038 vec3 pointing::to_vec3() const 00039 { 00040 double st=sin(theta); 00041 return vec3 (st*cos(phi), st*sin(phi), cos(theta)); 00042 } 00043 void pointing::from_vec3 (const vec3 &inp) 00044 { 00045 theta = atan2(sqrt(inp.x*inp.x+inp.y*inp.y),inp.z); 00046 phi = safe_atan2 (inp.y,inp.x); 00047 if (phi<0.) phi += twopi; 00048 } 00049 void pointing::normalize_theta() 00050 { 00051 theta=fmodulo(theta,twopi); 00052 if (theta>pi) 00053 { 00054 phi+=pi; 00055 theta=twopi-theta; 00056 } 00057 } 00058 void pointing::normalize() 00059 { 00060 normalize_theta(); 00061 phi=fmodulo(phi,twopi); 00062 } 00063 00064 ostream &operator<< (ostream &os, const pointing &p) 00065 { 00066 os << p.theta << ", " << p.phi << std::endl; 00067 return os; 00068 }