26 #include "Eigen/Geometry" 54 Angle haversine(
Angle const& deltaLon,
Angle const& deltaLat,
double cosLat1,
double cosLat2) {
55 double const sinLat =
sin(deltaLat / 2.0);
56 double const sinLon =
sin(deltaLon / 2.0);
57 double const havDDelta = sinLat * sinLat;
58 double const havDAlpha = sinLon * sinLon;
59 double const havD = havDDelta + cosLat1 * cosLat2 * havDAlpha;
60 double const sinDHalf =
sqrt(havD);
66 :
SpherePoint(longitude * units, latitude * units) {}
69 : _longitude(longitude.
wrap().asRadians()), _latitude(latitude.asRadians()) {
72 " is not a valid latitude.");
82 buffer <<
"Vector " << vector <<
" has zero norm and cannot be normalized.";
98 _latitude =
asin(unitVector.
z());
102 _longitude = (
atan2(unitVector.
y(), unitVector.
x()) *
radians).wrap().asRadians();
126 sin(_longitude) *
cos(_latitude),
sin(_latitude));
149 return _longitude == other._longitude && _latitude == other._latitude;
168 double const y =
sin(deltaLon) * cosDelta2;
169 double const x = cosDelta1 * sinDelta2 - sinDelta1 * cosDelta2 *
cos(deltaLon);
179 auto const rotation = Eigen::AngleAxisd(amount.asRadians(),
asEigen(axis.getVector())).matrix();
181 auto const xprime = rotation *
x;
206 auto v =
cos(phi) * u +
sin(phi) *
w;
221 double const sinDelta1 =
std::sin(delta1);
222 double const cosDelta1 =
std::cos(delta1);
223 double const sinDelta2 =
std::sin(delta2);
224 double const cosDelta2 =
std::cos(delta2);
225 double const cosAlphaDiff =
std::cos(alpha2 - alpha1);
226 double const sinAlphaDiff =
std::sin(alpha2 - alpha1);
228 double const div = cosDelta1 * cosAlphaDiff * cosDelta2 + sinDelta1 * sinDelta2;
229 double const xi = cosDelta1 * sinAlphaDiff / div;
230 double const eta = (cosDelta1 * cosAlphaDiff * sinDelta2 - sinDelta1 * cosDelta2) / div;
236 if (coords.
size() == 0) {
241 for (
auto const& sp : coords) {
242 auto const point = sp.getVector();
244 auto const add = point - corr;
245 auto const temp = sum + add;
246 corr = (temp - sum) - add;
249 sum /=
static_cast<double>(coords.size());
255 auto oldFlags = os.
setf(ostream::fixed);
259 os.
setf(ostream::showpos);
bool operator==(SpherePoint const &other) const noexcept
true if two points have the same longitude and latitude.
std::size_t hash_value() const noexcept
Return a hash of this object.
bool isFinite() const noexcept
true if this point is a well-defined position.
std::pair< Angle, Angle > getTangentPlaneOffset(SpherePoint const &other) const
Get the offset from a tangent plane centered at this point to another point.
table::Key< lsst::geom::Angle > latitude
Angle bearingTo(SpherePoint const &other) const
Orientation at this point of the great circle arc to another point.
constexpr double asRadians() const noexcept
Return an Angle's value in radians.
constexpr double asDegrees() const noexcept
Return an Angle's value in degrees.
Point2D getPosition(AngleUnit unit) const noexcept
Return longitude, latitude as a Point2D object.
Reports attempts to exceed implementation-defined length limits for some classes. ...
Angle getLongitude() const noexcept
The longitude of this point.
SpherePoint rotated(SpherePoint const &axis, Angle const &amount) const noexcept
Return a point rotated from this one around an axis.
sphgeom::UnitVector3d getVector() const noexcept
A unit vector representation of this point.
ItemVariant const * other
Vector3d is a vector in ℝ³ with components stored in double precision.
double sin(Angle const &a)
AngleUnit constexpr radians
constant with units of radians
A class representing an angle.
Angle operator[](size_t index) const
Longitude and latitude by index.
std::ostream & operator<<(std::ostream &os, SpherePoint const &point)
Print the value of a point to a stream.
Point< double, 2 > Point2D
double cos(Angle const &a)
SpherePoint() noexcept
Construct a SpherePoint with "nan" for longitude and latitude.
AngleUnit constexpr degrees
constant with units of degrees
A base class for image defects.
Angle separation(SpherePoint const &other) const noexcept
Angular distance between two points.
Angle getLatitude() const noexcept
The latitude of this point.
SpherePoint offset(Angle const &bearing, Angle const &amount) const
Return a point offset from this one along a great circle.
Eigen::Vector3d asEigen(sphgeom::Vector3d const &vector) noexcept
table::Key< lsst::geom::Angle > longitude
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Reports attempts to access elements outside a valid range of indices.
static LonLat fromRadians(double lon, double lat)
SpherePoint & operator=(SpherePoint const &other) noexcept
Overwrite this object with the value of another SpherePoint.
Point in an unspecified spherical coordinate system.
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
bool atPole() const noexcept
true if this point is either coordinate pole.
Reports invalid arguments.
lsst::geom::SpherePoint SpherePoint
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
bool operator!=(SpherePoint const &other) const noexcept
false if two points represent the same position.
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
static UnitVector3d fromNormalized(Vector3d const &v)
fromNormalized returns the unit vector equal to v, which is assumed to be normalized.
A class used to convert scalar POD types such as double to Angle.
SpherePoint averageSpherePoint(std::vector< SpherePoint > const &coords)
Return the average of a list of coordinates.
double getNorm() const
getNorm returns the L2 norm of this vector.