29 #include "Eigen/Geometry" 55 Angle haversine(
Angle const& deltaLon,
Angle const& deltaLat,
double cosLat1,
double cosLat2) {
56 double const sinLat =
sin(deltaLat / 2.0);
57 double const sinLon =
sin(deltaLon / 2.0);
58 double const havDDelta = sinLat * sinLat;
59 double const havDAlpha = sinLon * sinLon;
60 double const havD = havDDelta + cosLat1 * cosLat2 * havDAlpha;
61 double const sinDHalf =
sqrt(havD);
67 :
SpherePoint(longitude * units, latitude * units) {}
70 : _longitude(longitude.
wrap().asRadians()), _latitude(latitude.asRadians()) {
73 " is not a valid latitude.");
81 buffer <<
"Vector " << vector <<
" has zero norm and cannot be normalized.";
89 double const x = vector.getX() /
norm;
90 double const y = vector.getY() /
norm;
91 double const z = vector.getZ() /
norm;
139 return _longitude == other._longitude && _latitude == other._latitude;
153 double const y =
sin(deltaLon) * cosDelta2;
154 double const x = cosDelta1 * sinDelta2 - sinDelta1 * cosDelta2 *
cos(deltaLon);
164 auto const rotation = Eigen::AngleAxisd(amount.asRadians(), axis.getVector().asEigen()).matrix();
166 auto const xprime = rotation *
x;
189 auto u = Eigen::Vector3d(-
sin(_longitude),
cos(_longitude), 0.0);
191 Eigen::Vector3d v =
cos(phi) * u +
sin(phi) * w;
206 double const sinDelta1 =
std::sin(delta1);
207 double const cosDelta1 =
std::cos(delta1);
208 double const sinDelta2 =
std::sin(delta2);
209 double const cosDelta2 =
std::cos(delta2);
210 double const cosAlphaDiff =
std::cos(alpha2 - alpha1);
211 double const sinAlphaDiff =
std::sin(alpha2 - alpha1);
213 double const div = cosDelta1 * cosAlphaDiff * cosDelta2 + sinDelta1 * sinDelta2;
214 double const xi = cosDelta1 * sinAlphaDiff / div;
215 double const eta = (cosDelta1 * cosAlphaDiff * sinDelta2 - sinDelta1 * cosDelta2) / div;
221 if (coords.
size() == 0) {
226 for (
auto const & sp : coords) {
234 sum.
scale(1.0 / coords.size());
240 auto oldFlags = os.
setf(ostream::fixed);
244 os.
setf(ostream::showpos);
SpherePoint offset(Angle const &bearing, Angle const &amount) const
Return a point offset from this one along a great circle.
Point in an unspecified spherical coordinate system.
bool operator!=(SpherePoint const &other) const noexcept
false if two points represent the same position.
Angle separation(SpherePoint const &other) const noexcept
Angular distance between two points.
lsst::afw::geom::Angle Angle
void scale(double factor)
std::ostream & operator<<(std::ostream &os, SpherePoint const &point)
Print the value of a point to a stream.
AngleUnit constexpr radians
constant with units of radians
A coordinate class intended to represent offsets and dimensions.
Angle getLongitude() const noexcept
The longitude of this point.
AngleUnit constexpr degrees
constant with units of degrees
Point2D getPosition(AngleUnit unit) const
Return longitude, latitude as a Point2D object.
Angle operator[](size_t index) const
Longitude and latitude by index.
ItemVariant const * other
table::Key< geom::Angle > latitude
bool isFinite() const noexcept
true if this point is a well-defined position.
A class used to convert scalar POD types such as double to Angle.
A coordinate class intended to represent absolute positions.
lsst::afw::geom::SpherePoint SpherePoint
EigenVector const & asEigen() const
Return a fixed-size Eigen representation of the coordinate object.
A class representing an angle.
A base class for image defects.
table::Key< geom::Angle > longitude
Point< double, 2 > Point2D
SpherePoint()
Construct a SpherePoint with "nan" for longitude and latitude.
SpherePoint rotated(SpherePoint const &axis, Angle const &amount) const noexcept
Return a point rotated from this one around an axis.
Angle bearingTo(SpherePoint const &other) const
Orientation at this point of the great circle arc to another point.
Angle getLatitude() const noexcept
The latitude of this point.
Extent< double, 3 > Extent3D
#define LSST_EXCEPT(type,...)
constexpr double asRadians() const noexcept
Return an Angle's value in radians.
bool operator==(SpherePoint const &other) const noexcept
true if two points have the same longitude and latitude.
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.
Point3D getVector() const noexcept
A unit vector representation of this point.
constexpr double asDegrees() const noexcept
Return an Angle's value in degrees.
std::pair< Angle, Angle > getTangentPlaneOffset(SpherePoint const &other) const
Get the offset from a tangent plane centered at this point to another point.
Point< double, 3 > Point3D
SpherePoint averageSpherePoint(std::vector< SpherePoint > const &coords)
Return the average of a list of coordinates.