LevelS C++ support library  3.83
pointing.cc
Go to the documentation of this file.
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 
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  }
50  {
51  theta=fmodulo(theta,twopi);
52  if (theta>pi)
53  {
54  phi+=pi;
55  theta=twopi-theta;
56  }
57  }
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  }
T y
Definition: vec3.h:46
T z
Definition: vec3.h:46
void normalize_theta()
Definition: pointing.cc:49
void normalize()
Definition: pointing.cc:58
double phi
Definition: pointing.h:49
double safe_atan2(double y, double x)
Definition: math_utils.h:179
T x
Definition: vec3.h:46
vec3_t< float64 > vec3
Definition: vec3.h:143
Definition: vec3.h:43
vec3 to_vec3() const
Definition: pointing.cc:38
double fmodulo(double v1, double v2)
Definition: math_utils.h:71
double theta
Definition: pointing.h:47
void from_vec3(const vec3 &inp)
Definition: pointing.cc:43

Generated on Wed Nov 13 2024 12:18:16 for LevelS C++ support library