21 #ifndef __MIA_3DVECTOR_HH
22 #define __MIA_3DVECTOR_HH 1
30 #include <type_traits>
79 x(T(org.x)),y(T(org.y)),z(T(org.z)){
85 x=org.
x; y=org.
y; z=org.
z;
91 return x * x + y * y + z *
z;
100 return sqrt(
norm2());
128 throw std::logic_error(
"Access to vectorelement out of range");
147 throw std::logic_error(
"Access to vectorelement out of range");
153 x+=a.
x; y+=a.
y; z+=a.
z;
159 x-=a.
x; y-=a.
y; z-=a.
z;
165 x = T(x * a); y = T(y * a); z = T(z * a);
171 x = T(x * a.
x); y = T(y * a.
y); z = T(z * a.
z);
179 x = T(x/ a); y =T (y / a); z = T(z / a);
185 os << x <<
"," << y <<
"," <<
z;
201 is.clear(std::ios::badbit);
207 is.clear(std::ios::badbit);
213 is.clear(std::ios::badbit);
224 is.clear(std::ios::badbit);
230 is.clear(std::ios::badbit);
282 template <
typename T>
285 static const int size;
288 template <
typename T>
289 const int atomic_data<T3DVector<T> >::size = 3;
300 template <
typename T>
304 a.
y * b.
z - b.
y * a.
z,
305 a.
z * b.
x - b.
z * a.
x,
306 a.
x * b.
y - b.
x * a.
y
320 return a.
x * b.
x + a. y * b.
y + a.
z * b.
z;
337 std::ostream& operator << (std::ostream& os, const T3DVector<T>& v)
368 template <
typename T,
typename S>
407 assert(b.
x != 0.0 && b.
x != 0.0 && b.
x != 0.0);
435 a.
z * b.
x - b.
z * a.
x,
436 a.
x * b.
y - b.
x * a.
y);
443 return (b.
x == a.
x && b.
y == a.
y && b.
z == a.
z);
456 return (a.x < b.x && a.y < b.y && a.z < b.z);
462 return (b.x <= a.x && b.y <= a.y && b.z <= a.z);
468 return (b.
x > a.
x && b.
y > a.
y && b.
z > a.
z);
474 return (b.
x >= a.
x && b.
y >= a.
y && b.
z >= a.
z);
476 template <
typename T >
479 template <
typename T >
482 template <
typename T>
487 (a.
y < b.
y || (a.
y == b.
y && a.
x < b.
x)));
const T3DVector< T > operator/(const T3DVector< T > &a, double f)
vector division by scalar
const T operator[](size_t i) const
const T3DVector< T > & xyz() const
swizzle operator
T3DVector< T > & operator=(const T3DVector< T > &other)=default
we provide the default copy mechanisms
T3DVector< double > C3DDVector
A double 3D Vector.
void read(std::istream &is)
read the vector from a formatted string
const T3DVector< T > operator+(const T3DVector< T > &a, const T3DVector< T > &b)
vector addition
const T3DVector< T > yzx() const
swizzle operator
bool operator==(const T3DVector< T > &a, const T3DVector< T > &b)
comparison operator equal
T3DVector< float > C3DFVector
A float 3D Vector.
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
T value_type
typedef for generic programming
const T3DVector< T > operator-(const T3DVector< T > &a, const T3DVector< T > &b)
vector subtraction
double dot(const T3DVector< T > &a, const T3DVector< T > &b)
static T3DVector< T > _0
declare the vector (0,0,0)
T3DVector< T > & operator-=(const T3DVector< T > &a)
inplace subtraction
T3DVector< T > & operator/=(const double a)
inplace divisison by a scalar
T3DVector()
standart constructor
T3DVector< T > cross(const T3DVector< T > &a, const T3DVector< T > &b)
std::istream & operator>>(std::istream &is, T3DVector< T > &v)
stream input operator for 3DVector
const T3DVector< T > operator*(const T3DVector< T > &a, const T3DVector< T > &b)
vector scalar product
const T3DVector< T > zyx() const
swizzle operator
T3DVector< T > & operator*=(const double a)
inplace multiplication
static T3DVector< T > _1
declare the vector (1,1,1)
void write(std::ostream &os) const
print out the formatted vector to the stream
const T3DVector< T > xzy() const
swizzle operator
const T3DVector< T > yxz() const
swizzle operator
bool operator>=(const T3DVector< T > &b, const T3DVector< T > &a)
comparison greater or equal, returns true if all components of a are greater or equal then those of b...
double fabs(const T3DVector< T > &t)
A way to get the norm of a T3DVector using faba syntax.
const T3DVector< T > operator^(const T3DVector< T > &a, const T3DVector< T > &b)
3D vector cross product
const T3DVector< T > zxy() const
swizzle operator
void fill(T v)
Fill the vector elements with value v.
double norm2() const
square of Euclidian norm of the vector
T3DVector(const T3DVector< in > &org)
type casting copy constructor
static const unsigned int elements
the number of elements this vector holds (=3)
T3DVector(const T &x_, const T &y_, const T &z_)
constructor to construct vector from values
T3DVector(int dim)
create a zero-vector, dim must be 3
T3DVector< unsigned int > C3DBounds
A unsinged int 3D Vector (used for 3D field sizes)
T3DVector< T > & operator+=(const T3DVector< T > &a)
inplace addition
bool operator>(const T3DVector< T > &b, const T3DVector< T > &a)
comparison greater, returns true if all components of a are greater then those of b ...
bool operator!=(const T3DVector< T > &a, const T3DVector< T > &b)
comparison operator not equal
#define NS_MIA_END
conveniance define to end the mia namespace