29 #include "Eigen/Geometry" 56 Angle haversine(
Angle const& deltaLon,
Angle const& deltaLat,
double cosLat1,
double cosLat2) {
57 double const sinLat =
sin(deltaLat / 2.0);
58 double const sinLon =
sin(deltaLon / 2.0);
59 double const havDDelta = sinLat * sinLat;
60 double const havDAlpha = sinLon * sinLon;
61 double const havD = havDDelta + cosLat1 * cosLat2 * havDAlpha;
62 double const sinDHalf =
sqrt(havD);
68 :
SpherePoint(longitude * units, latitude * units) {}
71 : _longitude(longitude.
wrap().asRadians()), _latitude(latitude.asRadians()) {
74 " is not a valid latitude.");
84 buffer <<
"Vector " << vector <<
" has zero norm and cannot be normalized.";
100 _latitude =
asin(unitVector.
z());
104 _longitude = (
atan2(unitVector.
y(), unitVector.
x()) *
radians).wrap().asRadians();
128 sin(_longitude) *
cos(_latitude),
sin(_latitude));
151 return _longitude == other._longitude && _latitude == other._latitude;
165 double const y =
sin(deltaLon) * cosDelta2;
166 double const x = cosDelta1 * sinDelta2 - sinDelta1 * cosDelta2 *
cos(deltaLon);
176 auto const rotation = Eigen::AngleAxisd(amount.asRadians(),
asEigen(axis.getVector())).matrix();
178 auto const xprime = rotation *
x;
203 auto v =
cos(phi) * u +
sin(phi) *
w;
218 double const sinDelta1 =
std::sin(delta1);
219 double const cosDelta1 =
std::cos(delta1);
220 double const sinDelta2 =
std::sin(delta2);
221 double const cosDelta2 =
std::cos(delta2);
222 double const cosAlphaDiff =
std::cos(alpha2 - alpha1);
223 double const sinAlphaDiff =
std::sin(alpha2 - alpha1);
225 double const div = cosDelta1 * cosAlphaDiff * cosDelta2 + sinDelta1 * sinDelta2;
226 double const xi = cosDelta1 * sinAlphaDiff / div;
227 double const eta = (cosDelta1 * cosAlphaDiff * sinDelta2 - sinDelta1 * cosDelta2) / div;
233 if (coords.
size() == 0) {
238 for (
auto const& sp : coords) {
239 auto const point = sp.getVector();
241 auto const add = point - corr;
242 auto const temp = sum + add;
243 corr = (temp - sum) - add;
246 sum /=
static_cast<double>(coords.size());
252 auto oldFlags = os.
setf(ostream::fixed);
256 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
table::Key< geom::Angle > longitude
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
Angle getLongitude() const noexcept
The longitude of this point.
Reports attempts to exceed implementation-defined length limits for some classes. ...
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.
Vector3d is a vector in ℝ³ with components stored in double precision.
double sin(Angle const &a)
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.
double cos(Angle const &a)
lsst::afw::geom::SpherePoint SpherePoint
A class representing an angle.
A base class for image defects.
Eigen::Vector3d asEigen(sphgeom::Vector3d const &vector)
Point< double, 2 > Point2D
table::Key< geom::Angle > latitude
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.
#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)
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
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.
Reports invalid arguments.
bool atPole() const noexcept
true if this point is either coordinate pole.
ItemVariant const * other
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
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.
static UnitVector3d fromNormalized(Vector3d const &v)
fromNormalized returns the unit vector equal to v, which is assumed to be normalized.
SpherePoint averageSpherePoint(std::vector< SpherePoint > const &coords)
Return the average of a list of coordinates.
sphgeom::UnitVector3d getVector() const noexcept
A unit vector representation of this point.
double getNorm() const
getNorm returns the L2 norm of this vector.