File: geom_utils.h

package info (click to toggle)
healpix-cxx 3.50.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 3,008 kB
  • sloc: cpp: 13,882; ansic: 5,930; sh: 4,451; makefile: 216
file content (80 lines) | stat: -rw-r--r-- 2,912 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 *  This file is part of libcxxsupport.
 *
 *  libcxxsupport is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  libcxxsupport is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with libcxxsupport; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/*
 *  libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik
 *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
 *  (DLR).
 */

/*! \file geom_utils.h
 *  Geometric utility functions.
 *
 *  Copyright (C) 2003-2016 Max-Planck-Society
 *  \author Martin Reinecke
 *  \author Reinhard Hell
 */

#ifndef PLANCK_GEOM_UTILS_H
#define PLANCK_GEOM_UTILS_H

#include <vector>
#include "math_utils.h"
#include "vec3.h"

/*! Returns the orientation when looking from point \a loc on the unit
    sphere in the direction \a dir. \a loc must be normalized. The result
    ranges from -pi to pi, is 0 for North and pi/2 for West, i.e. the angle
    is given in mathematically positive sense.

    If \a loc is the North or South pole, the returned angle is
    \a atan2(dir.y,dir.x). */
inline double orientation (const vec3 &loc, const vec3 &dir)
  {
// FIXME: here is still optimization potential
  if (loc.x==0 && loc.y==0)
    return (loc.z>0) ? safe_atan2(dir.y,-dir.x) : safe_atan2(dir.y,dir.x);
  vec3 east (-loc.y, loc.x, 0);
  vec3 north = crossprod(loc,east);
  return safe_atan2(-dotprod(dir,east),dotprod(dir,north));
  }

/*! Returns the angle between \a v1 and \a v2 in radians. */
inline double v_angle (const vec3 &v1, const vec3 &v2)
  {
  using namespace std;
  return atan2 (crossprod(v1,v2).Length(), dotprod(v1,v2));
  }

/*! Returns the cosine of the angle between the two points on the sphere defined
    by (\a z1, \a phi1) and (\a z2, \a phi2), respectively. \a z is the cosine
    of the colatitude, and \a phi is the longitude. */
inline double cosdist_zphi (double z1, double phi1, double z2, double phi2)
  {
  using namespace std;
  return z1*z2+cos(phi1-phi2)*sqrt((1.-z1*z1)*(1.-z2*z2));
  }

/*! Finds the smallest enclosing cone for a point set on the sphere according to
    Barequet & Elber: Information Processing Letters 93(2005), p.83.
    All points are expected to be passed as unit vectors.
    The enclosing cone must have an opening angle <pi/2. */
void find_enclosing_circle (const std::vector<vec3> &point, vec3 &center,
  double &cosrad);

#endif