//
// template class Vector3D_Base is used by the class Vector3D
//
template <class TYPE>
class Vector3D_Base {
public:
//
// The components of the vector:
//
TYPE x,y,z;
// Class constructors:
Vector3D_Base<TYPE>() {}
Vector3D_Base<TYPE>(const TYPE& a,const TYPE& b,const TYPE& c)
{x=a;y=b;z=c;}
// Class destructor:
virtual ~Vector3D_Base<TYPE>() {}
// Non-converting copy constructor:
Vector3D_Base<TYPE>(const Vector3D_Base<TYPE>& a)
: x(a.x),y(a.y),z(a.z) {}
// Scalar product of two vectors:
TYPE operator*(const Vector3D_Base<TYPE>& a) const
{ return x*a.x+y*a.y+z*a.z; }
// Product of vector with scalar:
Vector3D_Base<TYPE> operator*(const TYPE& b) const
{ return Vector3D_Base<TYPE>(x*b,y*b,z*b); }
friend Vector3D_Base<TYPE> operator*(const TYPE& b,
const Vector3D_Base<TYPE>& a)
{return Vector3D_Base<TYPE>(a.x*b,a.y*b,a.z*b); }
// Division of a vector by a scalar:
Vector3D_Base<TYPE> operator/(const TYPE& a) const
{ return Vector3D_Base<TYPE>(x/a,y/a,z/a); }
// The cross product of two vectors:
friend Vector3D_Base<TYPE> cross(const Vector3D_Base<TYPE>& a,
const Vector3D_Base<TYPE>& b)
{ return Vector3D_Base<TYPE>(a.y*b.z-a.z*b.y,
a.z*b.x-a.x*b.z,
a.x*b.y-a.y*b.x); }
protected:
// A type-converting copy function:
template <class TYPE2>
void copy(const Vector3D_Base<TYPE2>& a)
{ x=a.x; y=a.y; z=a.z; }
};
//
// Define templated Vector3D
//
template <class TYPE> class Vector3D: public Vector3D_Base<TYPE> {};
//
// Define Vector3D<double>
//
template <>
class Vector3D<double> : public Vector3D_Base<double> {
public:
// Constructors:
Vector3D<double>() {};
Vector3D<double>(const Vector3D<double>& a)
: Vector3D_Base<double>(a) {}
Vector3D<double>(const Vector3D_Base<double>& a)
: Vector3D_Base<double>(a) {}
Vector3D<double>(double ax,double ay,double az)
: Vector3D_Base<double>(ax,ay,az) {}
// The norm of a vector:
friend double Norm(const Vector3D_Base<double>& a)
{ return sqrt(sqr(a.x)+sqr(a.y)+sqr(a.z)); }
// A vector of unit length:
friend Vector3D<double> unit(const Vector3D_Base<double>& a)
{ return a/Norm(a); }
// A function returning a vector having specific polar coordinates:
friend Vector3D_Base<double> polar(double r,double theta,double phi) {
return Vector3D_Base<double>(r*sin(theta)*cos(phi),
r*sin(theta)*sin(phi),
r*cos(theta));
}
};
// Constructor which converts from a real vector to a complex vector:
Vector3D<COMPLEX >(const Vector3D_Base<double>& a) { copy(a); }
// The norm of a complex vector:
friend COMPLEX Norm(const Vector3D_Base<COMPLEX >& a)
{ return std::sqrt(sqr(a.x)+sqr(a.y)+sqr(a.z)); }
// A vector of unit length:
friend Vector3D<COMPLEX > unit(const Vector3D_Base<COMPLEX >& a)
{ return a/Norm(a); }
};
// A vector perpendicular to two vectors:
Vector3D<double> perpto(const Vector3D<double>& a,
const Vector3D<double>& b);
Vector3D<COMPLEX > perpto(const Vector3D<COMPLEX >& a,
const Vector3D<COMPLEX >& b);
// Some useful typedefs for the SCATMECH library:
typedef Vector3D<double> Vector;
typedef Vector3D<COMPLEX > CVector;