LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+f5613e8b4f,g1470d8bcf6+190ad2ba91,g14a832a312+311607e4ab,g2079a07aa2+86d27d4dc4,g2305ad1205+a8e3196225,g295015adf3+b67ee847e5,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+a761f810f3,g487adcacf7+17c8fdbcbd,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+65b5bd823e,g5a732f18d5+53520f316c,g64a986408d+f5613e8b4f,g6c1bc301e9+51106c2951,g858d7b2824+f5613e8b4f,g8a8a8dda67+585e252eca,g99cad8db69+6729933424,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+ef4e3a5875,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e9bba80f27,gc120e1dc64+eee469a5e5,gc28159a63d+0e5473021a,gcf0d15dbbd+a761f810f3,gdaeeff99f8+f9a426f77a,ge6526c86ff+d4c1d4bfef,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf1cff7945b+f5613e8b4f,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
lsst::sphgeom::UnitVector3d Class Reference

UnitVector3d is a unit vector in ℝ³ with components stored in double precision. More...

#include <UnitVector3d.h>

Public Member Functions

 UnitVector3d ()
 The default constructor creates a unit vector equal to (1, 0, 0).
 
 UnitVector3d (UnitVector3d const &v)=default
 
 UnitVector3d (LonLat const &p)
 This constructor creates the unit vector corresponding to the point p on the unit sphere.
 
 UnitVector3d (Angle lon, Angle lat)
 This constructor creates a unit vector corresponding to the given spherical coordinates.
 
 operator Vector3d const & () const
 This conversion operator returns a const reference to the underlying Vector3d.
 
bool operator== (Vector3d const &v) const
 
bool operator!= (Vector3d const &v) const
 
double const * getData () const
 getData returns a pointer to the 3 components of this unit vector.
 
double operator() (int i) const
 The function call operator returns the i-th component of this vector.
 
double x () const
 
double y () const
 
double z () const
 
double dot (Vector3d const &v) const
 dot returns the inner product of this unit vector and v.
 
Vector3d cross (Vector3d const &v) const
 cross returns the cross product of this unit vector and v.
 
Vector3d robustCross (UnitVector3d const &v) const
 a.robustCross(b) is (b + a).cross(b - a) - twice the cross product of a and b.
 
UnitVector3d operator- () const
 The unary minus operator negates every component of this unit vector.
 
Vector3d operator* (double s) const
 The multiplication operator returns the component-wise product of this unit vector with scalar s.
 
Vector3d operator/ (double s) const
 The division operator returns the component-wise quotient of this unit vector with scalar s.
 
Vector3d operator+ (Vector3d const &v) const
 The addition operator returns the sum of this unit vector and v.
 
Vector3d operator- (Vector3d const &v) const
 The subtraction operator returns the difference between this unit vector and v.
 
Vector3d cwiseProduct (Vector3d const &v) const
 cwiseProduct returns the component-wise product of this unit vector and v.
 
UnitVector3d rotatedAround (UnitVector3d const &k, Angle a) const
 rotatedAround returns a copy of this unit vector, rotated around the unit vector k by angle a according to the right hand rule.
 
 UnitVector3d (Vector3d const &v)
 
 UnitVector3d (double x, double y, double z)
 

Static Public Member Functions

static UnitVector3d orthogonalTo (Vector3d const &v)
 orthogonalTo returns an arbitrary unit vector that is orthogonal to v.
 
static UnitVector3d orthogonalTo (Vector3d const &v1, Vector3d const &v2)
 orthogonalTo returns the unit vector n orthogonal to both v1 and v2 and with the same direction as the cross product of v1 and v2.
 
static UnitVector3d northFrom (Vector3d const &v)
 northFrom returns the unit vector orthogonal to v that points "north" from v.
 
static UnitVector3d orthogonalTo (NormalizedAngle const &a)
 orthogonalTo returns the unit vector orthogonal to the meridian with the given longitude.
 
static UnitVector3d fromNormalized (Vector3d const &v)
 fromNormalized returns the unit vector equal to v, which is assumed to be normalized.
 
static UnitVector3d fromNormalized (double x, double y, double z)
 fromNormalized returns the unit vector with the given components, which are assumed to correspond to those of a normalized vector.
 
static UnitVector3d X ()
 
static UnitVector3d Y ()
 
static UnitVector3d Z ()
 

Detailed Description

UnitVector3d is a unit vector in ℝ³ with components stored in double precision.

