7 #include <initializer_list> 20 vec3(T a, T b, T c) : x(a), y(b), z(c){}
23 vec3(std::initializer_list<T> l) : x(*l.begin()), y(*(l.begin()+1)), z(*(l.begin()+2)){}
52 std::ostream& operator<<(std::ostream& stream, const vec3<T> vec);
59 result.
x = this->
x + other.
x;
60 result.
y = this->
y + other.
y;
61 result.
z = this->
z + other.
z;
68 result.
x = this->
x - other.
x;
69 result.
y = this->
y - other.
y;
70 result.
z = this->
z - other.
z;
85 return (this->
x == other.
x) && (this->
y == other.
y) && (this->
z == other.
z);
90 return this->
x * other.
x + this->
y * other.
y + this->
z * other.
z;
95 return this->
x * this->
x + this->
y * this->
y + this->
z * this->
z;
100 return std::abs(this->
x) + std::abs(this->
y) + std::abs(this->
z);
104 template <
typename T>
106 return std::sqrt(this->
dot());
109 template <
typename T>
110 inline std::ostream& operator<<(std::ostream& stream, const vec3<T> vec){
111 stream <<
"(" << vec.x <<
"," << vec.y <<
"," << vec.z <<
")";
T norm2() const
Returns the euclidean norm of the vector.
Definition: vec3.h:105
Represents a triple (x, y, z) of any type.
Definition: vec3.h:12
vec3()
Internal coordinates are not initialized and may contain junk.
Definition: vec3.h:17
vec3(std::initializer_list< T > l)
Example v = {1, 2, 3}.
Definition: vec3.h:23
vec3< T > operator-() const
Unary minus operation.
Definition: vec3.h:75
vec3< T > operator+(const vec3< T > other) const
Element-wise sum.
Definition: vec3.h:57
T z
(x,y,z) coordinates.
Definition: vec3.h:14
vec3(T a, T b, T c)
Example v = vec3(1, 2, 3).
Definition: vec3.h:20
T norm1() const
Returns the norm1 of the vector (absolute value norm).
Definition: vec3.h:99
T x
(x,y,z) coordinates.
Definition: vec3.h:14
T dot() const
Returns the dot product of the vector with itself.
Definition: vec3.h:94
T y
(x,y,z) coordinates.
Definition: vec3.h:14
bool operator==(const vec3< T > other) const
Returns true if both vectors have equal coordinates.
Definition: vec3.h:84