LSST Applications g013ef56533+d2224463a4,g199a45376c+0ba108daf9,g19c4beb06c+9f335b2115,g1fd858c14a+2459ca3e43,g210f2d0738+2d3d333a78,g262e1987ae+abbb004f04,g2825c19fe3+eedc38578d,g29ae962dfc+0cb55f06ef,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+19c3a54948,g47891489e3+501a489530,g4cdb532a89+a047e97985,g511e8cfd20+ce1f47b6d6,g53246c7159+8c5ae1fdc5,g54cd7ddccb+890c8e1e5d,g5fd55ab2c7+951cc3f256,g64539dfbff+2d3d333a78,g67b6fd64d1+501a489530,g67fd3c3899+2d3d333a78,g74acd417e5+0ea5dee12c,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+501a489530,g8d7436a09f+5ea4c44d25,g8ea07a8fe4+81eaaadc04,g90f42f885a+34c0557caf,g9486f8a5af+165c016931,g97be763408+d5e351dcc8,gbf99507273+8c5ae1fdc5,gc2a301910b+2d3d333a78,gca7fc764a6+501a489530,gce8aa8abaa+8c5ae1fdc5,gd7ef33dd92+501a489530,gdab6d2f7ff+0ea5dee12c,ge410e46f29+501a489530,geaed405ab2+e3b4b2a692,gf9a733ac38+8c5ae1fdc5,w.2025.41
LSST Data Management Base Package
Loading...
Searching...
No Matches
NormalizedAngle.cc
Go to the documentation of this file.
1/*
2 * This file is part of sphgeom.
3 *
4 * Developed for the LSST Data Management System.
5 * This product includes software developed by the LSST Project
6 * (http://www.lsst.org).
7 * See the COPYRIGHT file at the top-level directory of this distribution
8 * for details of code ownership.
9 *
10 * This software is dual licensed under the GNU General Public License and also
11 * under a 3-clause BSD license. Recipients may choose which of these licenses
12 * to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
13 * respectively. If you choose the GPL option then the following text applies
14 * (but note that there is still no warranty even if you opt for BSD instead):
15 *
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29
32
34
35#include "lsst/sphgeom/LonLat.h"
37
38
39namespace lsst {
40namespace sphgeom {
41
43 NormalizedAngle const & b)
44{
46 double a1 = std::fabs(a.asRadians() - b.asRadians());
47 double a2 = 2.0 * PI - a1;
48 x._a = Angle(std::min(a1, a2));
49 return x;
50}
51
53 NormalizedAngle const & b)
54{
56 double c = 0.5 * (a.asRadians() + b.asRadians());
57 if (a <= b) {
58 x._a = Angle(c);
59 } else {
60 // The result is (a + b + 2π) / 2, normalized to [0, 2π)
61 x._a = Angle((c < PI) ? (c + PI) : (c - PI));
62 }
63 return x;
64}
65
67 double x = sin((p1.getLon() - p2.getLon()) * 0.5);
68 x *= x;
69 double y = sin((p1.getLat() - p2.getLat()) * 0.5);
70 y *= y;
71 double z = cos((p1.getLat() + p2.getLat()) * 0.5);
72 z *= z;
73 // Compute the square of the sine of half of the desired angle. This is
74 // easily shown to be be one fourth of the squared Euclidian distance
75 // (chord length) between p1 and p2.
76 double sha2 = (x * (z - y) + y);
77 // Avoid domain errors in asin and sqrt due to rounding errors.
78 if (sha2 < 0.0) {
79 _a = Angle(0.0);
80 } else if (sha2 >= 1.0) {
81 _a = Angle(PI);
82 } else {
83 _a = Angle(2.0 * std::asin(std::sqrt(sha2)));
84 }
85}
86
88 double s = v1.cross(v2).getNorm();
89 double c = v1.dot(v2);
90 if (s == 0.0 && c == 0.0) {
91 // Avoid the atan2(±0, -0) = ±PI special case.
92 _a = Angle(0.0);
93 } else {
94 _a = Angle(std::atan2(s, c));
95 }
96}
97
98}} // namespace lsst::sphgeom
This file contains a class representing spherical coordinates.
This file declares a class for representing normalized angles.
This file declares a class for representing vectors in ℝ³.
T asin(T... args)
T atan2(T... args)
Angle represents an angle in radians.
Definition Angle.h:50
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
Definition LonLat.h:55
Angle getLat() const
Definition LonLat.h:97
NormalizedAngle getLon() const
Definition LonLat.h:95
NormalizedAngle()=default
This constructor creates a NormalizedAngle with a value of zero.
static NormalizedAngle between(NormalizedAngle const &a, NormalizedAngle const &b)
For two angles a and b, between(a, b) returns the smaller of a.getAngleTo(b) and b....
static NormalizedAngle center(NormalizedAngle const &a, NormalizedAngle const &b)
For two normalized angles a and b, center(a, b) returns the angle m such that a.getAngleTo(m) is equa...
Vector3d is a vector in ℝ³ with components stored in double precision.
Definition Vector3d.h:51
double dot(Vector3d const &v) const
dot returns the inner product of this vector and v.
Definition Vector3d.h:80
double getNorm() const
getNorm returns the L2 norm of this vector.
Definition Vector3d.h:88
Vector3d cross(Vector3d const &v) const
cross returns the cross product of this vector and v.
Definition Vector3d.h:108
T fabs(T... args)
T min(T... args)
double sin(Angle const &a)
Definition Angle.h:109
double cos(Angle const &a)
Definition Angle.h:110
constexpr double PI
Definition constants.h:43
T sqrt(T... args)