Conceptually, a UnitVector3d is a Vector3d. However, it does not inherit from Vector3d because all its mutators must correspond to isometries. Propagating this restriction to the Vector3d base class would make the base class unduly difficult to use. Furthermore, the base class assignment operator would have to be made virtual - otherwise it would be possible to cast a UnitVector3d reference to a Vector3d reference and then assign components yielding non-unit norm. For a class this compact and performance critical, the addition of a vtable pointer per instance and the potential for virtual call overhead on assignment is deemed prohibitive.

This class supports conversion from longitude and latitude angles. All methods that accept a LonLat or equivalent angles shall convert from longitude/latitude to a unit vector according to the following conventions:

Definition at line 62 of file UnitVector3d.h.

Constructor & Destructor Documentation

◆ UnitVector3d() [1/6]

lsst::sphgeom::UnitVector3d::UnitVector3d ( )
inline

The default constructor creates a unit vector equal to (1, 0, 0).

Definition at line 113 of file UnitVector3d.h.

113: _v(1.0, 0.0, 0.0) {}

◆ UnitVector3d() [2/6]

lsst::sphgeom::UnitVector3d::UnitVector3d ( UnitVector3d const & v)
default

◆ UnitVector3d() [3/6]

lsst::sphgeom::UnitVector3d::UnitVector3d ( Vector3d const & v)
inlineexplicit

This constructor creates a unit vector with the given direction.

Definition at line 119 of file UnitVector3d.h.

119 : _v(v) {
120 _v.normalize();
121 }
double normalize()
normalize scales this vector to have unit norm and returns its norm prior to scaling.
Definition Vector3d.cc:48

◆ UnitVector3d() [4/6]

lsst::sphgeom::UnitVector3d::UnitVector3d ( double x,
double y,
double z )
inline

This constructor creates a unit vector with the given direction.

Definition at line 123 of file UnitVector3d.h.

123 : _v(x, y, z) {
124 _v.normalize();
125 }

◆ UnitVector3d() [5/6]

lsst::sphgeom::UnitVector3d::UnitVector3d ( LonLat const & p)
inlineexplicit

This constructor creates the unit vector corresponding to the point p on the unit sphere.

Definition at line 130 of file UnitVector3d.h.

130 {
131 *this = UnitVector3d(p.getLon(), p.getLat());
132 }
UnitVector3d()
The default constructor creates a unit vector equal to (1, 0, 0).

◆ UnitVector3d() [6/6]

lsst::sphgeom::UnitVector3d::UnitVector3d ( Angle lon,
Angle lat )

This constructor creates a unit vector corresponding to the given spherical coordinates.

Definition at line 70 of file UnitVector3d.cc.

70 {
71 double sinLon = sin(lon);
72 double cosLon = cos(lon);
73 double sinLat = sin(lat);
74 double cosLat = cos(lat);
75 _v = Vector3d(cosLon * cosLat,
76 sinLon * cosLat,
77 sinLat);
78}
double sin(Angle const &a)
Definition Angle.h:109
double cos(Angle const &a)
Definition Angle.h:110

Member Function Documentation

◆ cross()

Vector3d lsst::sphgeom::UnitVector3d::cross ( Vector3d const & v) const
inline

cross returns the cross product of this unit vector and v.

Definition at line 162 of file UnitVector3d.h.

162{ return _v.cross(v); }
Vector3d cross(Vector3d const &v) const
cross returns the cross product of this vector and v.
Definition Vector3d.h:108

◆ cwiseProduct()

Vector3d lsst::sphgeom::UnitVector3d::cwiseProduct ( Vector3d const & v) const
inline

cwiseProduct returns the component-wise product of this unit vector and v.

Definition at line 194 of file UnitVector3d.h.

194 {
195 return _v.cwiseProduct(v);
196 }
Vector3d cwiseProduct(Vector3d const &v) const
cwiseProduct returns the component-wise product of this vector and v.
Definition Vector3d.h:157

◆ dot()

double lsst::sphgeom::UnitVector3d::dot ( Vector3d const & v) const
inline

dot returns the inner product of this unit vector and v.

Definition at line 159 of file UnitVector3d.h.

159{ return _v.dot(v); }
double dot(Vector3d const &v) const
dot returns the inner product of this vector and v.
Definition Vector3d.h:80

◆ fromNormalized() [1/2]

