17 Vec3(T _x=0, T _y=0, T _z=0) : x(_x), y(_y), z(_z) {}
25 return Vec3<T>(x+v.x,y+v.y,z+v.z);
38 return Vec3<T>(x-v.x,y-v.y,z-v.z);
51 return Vec3<T>(T(x*d),T(y*d),T(z*d));
64 return Vec3<T>(T(x/d),T(y/d),T(z/d));
77 return x*v.x + y*v.y + z*v.z;
91 return Vec3<T>(x*v.x, y*v.y, z*v.z);
103 return std::sqrt(
double(x*x+y*y+z*z));
113 return (x==v.x && y==v.y && z==v.z);
118 return !((*this)==v);
128 friend std::ostream& operator<<(std::ostream &os, const Vec3<T> &v) {
129 os << v.x <<
" " << v.y<<
" "<<v.z;
Vec3< T > operator/(const double &d) const
Division with double.
Definition: Vector3.h:63
bool operator!=(const Vec3< T > &v) const
Not equal (used for integer position vectors)
Definition: Vector3.h:117
Class representing 3D vectors, with elements of type T.
Definition: Vector3.h:9
Vec3< T > operator%(const Vec3< T > &v) const
Element-wise multiplication (hadamard product)
Definition: Vector3.h:90
Vec3< T > & operator-=(const Vec3< T > &v)
In-place vector subtraction.
Definition: Vector3.h:42
Vec3< T > cross(const Vec3< T > &v) const
Cross product.
Definition: Vector3.h:81
Vec3< T > & operator/=(const double &d)
In-place division with double.
Definition: Vector3.h:68
Vec3< T > operator*(const double &d) const
Multiplication with double.
Definition: Vector3.h:50
friend Vec3< T > operator*(const double &d, const Vec3< T > &v)
Multiplication with double.
Definition: Vector3.h:122
Vec3< T > & operator*=(const double &d)
In-place multiplication with double.
Definition: Vector3.h:55
double operator*(const Vec3< T > &v) const
Scalar product.
Definition: Vector3.h:76
Vec3< T > & operator+=(const Vec3< T > &v)
In-place vector addition.
Definition: Vector3.h:29
double norm() const
Vector norm.
Definition: Vector3.h:102
double norm2() const
Vector norm squared.
Definition: Vector3.h:107
Vec3(Vec3< T2 > v)
Copy constructor.
Definition: Vector3.h:21
Vec3< T > operator+(const Vec3< T > &v) const
Vector addition.
Definition: Vector3.h:24
Vec3< T > operator-(const Vec3< T > &v) const
Vector subtraction.
Definition: Vector3.h:37
bool operator==(const Vec3< T > &v) const
Equal (used for integer position vectors)
Definition: Vector3.h:112
Vec3(T _x=0, T _y=0, T _z=0)
Standard constructor.
Definition: Vector3.h:17
Vec3< T > & normalize()
Normalize.
Definition: Vector3.h:95