File indexing completed on 2024-04-14 03:42:34

0001 #ifndef _SpatialVector_h
0002 #define _SpatialVector_h
0003 
0004 //#     Filename:       SpatialVector.h
0005 //#
0006 //#     Standard 3-d vector class
0007 //#
0008 //#     Author:         Peter Z. Kunszt, based on A. Szalay's code
0009 //#
0010 //#     Date:           October 15, 1998
0011 //#
0012 //#     SPDX-FileCopyrightText: 2000 Peter Z. Kunszt Alex S. Szalay, Aniruddha R. Thakar
0013 //#                     The Johns Hopkins University
0014 //#
0015 //#     Modification History:
0016 //#
0017 //#     Oct 18, 2001 : Dennis C. Dinge -- Replaced ValVec with std::vector
0018 //#
0019 
0020 #include <cmath>
0021 #include <SpatialGeneral.h>
0022 
0023 //########################################################################
0024 /**
0025    @class SpatialVector
0026    SpatialVector is a 3D vector usually living on the surface of
0027    the sphere. The corresponding ra, dec can be obtained if the vector
0028    has unit length. That can be ensured with the normalize() function.
0029 
0030 */
0031 
0032 class LINKAGE SpatialVector
0033 {
0034   public:
0035     /// constructs (1,0,0), ra=0, dec=0.
0036     SpatialVector();
0037 
0038     /// Constructor from three coordinates, not necessarily normed to 1
0039     SpatialVector(float64 x, float64 y, float64 z);
0040 
0041     /// Constructor from ra/dec, this is always normed to 1
0042     SpatialVector(float64 ra, float64 dec);
0043 
0044     /// Set member function: set values - always normed to 1
0045     void set(const float64 &x, const float64 &y, const float64 &z);
0046 
0047     /// Set member function: set values - always normed to 1
0048     void set(const float64 &ra, const float64 &dec);
0049 
0050     /// Get x,y,z
0051     void get(float64 &x, float64 &y, float64 &z) const;
0052 
0053     /// Get ra,dec - normalizes x,y,z
0054     void get(float64 &ra, float64 &dec);
0055 
0056     /// return length of vector
0057     float64 length() const;
0058 
0059     /// return x (only as rvalue)
0060     float64 x() const { return x_; }
0061 
0062     /// return y
0063     float64 y() const { return y_; }
0064 
0065     /// return z
0066     float64 z() const { return z_; }
0067 
0068     /// return ra - this norms the vector to 1 if not already done so
0069     float64 ra();
0070 
0071     /// return dec - this norms the vector to 1 if not already done so
0072     float64 dec();
0073 
0074     /// Normalize vector length to 1
0075     void normalize();
0076 
0077     /// Comparison
0078     int operator==(const SpatialVector &) const;
0079 
0080     /// dot product
0081     float64 operator*(const SpatialVector &)const;
0082 
0083     /// cross product
0084     SpatialVector operator^(const SpatialVector &) const;
0085 
0086     /// addition
0087     SpatialVector operator+(const SpatialVector &) const;
0088 
0089     /// subtraction
0090     SpatialVector operator-(const SpatialVector &) const;
0091 
0092     /** @name Scalar products with int and float */
0093     //@{
0094     /** @name operator *= */
0095     SpatialVector &operator*=(float64);
0096     SpatialVector &operator*=(int);
0097     friend SpatialVector operator*(float64, const SpatialVector &);
0098     friend SpatialVector operator*(int, const SpatialVector &);
0099     friend SpatialVector operator*(const SpatialVector &, float64);
0100     friend SpatialVector operator*(const SpatialVector &, int);
0101     //@}
0102 
0103   private:
0104     float64 x_;
0105     float64 y_;
0106     float64 z_;
0107     float64 ra_;
0108     float64 dec_;
0109     bool okRaDec_;
0110 
0111     void updateXYZ();
0112     void updateRaDec();
0113 
0114     friend class SpatialIndex;
0115 };
0116 
0117 // Friend operators
0118 SpatialVector operator*(float64, const SpatialVector &);
0119 SpatialVector operator*(int, const SpatialVector &);
0120 SpatialVector operator*(const SpatialVector &, float64);
0121 SpatialVector operator*(const SpatialVector &, int);
0122 
0123 #endif