| 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 "pointing.h" |
| 33 |
#include "lsconstants.h" |
| 34 |
#include "math_utils.h" |
| 35 |
|
| 36 |
using namespace std; |
| 37 |
|
| 38 |
vec3 pointing::to_vec3() const |
| 39 |
{ |
| 40 |
double st=sin(theta); |
| 41 |
return vec3 (st*cos(phi), st*sin(phi), cos(theta)); |
| 42 |
} |
| 43 |
void pointing::from_vec3 (const vec3 &inp) |
| 44 |
{ |
| 45 |
theta = atan2(sqrt(inp.x*inp.x+inp.y*inp.y),inp.z); |
| 46 |
phi = safe_atan2 (inp.y,inp.x); |
| 47 |
if (phi<0.) phi += twopi; |
| 48 |
} |
| 49 |
void pointing::normalize_theta() |
| 50 |
{ |
| 51 |
theta=fmodulo(theta,twopi); |
| 52 |
if (theta>pi) |
| 53 |
{ |
| 54 |
phi+=pi; |
| 55 |
theta=twopi-theta; |
| 56 |
} |
| 57 |
} |
| 58 |
void pointing::normalize() |
| 59 |
{ |
| 60 |
normalize_theta(); |
| 61 |
phi=fmodulo(phi,twopi); |
| 62 |
} |
| 63 |
|
| 64 |
ostream &operator<< (ostream &os, const pointing &p) |
| 65 |
{ |
| 66 |
os << p.theta << ", " << p.phi << std::endl; |
| 67 |
return os; |
| 68 |
} |