23 extern double const pi;
25 template <std::
size_t N>
45 template <std::
size_t N>
46 class Vector :
public Array<double,N>
54 for (std::size_t i=0; i < N; ++i)
61 for (std::size_t i=0; i < N; ++i)
62 c[i] = (*
this)[i] + b[i];
68 for (std::size_t i=0; i < N; ++i)
76 for (std::size_t i=0; i < N; ++i)
77 c[i] = (*
this)[i] - b[i];
86 for (std::size_t i=0; i < N; ++i)
87 c[i] = (*
this)[i] * s;
95 for (std::size_t i=0; i < N; ++i)
96 c[i] = (*
this)[i] / s;
106 for (std::size_t i=0; i < N; ++i)
107 r += (*
this)[i] * b[i];
117 for (std::size_t i=0; i < N; ++i)
126 r[0] = a[1]*b[2] - a[2]*b[1];
127 r[1] = a[2]*b[0] - a[0]*b[2];
128 r[2] = a[0]*b[1] - a[1]*b[0];
133 template<std::
size_t N>
136 return b*((a*b)/(b*b));
140 template<std::
size_t N>
190 double x()
const {
return (*
this)[0];}
192 double y()
const {
return (*
this)[1];}
194 double z()
const {
return (*
this)[2];}
196 double&
x() {
return (*
this)[0];}
198 double&
y() {
return (*
this)[1];}
200 double&
z() {
return (*
this)[2];}
double & z()
mutable z component
double & y()
mutable y component
double & x()
mutable x component
void fromArray(const double *abc)
read vector from array
Vector< N > & operator+=(Vector< N > const &b)
add a vector to this vector
std::ostream & operator<<(std::ostream &s, apf::Vector3 const &v)
write apf::Vector3 to a C++ stream
void toArray(double *abc) const
write vector to array
Vector< N > operator/(double s) const
divide a vector by a scalar
void zero()
zero the vector
double getLength() const
get the vector magnitude
template-generic vector of N doubles
Vector< N > operator+(Vector< N > const &b) const
add two vectors
double y() const
immutable y component
Vector3(double const *abc)
construct from array
convenience wrapper over apf::Vector<3>
double const pi
The mathematical constant pi.
Vector< N > normalize() const
divide the vector by its magnitude
double x() const
immutable x component
double sqrt(double A)
wrapper for standard sqrt function
Vector< N > operator-(Vector< N > const &b) const
subtract two vectors
Vector< N > reject(Vector< N > const &a, Vector< N > const &b)
vector rejection
double operator*(Vector< N > const &b) const
vector dot product
Vector< N > operator*(double s) const
multiply a vector times a scalar
double z() const
immutable z component
Vector< N > project(Vector< N > const &a, Vector< N > const &b)
Returns vector (a) projected onto vector (b)
Vector< 3 > cross(Vector< 3 > const &a, Vector< 3 > const &b)
3D vector cross product
Vector3(double a, double b, double c)
construct from 3 values
Vector(double const *v)
construct from array