11#ifndef BASIC_VECTOR3D_H
12#define BASIC_VECTOR3D_H
59 template<
typename U = T,
60 typename =
typename std::enable_if<!std::is_same<U,float>::value >::type>
62 v_[0] = v.
x();
v_[1] = v.
y();
v_[2] = v.
z();
79 operator T * () {
return v_; }
83 operator const T * ()
const {
return v_; }
105 v_[0] += v.
v_[0];
v_[1] += v.
v_[1];
v_[2] += v.
v_[2];
return *
this;
110 v_[0] -= v.
v_[0];
v_[1] -= v.
v_[1];
v_[2] -= v.
v_[2];
return *
this;
115 v_[0] *= a;
v_[1] *= a;
v_[2] *= a;
return *
this;
120 v_[0] /= a;
v_[1] /= a;
v_[2] /= a;
return *
this;
147 T
x()
const {
return v_[0]; }
150 T
y()
const {
return v_[1]; }
153 T
z()
const {
return v_[2]; }
167 void set(T x1, T y1, T z1) {
v_[0] = x1;
v_[1] = y1;
v_[2] = z1; }
188 factor = rh/factor;
v_[0] *= factor;
v_[1] *= factor;
208 return x() == 0 &&
y() == 0 ? 0 : std::atan2(
y(),
x());
213 return x() == 0 &&
y() == 0 &&
z() == 0 ? 0 : std::atan2(
perp(),
z());
234 factor = ma/factor;
v_[0] *= factor;
v_[1] *= factor;
v_[2] *= factor;
248 set(ma*std::sin(th)*std::cos(ph), ma*std::sin(th)*std::sin(ph), ma*std::cos(th));
276 return x()*v.
x()+
y()*v.
y()+
z()*v.
z();
284 x()*v.
y()-v.
x()*
y());
291 return tot > 0 ?
mag2()-s*s/tot :
mag2();
297 return std::sqrt(
perp2(v));
319 T dx =
x() < 0 ? -
x() :
x();
320 T dy =
y() < 0 ? -
y() :
y();
321 T dz =
z() < 0 ? -
z() :
z();
409 return BasicVector3D<float>(v.
x()*
static_cast<float>(a), v.
y()*
static_cast<float>(a), v.
z()*
static_cast<float>(a));
427 return BasicVector3D<float>(
static_cast<float>(a)*v.
x(),
static_cast<float>(a)*v.
y(),
static_cast<float>(a)*v.
z());
436 return BasicVector3D<float>(v.
x()/
static_cast<float>(a), v.
y()/
static_cast<float>(a), v.
z()/
static_cast<float>(a));
445 return (a.
x()==b.
x() && a.
y()==b.
y() && a.
z()==b.
z());
454 return (a.
x()!=b.
x() || a.
y()!=b.
y() || a.
z()!=b.
z());
554 return (a.
x()==b.
x() && a.
y()==b.
y() && a.
z()==b.
z());
564 return (a.
x()!=b.
x() || a.
y()!=b.
y() || a.
z()!=b.
z());
BasicVector3D< float > operator-(const BasicVector3D< float > &a, const BasicVector3D< float > &b)
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
BasicVector3D< float > operator*(const BasicVector3D< float > &v, double a)
float operator*(const BasicVector3D< float > &a, const BasicVector3D< float > &b)
BasicVector3D< T > & rotateZ(T a)
BasicVector3D< double > operator*(const BasicVector3D< double > &v, double a)
bool operator!=(const BasicVector3D< float > &a, const BasicVector3D< float > &b)
BasicVector3D< T > & operator/=(double a)
BasicVector3D< T > & rotateX(T a)
BasicVector3D< T > & rotate(T a, const BasicVector3D< T > &v)
BasicVector3D< float > operator+(const BasicVector3D< float > &a, const BasicVector3D< float > &b)
BasicVector3D< float > operator/(const BasicVector3D< float > &v, double a)
T operator[](int i) const
T angle(const BasicVector3D< T > &v) const
BasicVector3D< T > & operator*=(double a)
BasicVector3D< double > operator+(const BasicVector3D< double > &a, const BasicVector3D< double > &b)
bool operator==(const BasicVector3D< float > &a, const BasicVector3D< float > &b)
BasicVector3D< float > operator-(const BasicVector3D< float > &v)
virtual ~BasicVector3D()=default
bool operator==(const BasicVector3D< double > &a, const BasicVector3D< double > &b)
BasicVector3D< double > operator+(const BasicVector3D< double > &v)
BasicVector3D(T x1, T y1, T z1)
BasicVector3D< double > operator-(const BasicVector3D< double > &v)
BasicVector3D< T > & rotateY(T a)
BasicVector3D(BasicVector3D< T > &&)=default
BasicVector3D< double > operator/(const BasicVector3D< double > &v, double a)
BasicVector3D< double > operator-(const BasicVector3D< double > &a, const BasicVector3D< double > &b)
BasicVector3D(const BasicVector3D< T > &)=default
bool operator!=(const BasicVector3D< double > &a, const BasicVector3D< double > &b)
BasicVector3D< T > unit() const
BasicVector3D< float > operator*(double a, const BasicVector3D< float > &v)
BasicVector3D< double > operator*(double a, const BasicVector3D< double > &v)
BasicVector3D< T > & operator+=(const BasicVector3D< T > &v)
BasicVector3D(const BasicVector3D< float > &v)
BasicVector3D< T > & operator-=(const BasicVector3D< T > &v)
double operator*(const BasicVector3D< double > &a, const BasicVector3D< double > &b)
T perp2(const BasicVector3D< T > &v) const
BasicVector3D< T > & operator=(const BasicVector3D< T > &)=default
void set(T x1, T y1, T z1)
BasicVector3D< T > orthogonal() const
T perp(const BasicVector3D< T > &v) const
BasicVector3D< float > operator+(const BasicVector3D< float > &v)
T dot(const BasicVector3D< T > &v) const
T operator()(int i) const
std::istream & operator>>(std::istream &is, BasicVector3D< float > &a)
std::ostream & operator<<(std::ostream &os, const BasicVector3D< float > &a)