| 1 | // 3-D Geometry
|
|---|
| 2 | // B. Revenu, G. Le Meur 2000
|
|---|
| 3 | // R. Ansari (documentation 2006)
|
|---|
| 4 | // DAPNIA/SPP (Saclay) / CEA LAL - IN2P3/CNRS (Orsay)
|
|---|
| 5 |
|
|---|
| 6 | #include <math.h>
|
|---|
| 7 | #include "sopnamsp.h"
|
|---|
| 8 | #include "unitvector.h"
|
|---|
| 9 |
|
|---|
| 10 | /*!
|
|---|
| 11 | \class SOPHYA::UnitVector
|
|---|
| 12 | \ingroup SkyMap
|
|---|
| 13 | \brief Specialisation of Vector3d class for representing unit (length=1) 3-vectors.
|
|---|
| 14 | */
|
|---|
| 15 |
|
|---|
| 16 | //! Default constructor : unit vector in the x direction
|
|---|
| 17 | UnitVector::UnitVector() : Vector3d(1.,0.,0.)
|
|---|
| 18 | {
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | //! Constructor: Unit vector along the x,y,z cartesian coordinates
|
|---|
| 22 | UnitVector::UnitVector(double x, double y, double z) : Vector3d(x,y,z)
|
|---|
| 23 | {
|
|---|
| 24 | this->Normalize();
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | //! Constructor: Unit vector along the theta,phi direction (spherical coordinates)
|
|---|
| 28 | UnitVector::UnitVector(double theta, double phi) : Vector3d(theta,phi)
|
|---|
| 29 | {
|
|---|
| 30 | this->Normalize();
|
|---|
| 31 | }
|
|---|
| 32 | //! copy constructor
|
|---|
| 33 | UnitVector::UnitVector(const Vector3d& v) : Vector3d(v)
|
|---|
| 34 | {
|
|---|
| 35 | this->Normalize();
|
|---|
| 36 | }
|
|---|
| 37 | //! print the vector on stream os
|
|---|
| 38 | void UnitVector::Print(ostream& os) const
|
|---|
| 39 | {
|
|---|
| 40 | os << "UnitVector : (X,Y,Z)= (" << _x << ", " << _y << ", " << _z
|
|---|
| 41 | << ") Theta,Phi= " << _theta << ", " << _phi << "\n"
|
|---|
| 42 | << "norme =" << this->Norm() << endl;
|
|---|
| 43 | }
|
|---|
| 44 | //++
|
|---|
| 45 | // Titre Operators
|
|---|
| 46 | //--
|
|---|
| 47 | //++
|
|---|
| 48 | Vector3d& UnitVector::operator = (const Vector3d& v)
|
|---|
| 49 | //
|
|---|
| 50 | //--
|
|---|
| 51 |
|
|---|
| 52 | {
|
|---|
| 53 | Setxyz(v.X(),v.Y(),v.Z());
|
|---|
| 54 | this->Normalize();
|
|---|
| 55 | return *this;
|
|---|
| 56 | }
|
|---|
| 57 | //++
|
|---|
| 58 | Vector3d& UnitVector::operator += (const Vector3d& v)
|
|---|
| 59 | //
|
|---|
| 60 | //--
|
|---|
| 61 | {
|
|---|
| 62 | Setxyz(_x+v.X(),_y+v.Y(),_z+v.Z());
|
|---|
| 63 | this->Normalize();
|
|---|
| 64 | return *this;
|
|---|
| 65 | }
|
|---|
| 66 | //++
|
|---|
| 67 | Vector3d& UnitVector::operator -= (const Vector3d& v)
|
|---|
| 68 | //
|
|---|
| 69 | //--
|
|---|
| 70 | {
|
|---|
| 71 | Setxyz(_x-v.X(),_y-v.Y(),_z-v.Z());
|
|---|
| 72 | this->Normalize();
|
|---|
| 73 | return *this;
|
|---|
| 74 | }
|
|---|
| 75 | //++
|
|---|
| 76 | Vector3d UnitVector::operator + (const Vector3d& v) const
|
|---|
| 77 | //
|
|---|
| 78 | //--
|
|---|
| 79 | {
|
|---|
| 80 | return UnitVector(_x+v.X(),_y+v.Y(),_z+v.Z());
|
|---|
| 81 | }
|
|---|
| 82 | //++
|
|---|
| 83 | Vector3d UnitVector::operator - (const Vector3d& v) const
|
|---|
| 84 | //
|
|---|
| 85 | //--
|
|---|
| 86 | {
|
|---|
| 87 | return UnitVector(_x-v.X(),_y-v.Y(),_z-v.Z());
|
|---|
| 88 | }
|
|---|