26 #include "Eigen/Geometry" 53 Angle haversine(
Angle const& deltaLon,
Angle const& deltaLat,
double cosLat1,
double cosLat2) {
54 double const sinLat =
sin(deltaLat / 2.0);
55 double const sinLon =
sin(deltaLon / 2.0);
56 double const havDDelta = sinLat * sinLat;
57 double const havDAlpha = sinLon * sinLon;
58 double const havD = havDDelta + cosLat1 * cosLat2 * havDAlpha;
59 double const sinDHalf =
sqrt(havD);
65 :
SpherePoint(longitude * units, latitude * units) {}
68 : _longitude(longitude.
wrap().asRadians()), _latitude(latitude.asRadians()) {
71 " is not a valid latitude.");
81 buffer <<
"Vector " << vector <<
" has zero norm and cannot be normalized.";
97 _latitude =
asin(unitVector.
z());
101 _longitude = (
atan2(unitVector.
y(), unitVector.
x()) *
radians).wrap().asRadians();
125 sin(_longitude) *
cos(_latitude),
sin(_latitude));
148 return _longitude == other._longitude && _latitude == other._latitude;
162 double const y =
sin(deltaLon) * cosDelta2;
163 double const x = cosDelta1 * sinDelta2 - sinDelta1 * cosDelta2 *
cos(deltaLon);
173 auto const rotation = Eigen::AngleAxisd(amount.asRadians(),
asEigen(axis.getVector())).matrix();
175 auto const xprime = rotation *
x;
200 auto v =
cos(phi) * u +
sin(phi) *
w;
215 double const sinDelta1 =
std::sin(delta1);
216 double const cosDelta1 =
std::cos(delta1);
217 double const sinDelta2 =
std::sin(delta2);
218 double const cosDelta2 =
std::cos(delta2);
219 double const cosAlphaDiff =
std::cos(alpha2 - alpha1);
220 double const sinAlphaDiff =
std::sin(alpha2 - alpha1);
222 double const div = cosDelta1 * cosAlphaDiff * cosDelta2 + sinDelta1 * sinDelta2;
223 double const xi = cosDelta1 * sinAlphaDiff / div;
224 double const eta = (cosDelta1 * cosAlphaDiff * sinDelta2 - sinDelta1 * cosDelta2) / div;
230 if (coords.
size() == 0) {
235 for (
auto const& sp : coords) {
236 auto const point = sp.getVector();
238 auto const add = point - corr;
239 auto const temp = sum + add;
240 corr = (temp - sum) - add;
243 sum /=
static_cast<double>(coords.size());
249 auto oldFlags = os.
setf(ostream::fixed);
253 os.
setf(ostream::showpos);
bool operator==(SpherePoint const &other) const noexcept
true if two points have the same longitude and latitude.
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.
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
ItemVariant const * other
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.
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.