NASA - Jet Propulsion Laboratory
    + View the NASA Portal
Search JPL
Jet Propulsion Laboratory Home Earth Solar System Stars & Galaxies Technology
Introduction Background Software Links

pointing.h

Go to the documentation of this file.
00001 /*
00002  *  This file is part of Healpix_cxx.
00003  *
00004  *  Healpix_cxx 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  *  Healpix_cxx 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 Healpix_cxx; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  *  For more information about HEALPix, see http://healpix.jpl.nasa.gov
00019  */
00020 
00021 /*
00022  *  Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
00023  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00024  *  (DLR).
00025  */
00026 
00027 /*! \file pointing.h
00028  *  Class representing a direction in 3D space
00029  *
00030  *  Copyright (C) 2003 Max-Planck-Society
00031  *  \author Martin Reinecke
00032  */
00033 
00034 #ifndef PLANCK_POINTING_H
00035 #define PLANCK_POINTING_H
00036 
00037 #include <cmath>
00038 #include "vec3.h"
00039 #include "cxxutils.h"
00040 
00041 /*! \defgroup pointinggroup Pointings */
00042 /*! \{ */
00043 
00044 /*! Class representing a direction in 3D space or a location on the
00045     unit sphere. */
00046 class pointing
00047   {
00048   public:
00049     /*! Colatitude of the pointing (i.e. the North pole is at \a theta=0). */
00050     double theta;
00051     /*! Longitude of the pointing. */
00052     double phi;
00053 
00054     /*! Default constructor. \a theta and \a phi are not initialized. */
00055     pointing() {}
00056     /*! Creates a pointing with \a Theta and \a Phi. */
00057     pointing (double Theta, double Phi) : theta(Theta), phi(Phi) {}
00058 
00059 // FIXME: should become "explicit" some time
00060     /*! Creates a pointing from the vector \a inp. \a inp need not be
00061         normalized. */
00062     pointing (const vec3 &inp)
00063       {
00064       using namespace std;
00065       theta = atan2(sqrt(inp.x*inp.x+inp.y*inp.y),inp.z);
00066       phi = safe_atan2 (inp.y,inp.x);
00067       if (phi<0) phi += twopi;
00068       }
00069 // FIXME: should be removed some time
00070     /*! Returns a normalized vector pointing in the same direction. */
00071     operator vec3() const
00072       {
00073       double st=sin(theta);
00074       return vec3 (st*cos(phi), st*sin(phi), cos(theta));
00075       }
00076     /*! Returns a normalized vector pointing in the same direction. */
00077     vec3 to_vec3() const
00078       {
00079       double st=sin(theta);
00080       return vec3 (st*cos(phi), st*sin(phi), cos(theta));
00081       }
00082     /*! Changes the angles so that \a 0<=theta<=pi and \a 0<=phi<2*pi. */
00083     void normalize()
00084       {
00085       theta=fmodulo(theta,twopi);
00086       if (theta>pi)
00087         {
00088         phi+=pi;
00089         theta=twopi-theta;
00090         }
00091       phi=fmodulo(phi,twopi);
00092       }
00093   };
00094 
00095 /*! Converts \a vec to \a ptg. \a vec need not be normalized.
00096     \relates pointing */
00097 inline void vec2pnt(const vec3 &vec, pointing &ptg)
00098   {
00099   using namespace std;
00100   ptg.theta = atan2(sqrt(vec.x*vec.x+vec.y*vec.y),vec.z);
00101   ptg.phi = safe_atan2 (vec.y,vec.x);
00102   if (ptg.phi<0) ptg.phi += twopi;
00103   }
00104 
00105 /*! Writes \a p to \a os.
00106     \relates pointing */
00107 inline std::ostream &operator<< (std::ostream &os, const pointing &p)
00108   {
00109   os << p.theta << ", " << p.phi << std::endl;
00110   return os;
00111   }
00112 
00113 /*! \} */
00114 
00115 #endif

Generated on Fri Jun 18 16:12:29 2010 for LevelS C++ support library
Privacy / Copyright
FIRST GOV Contact: NASA Home Page Site Manager:
Webmaster:

CL 03-2650