static UnitVector3d lsst::sphgeom::UnitVector3d::fromNormalized ( double x,
double y,
double z )
inlinestatic

fromNormalized returns the unit vector with the given components, which are assumed to correspond to those of a normalized vector.

Use with caution - this assumption is not verified!

Definition at line 96 of file UnitVector3d.h.

96 {
97 UnitVector3d u; u._v = Vector3d(x, y, z); return u;
98 }

◆ fromNormalized() [2/2]

static UnitVector3d lsst::sphgeom::UnitVector3d::fromNormalized ( Vector3d const & v)
inlinestatic

fromNormalized returns the unit vector equal to v, which is assumed to be normalized.

Use with caution - this assumption is not verified!

Definition at line 89 of file UnitVector3d.h.

89 {
90 UnitVector3d u; u._v = v; return u;
91 }

◆ getData()

double const * lsst::sphgeom::UnitVector3d::getData ( ) const
inline

getData returns a pointer to the 3 components of this unit vector.

Definition at line 147 of file UnitVector3d.h.

147{ return _v.getData(); }
double const * getData() const
data returns a pointer to the 3 components of this vector.
Definition Vector3d.h:68

◆ northFrom()

UnitVector3d lsst::sphgeom::UnitVector3d::northFrom ( Vector3d const & v)
static

northFrom returns the unit vector orthogonal to v that points "north" from v.

More precisely, it returns a unit vector orthogonal to v that lies in the plane defined by v, the north pole (0, 0, 1), and the origin. If v is colinear with the z axis, then (-1, 0, 0) is returned if v points north, and (1, 0, 0) is returned if v points south.

Definition at line 58 of file UnitVector3d.cc.

58 {
59 Vector3d n(-v.x() * v.z(),
60 -v.y() * v.z(),
61 v.x() * v.x() + v.y() * v.y());
62 if (n.isZero()) {
63 UnitVector3d u;
64 u._v = Vector3d(-::copysign(1.0, v.z()), 0.0, 0.0);
65 return u;
66 }
67 return UnitVector3d(n);
68}

◆ operator Vector3d const &()

lsst::sphgeom::UnitVector3d::operator Vector3d const & ( ) const
inline

This conversion operator returns a const reference to the underlying Vector3d.

It allows a UnitVector3d to transparently replace a Vector3d as an argument in most function calls.

Definition at line 141 of file UnitVector3d.h.

141{ return _v; }

◆ operator!=()

bool lsst::sphgeom::UnitVector3d::operator!= ( Vector3d const & v) const
inline

Definition at line 144 of file UnitVector3d.h.

144{ return _v != v; }

◆ operator()()

double lsst::sphgeom::UnitVector3d::operator() ( int i) const
inline

The function call operator returns the i-th component of this vector.

Definition at line 150 of file UnitVector3d.h.

150{ return _v(i); }

◆ operator*()

Vector3d lsst::sphgeom::UnitVector3d::operator* ( double s) const
inline

The multiplication operator returns the component-wise product of this unit vector with scalar s.

Definition at line 179 of file UnitVector3d.h.

179{ return _v * s; }

◆ operator+()

Vector3d lsst::sphgeom::UnitVector3d::operator+ ( Vector3d const & v) const
inline

The addition operator returns the sum of this unit vector and v.

Definition at line 186 of file UnitVector3d.h.

186{ return _v + v; }

◆ operator-() [1/2]

UnitVector3d lsst::sphgeom::UnitVector3d::operator- ( ) const
inline

The unary minus operator negates every component of this unit vector.

Definition at line 173 of file UnitVector3d.h.

173 {
174 UnitVector3d u; u._v = -_v; return u;
175 }

◆ operator-() [2/2]

Vector3d lsst::sphgeom::UnitVector3d::operator- ( Vector3d const & v) const
inline

The subtraction operator returns the difference between this unit vector and v.

Definition at line 190 of file UnitVector3d.h.

190{ return _v - v; }

◆ operator/()

Vector3d lsst::sphgeom::UnitVector3d::operator/ ( double s) const
inline

The division operator returns the component-wise quotient of this unit vector with scalar s.

Definition at line 183 of file UnitVector3d.h.

183{ return _v / s; }

◆ operator==()

bool lsst::sphgeom::UnitVector3d::operator== ( Vector3d const & v) const
inline

Definition at line 143 of file UnitVector3d.h.

143{ return _v == v; }

◆ orthogonalTo() [1/3]

