Line data Source code
1 : /* 2 : * This file is part of libcxxsupport. 3 : * 4 : * libcxxsupport is free software; you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation; either version 2 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * libcxxsupport is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with libcxxsupport; if not, write to the Free Software 16 : * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 : */ 18 : 19 : /* 20 : * libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik 21 : * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt 22 : * (DLR). 23 : */ 24 : 25 : /*! \file pointing.cc 26 : * Class representing a direction in 3D space 27 : * 28 : * Copyright (C) 2003-2012 Max-Planck-Society 29 : * \author Martin Reinecke 30 : */ 31 : 32 : #include "healpix_base/pointing.h" 33 : #include "healpix_base/lsconstants.h" 34 : #include "healpix_base/math_utils.h" 35 : 36 : namespace healpix{ 37 : 38 : using namespace std; 39 : 40 0 : vec3 pointing::to_vec3() const 41 : { 42 0 : double st=sin(theta); 43 0 : return vec3 (st*cos(phi), st*sin(phi), cos(theta)); 44 : } 45 0 : void pointing::from_vec3 (const vec3 &inp) 46 : { 47 0 : theta = atan2(sqrt(inp.x*inp.x+inp.y*inp.y),inp.z); 48 0 : phi = safe_atan2 (inp.y,inp.x); 49 0 : if (phi<0.) phi += twopi; 50 0 : } 51 0 : void pointing::normalize_theta() 52 : { 53 0 : theta=fmodulo(theta,twopi); 54 0 : if (theta>pi) 55 : { 56 0 : phi+=pi; 57 0 : theta=twopi-theta; 58 : } 59 0 : } 60 0 : void pointing::normalize() 61 : { 62 0 : normalize_theta(); 63 0 : phi=fmodulo(phi,twopi); 64 0 : } 65 : 66 0 : ostream &operator<< (ostream &os, const pointing &p) 67 : { 68 0 : os << p.theta << ", " << p.phi << std::endl; 69 0 : return os; 70 : } 71 : } // namespace healpix 72 :