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);
72 " is not a valid latitude.");
82 buffer <<
"Vector " <<
vector <<
" has zero norm and cannot be normalized.";
98 _latitude =
asin(unitVector.
z());
126 sin(_longitude) *
cos(_latitude),
sin(_latitude));
130 return Point2D(getLongitude().asAngularUnits(unit), getLatitude().asAngularUnits(unit));
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);
174 return haversine(getLongitude() - other.getLongitude(), getLatitude() - other.getLatitude(),
175 cos(getLatitude().asRadians()),
cos(other.getLatitude().asRadians()));
179 auto const rotation = Eigen::AngleAxisd(amount.asRadians(),
asEigen(axis.getVector())).matrix();
180 auto const x =
asEigen(getVector());
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);
260 os.
setf(ostream::showpos);
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
table::Key< lsst::geom::Angle > longitude
table::Key< lsst::geom::Angle > latitude
A class representing an angle.
constexpr double asRadians() const noexcept
Return an Angle's value in radians.
constexpr double asDegrees() const noexcept
Return an Angle's value in degrees.
A class used to convert scalar POD types such as double to Angle.
Point in an unspecified spherical coordinate system.
SpherePoint & operator=(SpherePoint const &other) noexcept
Overwrite this object with the value of another SpherePoint.
std::pair< Angle, Angle > getTangentPlaneOffset(SpherePoint const &other) const
Get the offset from a tangent plane centered at this point to another point.
SpherePoint offset(Angle const &bearing, Angle const &amount) const
Return a point offset from this one along a great circle.
bool isFinite() const noexcept
true if this point is a well-defined position.
bool operator!=(SpherePoint const &other) const noexcept
false if two points represent the same position.
Point2D getPosition(AngleUnit unit) const noexcept
Return longitude, latitude as a Point2D object.
Angle bearingTo(SpherePoint const &other) const
Orientation at this point of the great circle arc to another point.
bool atPole() const noexcept
true if this point is either coordinate pole.
Angle separation(SpherePoint const &other) const noexcept
Angular distance between two points.
sphgeom::UnitVector3d getVector() const noexcept
A unit vector representation of this point.
SpherePoint() noexcept
Construct a SpherePoint with "nan" for longitude and latitude.
Angle getLatitude() const noexcept
The latitude of this point.
Angle getLongitude() const noexcept
The longitude of this point.
bool operator==(SpherePoint const &other) const noexcept
true if two points have the same longitude and latitude.
SpherePoint rotated(SpherePoint const &axis, Angle const &amount) const noexcept
Return a point rotated from this one around an axis.
Angle operator[](size_t index) const
Longitude and latitude by index.
std::size_t hash_value() const noexcept
Return a hash of this object.
Reports invalid arguments.
Reports attempts to exceed implementation-defined length limits for some classes.
Reports attempts to access elements outside a valid range of indices.
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
static LonLat fromRadians(double lon, double lat)
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
static UnitVector3d fromNormalized(Vector3d const &v)
fromNormalized returns the unit vector equal to v, which is assumed to be normalized.
Vector3d is a vector in ℝ³ with components stored in double precision.
lsst::geom::SpherePoint SpherePoint
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Eigen::Vector3d asEigen(sphgeom::Vector3d const &vector) noexcept
SpherePoint averageSpherePoint(std::vector< SpherePoint > const &coords)
Return the average of a list of coordinates.
constexpr AngleUnit degrees
constant with units of degrees
std::ostream & operator<<(std::ostream &os, lsst::geom::AffineTransform const &transform)
Point< double, 2 > Point2D
constexpr AngleUnit radians
constant with units of radians
double sin(Angle const &a)
double cos(Angle const &a)
A base class for image defects.