static UnitVector3d lsst::sphgeom::UnitVector3d::orthogonalTo ( NormalizedAngle const & a)
inlinestatic

orthogonalTo returns the unit vector orthogonal to the meridian with the given longitude.

Definition at line 83 of file UnitVector3d.h.

83 {
84 UnitVector3d u; u._v = Vector3d(-sin(a), cos(a), 0.0); return u;
85 }

◆ orthogonalTo() [2/3]

UnitVector3d lsst::sphgeom::UnitVector3d::orthogonalTo ( Vector3d const & v)
static

orthogonalTo returns an arbitrary unit vector that is orthogonal to v.

Definition at line 41 of file UnitVector3d.cc.

41 {
42 if (std::fabs(v.x()) > std::fabs(v.y())) {
43 return UnitVector3d(-v.z(), 0.0, v.x());
44 }
45 return UnitVector3d(0.0, v.z(), -v.y());
46}
T fabs(T... args)

◆ orthogonalTo() [3/3]

UnitVector3d lsst::sphgeom::UnitVector3d::orthogonalTo ( Vector3d const & v1,
Vector3d const & v2 )
static

orthogonalTo returns the unit vector n orthogonal to both v1 and v2 and with the same direction as the cross product of v1 and v2.

If v1 and v2 are nearly (anti)parallel, then an arbitrary unit vector orthogonal to v1 is returned.

Definition at line 48 of file UnitVector3d.cc.

50{
51 Vector3d n = (v2 + v1).cross(v2 - v1);
52 if (n.isZero()) {
53 return orthogonalTo(v1);
54 }
55 return UnitVector3d(n);
56}
static UnitVector3d orthogonalTo(Vector3d const &v)
orthogonalTo returns an arbitrary unit vector that is orthogonal to v.
Vector3d cross(Vector3d const &v) const
cross returns the cross product of this unit vector and v.

◆ robustCross()

Vector3d lsst::sphgeom::UnitVector3d::robustCross ( UnitVector3d const & v) const
inline

a.robustCross(b) is (b + a).cross(b - a) - twice the cross product of a and b.

The result is almost orthogonal to a and b even for nearly (anti-)parallel unit vectors. The idea comes from the Google S2 library.

Definition at line 168 of file UnitVector3d.h.

168 {
169 return (v + *this).cross(v - *this);
170 }

◆ rotatedAround()

UnitVector3d lsst::sphgeom::UnitVector3d::rotatedAround ( UnitVector3d const & k,
Angle a ) const
inline

rotatedAround returns a copy of this unit vector, rotated around the unit vector k by angle a according to the right hand rule.

Definition at line 200 of file UnitVector3d.h.

200 {
201 return UnitVector3d(_v.rotatedAround(k, a));
202 }
Vector3d rotatedAround(UnitVector3d const &k, Angle a) const
rotatedAround returns a copy of this vector, rotated around the unit vector k by angle a according to...
Definition Vector3d.cc:132

◆ X()

static UnitVector3d lsst::sphgeom::UnitVector3d::X ( )
inlinestatic

Definition at line 100 of file UnitVector3d.h.

100 {
101 return UnitVector3d();
102 }

◆ x()

double lsst::sphgeom::UnitVector3d::x ( ) const
inline

Definition at line 152 of file UnitVector3d.h.

152{ return _v.x(); }
double x() const
Definition Vector3d.h:73

◆ Y()

static UnitVector3d lsst::sphgeom::UnitVector3d::Y ( )
inlinestatic

Definition at line 104 of file UnitVector3d.h.

104 {
105 UnitVector3d u; u._v = Vector3d(0.0, 1.0, 0.0); return u;
106 }

◆ y()

double lsst::sphgeom::UnitVector3d::y ( ) const
inline

Definition at line 154 of file UnitVector3d.h.

154{ return _v.y(); }
double y() const
Definition Vector3d.h:75

◆ Z()

static UnitVector3d lsst::sphgeom::UnitVector3d::Z ( )
inlinestatic

Definition at line 108 of file UnitVector3d.h.

108 {
109 UnitVector3d u; u._v = Vector3d(0.0, 0.0, 1.0); return u;
110 }

◆ z()

double lsst::sphgeom::UnitVector3d::z ( ) const
inline

Definition at line 156 of file UnitVector3d.h.

156{ return _v.z(); }
double z() const
Definition Vector3d.h:77

The documentation for this class was generated from the following files: