Debian Codegraph @

cextern/healpix/src/cxx/cxxsupport/geom_utils.h

raw
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 geom_utils.h
26 * Geometric utility functions.
27 *
28 * Copyright (C) 2003-2016 Max-Planck-Society
29 * \author Martin Reinecke
30 * \author Reinhard Hell
31 */
32
33 #ifndef PLANCK_GEOM_UTILS_H
34 #define PLANCK_GEOM_UTILS_H
35
36 #include <vector>
37 #include "math_utils.h"
38 #include "vec3.h"
39
40 /*! Returns the orientation when looking from point \a loc on the unit
41 sphere in the direction \a dir. \a loc must be normalized. The result
42 ranges from -pi to pi, is 0 for North and pi/2 for West, i.e. the angle
43 is given in mathematically positive sense.
44
45 If \a loc is the North or South pole, the returned angle is
46 \a atan2(dir.y,dir.x). */
47 inline double orientation (const vec3 &loc, const vec3 &dir)
48 {
49 // FIXME: here is still optimization potential
50 if (loc.x==0 && loc.y==0)
51 return (loc.z>0) ? safe_atan2(dir.y,-dir.x) : safe_atan2(dir.y,dir.x);
52 vec3 east (-loc.y, loc.x, 0);
53 vec3 north = crossprod(loc,east);
54 return safe_atan2(-dotprod(dir,east),dotprod(dir,north));
55 }
56
57 /*! Returns the angle between \a v1 and \a v2 in radians. */
58 inline double v_angle (const vec3 &v1, const vec3 &v2)
59 {
60 using namespace std;
61 return atan2 (crossprod(v1,v2).Length(), dotprod(v1,v2));
62 }
63
64 /*! Returns the cosine of the angle between the two points on the sphere defined
65 by (\a z1, \a phi1) and (\a z2, \a phi2), respectively. \a z is the cosine
66 of the colatitude, and \a phi is the longitude. */
67 inline double cosdist_zphi (double z1, double phi1, double z2, double phi2)
68 {
69 using namespace std;
70 return z1*z2+cos(phi1-phi2)*sqrt((1.-z1*z1)*(1.-z2*z2));
71 }
72
73 /*! Finds the smallest enclosing cone for a point set on the sphere according to
74 Barequet & Elber: Information Processing Letters 93(2005), p.83.
75 All points are expected to be passed as unit vectors.
76 The enclosing cone must have an opening angle <pi/2. */
77 void find_enclosing_circle (const std::vector<vec3> &point, vec3 &center,
78 double &cosrad);
79
80 #endif