1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
#ifndef _SpatialVector_h
#define _SpatialVector_h
//# Filename: SpatialVector.h
//#
//# Standard 3-d vector class
//#
//# Author: Peter Z. Kunszt, based on A. Szalay's code
//#
//# Date: October 15, 1998
//#
//# SPDX-FileCopyrightText: 2000 Peter Z. Kunszt Alex S. Szalay, Aniruddha R. Thakar
//# The Johns Hopkins University
//#
//# Modification History:
//#
//# Oct 18, 2001 : Dennis C. Dinge -- Replaced ValVec with std::vector
//#
#include <cmath>
#include <SpatialGeneral.h>
//########################################################################
/**
@class SpatialVector
SpatialVector is a 3D vector usually living on the surface of
the sphere. The corresponding ra, dec can be obtained if the vector
has unit length. That can be ensured with the normalize() function.
*/
class LINKAGE SpatialVector
{
public:
/// constructs (1,0,0), ra=0, dec=0.
SpatialVector();
/// Constructor from three coordinates, not necessarily normed to 1
SpatialVector(float64 x, float64 y, float64 z);
/// Constructor from ra/dec, this is always normed to 1
SpatialVector(float64 ra, float64 dec);
/// Set member function: set values - always normed to 1
void set(const float64 &x, const float64 &y, const float64 &z);
/// Set member function: set values - always normed to 1
void set(const float64 &ra, const float64 &dec);
/// Get x,y,z
void get(float64 &x, float64 &y, float64 &z) const;
/// Get ra,dec - normalizes x,y,z
void get(float64 &ra, float64 &dec);
/// return length of vector
float64 length() const;
/// return x (only as rvalue)
float64 x() const { return x_; }
/// return y
float64 y() const { return y_; }
/// return z
float64 z() const { return z_; }
/// return ra - this norms the vector to 1 if not already done so
float64 ra();
/// return dec - this norms the vector to 1 if not already done so
float64 dec();
/// Normalize vector length to 1
void normalize();
/// Comparison
int operator==(const SpatialVector &) const;
/// dot product
float64 operator*(const SpatialVector &)const;
/// cross product
SpatialVector operator^(const SpatialVector &) const;
/// addition
SpatialVector operator+(const SpatialVector &) const;
/// subtraction
SpatialVector operator-(const SpatialVector &) const;
/** @name Scalar products with int and float */
//@{
/** @name operator *= */
SpatialVector &operator*=(float64);
SpatialVector &operator*=(int);
friend SpatialVector operator*(float64, const SpatialVector &);
friend SpatialVector operator*(int, const SpatialVector &);
friend SpatialVector operator*(const SpatialVector &, float64);
friend SpatialVector operator*(const SpatialVector &, int);
//@}
private:
float64 x_;
float64 y_;
float64 z_;
float64 ra_;
float64 dec_;
bool okRaDec_;
void updateXYZ();
void updateRaDec();
friend class SpatialIndex;
};
// Friend operators
SpatialVector operator*(float64, const SpatialVector &);
SpatialVector operator*(int, const SpatialVector &);
SpatialVector operator*(const SpatialVector &, float64);
SpatialVector operator*(const SpatialVector &, int);
#endif
|