casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MVPosition.h
Go to the documentation of this file.
1 //# MVPosition.h: A 3D vector in space
2 //# Copyright (C) 1996,1997,1998,1999,2000,2001
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef CASA_MVPOSITION_H
29 #define CASA_MVPOSITION_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
38 #include <casacore/casa/iosfwd.h>
39 
40 namespace casacore { //# NAMESPACE CASACORE - BEGIN
41 
42 //# Forward Declarations
43 class RotMatrix;
44 
45 //# Constants (SUN compiler does not accept non-simple default arguments)
46 
47 // <summary> A 3D vector in space </summary>
48 
49 // <use visibility=export>
50 
51 // <reviewed reviewer="tcornwel" date="1996/02/22" tests="tMeasMath" demos="">
52 // </reviewed>
53 
54 // <prerequisite>
55 // <li> <linkto class=MeasValue>MeasValue</linkto>
56 // <li> <linkto class=Vector>Vector</linkto>
57 // <li> <linkto class=Quantum>Quantum</linkto>
58 // </prerequisite>
59 //
60 // <etymology>
61 // From Measure, Value and Position
62 // </etymology>
63 //
64 // <synopsis>
65 // A MVPosition is a 3-vector of positions in a rectangular frame with
66 // internal units of m.<br>
67 // It can be constructed with:
68 // <ul>
69 // <li> MVPosition() creates point at origin (0,0,0)
70 // <li> MVPosition(MVPosition) creates a copy
71 // <li> MVPosition(Double, Double, Double) creates (x,y,z) with
72 // specified values
73 // <li> MVPosition(Quantity length,Double, Double) creates a MVPosition assuming
74 // that the two values are (in radians) angle along 'equator'
75 // and towards 'pole'. A length of zero will be made 1um.
76 // <li> MVPosition(Quantity length, Quantity, Quantity) creates a MVPosition
77 // assuming angles as in previous, or positions
78 // <li> <src>MVPosition(Quantity, Quantum<Vector<Double> >)</src> creates a
79 // MVPosition from angle vector, using first two angles, and
80 // assuming second as zero if not present, and pole if length 0.
81 // <li> <src>MVPosition(Quantum<Vector<Double> ></src> creates from
82 // angles or positions, depending on the units in the
83 // quantum vector. In the angle case,
84 // the data derived can be scaled with the readjust() function. If
85 // the unit of the quantum vector is length, position is
86 // assumed.
87 // <li> <src>MVPosition(Vector<Double></src> creates from angles (less than
88 // or equal to two elements) or x,y,z (3 elements).
89 // <li> <src>MVPosition(Vector<Quantity></src> creates from length+angles,
90 // angles, or x,y,z, depending on units.
91 // </ul>
92 // A void adjust(Double) function normalises the vector to a length of 1;
93 // a get() returns as a
94 // Double 3-vector the length and angles of the position vector;
95 // a getAngle() returns a Quantum 2-vector, (uInt) returns the indicated
96 // element, and getValue returns the vector.<br>
97 // Positions can be added and subtracted.<br>
98 // The multiplication of two positions produces the in-product.<br>
99 // </synopsis>
100 //
101 // <example>
102 // See <linkto class=MPosition>Mposition</linkto> class.
103 // </example>
104 //
105 // <motivation>
106 // To do coordinate transformations
107 // </motivation>
108 //
109 // <todo asof="1996/02/04">
110 // <li> See if not better to have a direction + length
111 // </todo>
112 
113 class MVPosition : public MeasValue {
114 
115 public:
116  //# Constants
117  // Internal limts codes for negative height
118  // <group>
119  static const Double loLimit;
120  static const Double hiLimit;
121  // </group>
122  //# Friends
123 
124  //# Constructors
125  // Default constructor generates a (0,0,0) position
126  MVPosition();
127  // Copy constructor
128  MVPosition(const MVPosition &other);
129  // Creates a specified vector
130  MVPosition(Double in0, Double in1, Double in2);
131  // Creates a vector with specified length towards pole
132  // <group>
133  explicit MVPosition(Double in0);
134  MVPosition(const Quantity &l);
135  // </group>
136  // Creates the position from specified (azimuth,elevation) angles and length
137  MVPosition(const Quantity &l, Double angle0, Double angle1);
138  // Creates the position from specified angles and length. or positions
139  // <thrown>
140  // <li> AipsError if quantities not in angle format
141  // </thrown>
142  // <group>
143  MVPosition(const Quantity &l, const Quantity &angle0,
144  const Quantity &angle1);
145  // If not enough angles: pole assumed (if none), or elevation =0 (if 1)
146  MVPosition(const Quantum<Vector<Double> > &angle);
147  MVPosition(const Quantity &l, const Quantum<Vector<Double> > &angle);
148  // </group>
149  // Create from specified length and/or angles and/or position
150  // <group>
151  explicit MVPosition(const Vector<Double> &other);
152  MVPosition(const Vector<Quantity> &other);
153  // </group>
154  // Copy assignment
155  MVPosition &operator=(const MVPosition &other);
156 
157  // Destructor
158  virtual ~MVPosition();
159 
160  //# Operators
161  // Multiplication defined as in-product
162  // <group>
163  Double operator*(const MVPosition &other) const;
164  // </group>
165 
166  // Equality comparisons
167  // <group>
168  Bool operator== (const MVPosition &other) const;
169  Bool operator!= (const MVPosition &other) const;
170  Bool near(const MVPosition &other, Double tol=1e-13) const;
171  Bool near(const MVPosition &other, Quantity tol) const;
172  Bool nearAbs(const MVPosition &other, Double tol=1e-13) const;
173  // </group>
174 
175  // Addition and subtraction
176  // <group>
177  MVPosition operator-() const;
178  MVPosition &operator+=(const MVPosition &right);
179  MVPosition operator+(const MVPosition &right) const;
180  MVPosition &operator-=(const MVPosition &right);
181  MVPosition operator-(const MVPosition &right) const;
182  // </group>
183 
184  // Multiplication with rotation matrix (see also global functions)
185  // <group>
186  MVPosition &operator*=(const RotMatrix &right);
187  // </group>
188 
189  // Multiplication with constant
190  // <group>
191  MVPosition &operator*=(Double right);
192  // </group>
193 
194  // Obtain an element
195  // <group>
196  Double &operator()(uInt which);
197  const Double &operator()(uInt which) const;
198  // </group>
199 
200  //# General Member Functions
201 
202  // Tell me your type
203  // <group>
204  static void assure(const MeasValue &in);
205  // </group>
206 
207  // Normalise direction aspects by adjusting the length to 1
208  // <group>
209  // For position no adjustment; for direction adjustment
210  virtual void adjust();
211  // Adjustment with returned factor
212  virtual void adjust(Double &res);
213  // Re-adjust using factor given
214  virtual void readjust(Double res);
215  // </group>
216  // Get radius of position
217  virtual Double radius();
218  // Generate a 3-vector of coordinates (length(m), angles(rad))
219  Vector<Double> get() const;
220  // Generate a 3-vector of x,y,z in m
221  const Vector<Double> &getValue() const;
222  // Generate angle 2-vector (in rad)
224  // and with specified units
225  Quantum<Vector<Double> > getAngle(const Unit &unit) const;
226  // Get the longitudinal angle (in radians)
227  Double getLong() const;
228  // and with specified units
229  Quantity getLong(const Unit &unit) const;
230  // Get the latitude angle (rad)
231  Double getLat() const;
232  // and with specified units
233  Quantity getLat(const Unit &unit) const;
234  // Generate the length
235  Quantity getLength() const;
236  // and generate it with the specified units
237  Quantity getLength(const Unit &unit) const;
238  // Get the position angle between the directions. I.e. the angle between
239  // the direction from one to the pole, and from one to the other.
240  // <group>
241  Double positionAngle(const MVPosition &other) const;
242  Quantity positionAngle(const MVPosition &other,
243  const Unit &unit) const;
244  // </group>
245  // Get the angular separation between two directions.
246  // <group>
247  Double separation(const MVPosition &other) const;
248  Quantity separation(const MVPosition &other,
249  const Unit &unit) const;
250  // </group>
251  // Produce the cross product
252  MVPosition crossProduct(const MVPosition &other) const;
253 
254  // Print data
255  virtual void print(ostream &os) const;
256  // Clone
257  virtual MeasValue *clone() const;
258 
259  // Get the value in internal units
260  virtual Vector<Double> getVector() const;
261  // Set the value from internal units (set 0 for empty vector)
262  virtual void putVector(const Vector<Double> &in);
263  // Get the internal value as a <src>Vector<Quantity></src>. Usable in
264  // records. The getXRecordValue() gets additional information for records.
265  // Note that the Vectors could be empty.
266  // <group>
267  virtual Vector<Quantum<Double> > getRecordValue() const;
268  virtual Vector<Quantum<Double> > getXRecordValue() const;
270  return getXRecordValue(); } ;
271  // </group>
272  // Set the internal value if correct values and dimensions
273  virtual Bool putValue(const Vector<Quantum<Double> > &in);
274 
275 protected:
276  //# Member functions
277  // Get the latitude assuming length is given
278  Double getLat(Double ln) const;
279  //# Data
280  // Position vector (in m)
282 };
283 
284 //# Global functions
285 // Rotate a position vector with rotation matrix and other multiplications
286 // <group>
287 MVPosition operator*(const RotMatrix &left, const MVPosition &right);
288 MVPosition operator*(const MVPosition &left, const RotMatrix &right);
289 MVPosition operator*(Double left, const MVPosition &right);
290 MVPosition operator*(const MVPosition &left, Double right);
291 Double operator*(const Vector<Double> &left, const MVPosition &right);
292 Double operator*(const MVPosition &left, const Vector<Double> &right);
293 // </group>
294 
295 
296 } //# NAMESPACE CASACORE - END
297 
298 #endif
virtual Double radius()
Get radius of position.
MVPosition & operator+=(const MVPosition &right)
virtual Vector< Double > getVector() const
Get the value in internal units.
virtual MeasValue * clone() const
Clone.
Double & operator()(uInt which)
Obtain an element.
Bool nearAbs(const MVPosition &other, Double tol=1e-13) const
virtual void adjust()
Normalise direction aspects by adjusting the length to 1.
virtual Vector< Quantum< Double > > getRecordValue() const
Get the internal value as a Vector&lt;Quantity&gt;.
virtual Vector< Quantum< Double > > getTMRecordValue() const
Definition: MVPosition.h:269
Double positionAngle(const MVPosition &other) const
Get the position angle between the directions.
virtual Bool putValue(const Vector< Quantum< Double > > &in)
Set the internal value if correct values and dimensions.
virtual void print(ostream &os) const
Print data.
Bool near(const MVPosition &other, Double tol=1e-13) const
Double getLat() const
Get the latitude angle (rad)
static void assure(const MeasValue &in)
Tell me your type.
Bool operator!=(const MVPosition &other) const
Vector< Double > xyz
Position vector (in m)
Definition: MVPosition.h:281
virtual ~MVPosition()
Destructor.
A 3x3 rotation matrix.
Definition: RotMatrix.h:85
Double separation(const MVPosition &other) const
Get the angular separation between two directions.
defines physical units
Definition: Unit.h:189
MVPosition & operator*=(const RotMatrix &right)
Multiplication with rotation matrix (see also global functions)
MVPosition()
Default constructor generates a (0,0,0) position.
Base class for values in a Measure.
Definition: MeasValue.h:107
double Double
Definition: aipstype.h:55
virtual Vector< Quantum< Double > > getXRecordValue() const
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
A 3D vector in space.
Definition: MVPosition.h:113
Double getLong() const
Get the longitudinal angle (in radians)
virtual void putVector(const Vector< Double > &in)
Set the value from internal units (set 0 for empty vector)
MVPosition crossProduct(const MVPosition &other) const
Produce the cross product.
const Double e
e and functions thereof:
Quantity getLength() const
Generate the length.
static const Double hiLimit
Definition: MVPosition.h:120
virtual void readjust(Double res)
Re-adjust using factor given.
const Vector< Double > & getValue() const
Generate a 3-vector of x,y,z in m.
MVPosition operator-() const
Addition and subtraction.
MVPosition operator+(const MVPosition &right) const
Bool operator==(const MVPosition &other) const
Equality comparisons.
MVPosition & operator-=(const MVPosition &right)
MVPosition & operator=(const MVPosition &other)
Copy assignment.
Double operator*(const MVPosition &other) const
Multiplication defined as in-product.
MVBaseline operator*(const RotMatrix &left, const MVBaseline &right)
Rotate a Baseline vector with rotation matrix and other multiplications.
unsigned int uInt
Definition: aipstype.h:51
static const Double loLimit
Internal limts codes for negative height.
Definition: MVPosition.h:119
Quantum< Vector< Double > > getAngle() const
Generate angle 2-vector (in rad)