//******************************************************************************
//** SCATMECH: Polarized Light Scattering C++ Class Library
//**
//** File: vector3d.h
//**
//** Thomas A. Germer
//** Optical Technology Division, National Institute of Standards and Technology
//** 100 Bureau Dr. Stop 8442; Gaithersburg, MD 20899-8442
//** Phone: (301) 975-2876; FAX: (301) 840-8551
//** Email: [email=thomas.germer@nist.gov]thomas.germer@nist.gov[/email]
//**
//** Version: 3.01 (May 2002)
//**
//******************************************************************************
#ifndef SCATMECH_VECTOR3D_H
#define SCATMECH_VECTOR3D_H
#include "scatmech.h"
#ifndef NO_SCATMECH_NAMESPACE
namespace SCATMECH {
#endif // NO_SCATMECH_NAMESPACE
//
// template class Vector3D_Base is used by the class Vector3D
//
template
class Vector3D_Base {
public:
//
// The components of the vector:
//
TYPE x,y,z;
// Class constructors:
Vector3D_Base
Vector3D_Base
{x=a;y=b;z=c;}
// Class destructor:
virtual ~Vector3D_Base
// Non-converting copy constructor:
Vector3D_Base
: x(a.x),y(a.y),z(a.z) {}
// Assignment operator:
Vector3D_Base
{ x=a.x; y=a.y; z=a.z; return *this; }
// Addition of vectors:
Vector3D_Base
{ return Vector3D_Base
// Subtraction of vectors:
Vector3D_Base
{ return Vector3D_Base
// Unary minus sign:
Vector3D_Base
{ return Vector3D_Base
// Scalar product of two vectors:
TYPE operator*(const Vector3D_Base
{ return x*a.x+y*a.y+z*a.z; }
// Product of vector with scalar:
Vector3D_Base
{ return Vector3D_Base
friend Vector3D_Base
const Vector3D_Base
{return Vector3D_Base
// Division of a vector by a scalar:
Vector3D_Base
{ return Vector3D_Base
// The cross product of two vectors:
friend Vector3D_Base
const Vector3D_Base
{ return Vector3D_Base
a.z*b.x-a.x*b.z,
a.x*b.y-a.y*b.x); }
protected:
// A type-converting copy function:
template
void copy(const Vector3D_Base
{ x=a.x; y=a.y; z=a.z; }
};
//
// Define templated Vector3D
//
template
//
// Define Vector3D
//
template <>
class Vector3D
public:
// Constructors:
Vector3D
Vector3D
: Vector3D_Base
Vector3D
: Vector3D_Base
Vector3D
: Vector3D_Base
// The norm of a vector:
friend double Norm(const Vector3D_Base
{ return sqrt(sqr(a.x)+sqr(a.y)+sqr(a.z)); }
// A vector of unit length:
friend Vector3D
{ return a/Norm(a); }
// A function returning a vector having specific polar coordinates:
friend Vector3D_Base
return Vector3D_Base
r*sin(theta)*sin(phi),
r*cos(theta));
}
};
//
// Defining Vector3D
//
template <>
class Vector3D
public:
// Constructors:
Vector3D
Vector3D
: Vector3D_Base
Vector3D
: Vector3D_Base
Vector3D
const COMPLEX & ay,
const COMPLEX & az)
: Vector3D_Base
// Constructor which converts from a real vector to a complex vector:
Vector3D
// The norm of a complex vector:
friend COMPLEX Norm(const Vector3D_Base
{ return std::sqrt(sqr(a.x)+sqr(a.y)+sqr(a.z)); }
// A vector of unit length:
friend Vector3D
{ return a/Norm(a); }
};
// A vector perpendicular to two vectors:
Vector3D
const Vector3D
Vector3D
const Vector3D
// Some useful typedefs for the SCATMECH library:
typedef Vector3D
typedef Vector3D
#ifndef NO_SCATMECH_NAMESPACE
} // namespace SCATMECH
#endif // NO_SCATMECH_NAMESPACE
#endif // VECTOR3D_H
[ 本帖最后由 APFNTCHUO 于 2008-4-20 09:18 编辑 ]
gongji110 于 2008-04-20 10:18:11发表:
你搜一下Norm函数在哪个库了,或者编译的时候要添加哪个库,就可以解决了。