lsst.afw  15.0-24-g02ed2a30c+2
SpherePoint.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 /*
4  * LSST Data Management System
5  * See COPYRIGHT file at the top of the source tree.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 #ifndef LSST_AFW_GEOM_SPHEREPOINT_H_
26 #define LSST_AFW_GEOM_SPHEREPOINT_H_
27 
28 #include <cmath>
29 #include <ostream>
30 #include <utility>
31 
33 #include "lsst/sphgeom/Vector3d.h"
34 #include "lsst/afw/geom/Angle.h"
35 #include "lsst/afw/geom/Point.h"
36 
37 namespace lsst {
38 namespace afw {
39 namespace geom {
40 
61 class SpherePoint final {
62 public:
76  SpherePoint(Angle const& longitude, Angle const& latitude);
77 
92  SpherePoint(double longitude, double latitude, AngleUnit units);
93 
109  explicit SpherePoint(sphgeom::Vector3d const& vector);
110 
118  SpherePoint(sphgeom::LonLat const &lonLat);
119 
121  SpherePoint();
122 
130  SpherePoint(SpherePoint const& other) noexcept;
131 
138  SpherePoint(SpherePoint&& other) noexcept;
139 
140  ~SpherePoint();
141 
154  SpherePoint& operator=(SpherePoint const& other) noexcept;
155 
162  SpherePoint& operator=(SpherePoint&& other) noexcept;
163 
167  operator sphgeom::LonLat() const;
168 
169  /*
170  * Accessors
171  */
172 
180  Angle getLongitude() const noexcept { return _longitude * radians; };
181 
183  Angle getRa() const noexcept { return _longitude * radians; };
184 
192  Angle getLatitude() const noexcept { return _latitude * radians; };
193 
195  Angle getDec() const noexcept { return _latitude * radians; };
196 
202  Point2D getPosition(AngleUnit unit) const;
203 
211  sphgeom::UnitVector3d getVector() const noexcept;
212 
227  Angle operator[](size_t index) const;
228 
237  bool atPole() const noexcept {
238  // Unit tests indicate we don't need to worry about epsilon-errors, in that
239  // Objects constructed from lat=90*degrees, <0,0,1>, etc. all have atPole() = true.
240  return fabs(_latitude) >= HALFPI;
241  }
242 
252  bool isFinite() const noexcept;
253 
254  /*
255  * Comparisons between points
256  */
257 
278  bool operator==(SpherePoint const& other) const noexcept;
279 
286  bool operator!=(SpherePoint const& other) const noexcept;
287 
307  Angle bearingTo(SpherePoint const& other) const;
308 
318  Angle separation(SpherePoint const& other) const noexcept;
319 
320  /*
321  * Transformations of points
322  */
323 
335  SpherePoint rotated(SpherePoint const& axis, Angle const& amount) const noexcept;
336 
353  SpherePoint offset(Angle const& bearing, Angle const& amount) const;
354 
364 
365 private:
366  double _longitude; // radians
367  double _latitude; // radians
368 
370  void _set(sphgeom::UnitVector3d const& unitVector);
371 };
372 
381 
382 /*
383  * Object-level display
384  */
385 
407 }
408 }
409 } /* namespace lsst::afw::geom */
410 
411 #endif /* LSST_AFW_GEOM_SPHEREPOINT_H_ */
SpherePoint offset(Angle const &bearing, Angle const &amount) const
Return a point offset from this one along a great circle.
Definition: SpherePoint.cc:182
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:61
bool operator!=(SpherePoint const &other) const noexcept
false if two points represent the same position.
Definition: SpherePoint.cc:154
Angle separation(SpherePoint const &other) const noexcept
Angular distance between two points.
Definition: SpherePoint.cc:170
std::ostream & operator<<(std::ostream &os, SpherePoint const &point)
Print the value of a point to a stream.
Definition: SpherePoint.cc:250
double constexpr HALFPI
Definition: Angle.h:23
AngleUnit constexpr radians
constant with units of radians
Definition: Angle.h:87
Angle getLongitude() const noexcept
The longitude of this point.
Definition: SpherePoint.h:180
Angle getRa() const noexcept
Synonym for getLongitude.
Definition: SpherePoint.h:183
Point2D getPosition(AngleUnit unit) const
Return longitude, latitude as a Point2D object.
Definition: SpherePoint.cc:131
Angle operator[](size_t index) const
Longitude and latitude by index.
Definition: SpherePoint.cc:135
ItemVariant const * other
Definition: Schema.cc:55
table::Key< geom::Angle > latitude
Definition: VisitInfo.cc:165
bool isFinite() const noexcept
true if this point is a well-defined position.
Definition: SpherePoint.cc:146
A class used to convert scalar POD types such as double to Angle.
Definition: Angle.h:52
A class representing an angle.
Definition: Angle.h:102
A base class for image defects.
table::Key< geom::Angle > longitude
Definition: VisitInfo.cc:166
SpherePoint()
Construct a SpherePoint with "nan" for longitude and latitude.
Definition: SpherePoint.cc:110
SpherePoint rotated(SpherePoint const &axis, Angle const &amount) const noexcept
Return a point rotated from this one around an axis.
Definition: SpherePoint.cc:175
Angle bearingTo(SpherePoint const &other) const
Orientation at this point of the great circle arc to another point.
Definition: SpherePoint.cc:156
Angle getLatitude() const noexcept
The latitude of this point.
Definition: SpherePoint.h:192
STL class.
bool operator==(SpherePoint const &other) const noexcept
true if two points have the same longitude and latitude.
Definition: SpherePoint.cc:148
SpherePoint & operator=(SpherePoint const &other) noexcept
Overwrite this object with the value of another SpherePoint.
bool atPole() const noexcept
true if this point is either coordinate pole.
Definition: SpherePoint.h:237
Angle getDec() const noexcept
Synonym for getLatitude.
Definition: SpherePoint.h:195
std::pair< Angle, Angle > getTangentPlaneOffset(SpherePoint const &other) const
Get the offset from a tangent plane centered at this point to another point.
Definition: SpherePoint.cc:211
std::ostream * os
Definition: Schema.cc:736
STL class.
SpherePoint averageSpherePoint(std::vector< SpherePoint > const &coords)
Return the average of a list of coordinates.
Definition: SpherePoint.cc:232
sphgeom::UnitVector3d getVector() const noexcept
A unit vector representation of this point.
Definition: SpherePoint.cc:126