38 Vec3D(
double x,
double y,
double z);
81 double const&
operator[](std::size_t
const index)
const;
101 double norm2()
const;
218 return r[0] * v.
r[0] +
r[1] * v.
r[1] +
r[2] * v.
r[2];
224 if (index < 3)
return r[index];
227 throw std::runtime_error(
"ERROR: 3D vector has only three"
235 if (index < 3)
return r[index];
238 throw std::runtime_error(
"ERROR: 3D vector has only three"
245 if (
r[0] != rhs.
r[0])
return false;
246 if (
r[1] != rhs.
r[1])
return false;
247 if (
r[2] != rhs.
r[2])
return false;
253 return !(*
this == rhs);
258 return sqrt(
r[0] *
r[0] +
r[1] *
r[1] +
r[2] *
r[2]);
263 return r[0] *
r[0] +
r[1] *
r[1] +
r[2] *
r[2];
268 return fabs(
r[0]) + fabs(
r[1]) + fabs(
r[2]);
285 w.
r[0] =
r[1] * v.
r[2] -
r[2] * v.
r[1];
286 w.
r[1] =
r[2] * v.
r[0] -
r[0] * v.
r[2];
287 w.
r[2] =
r[0] * v.
r[1] -
r[1] * v.
r[0];
Vec3D operator+(Vec3D lhs, Vec3D const &rhs)
Overload + operator to implement vector addition.
Vec3D operator*(Vec3D v, double const a)
Overload * operator to implement multiplication with scalar.
Vec3D operator-(Vec3D lhs, Vec3D const &rhs)
Overload - operator to implement vector subtraction.
Vec3D operator/(Vec3D v, double const a)
Overload / operator to implement division by scalar.
Vector in 3 dimensional real space.
bool operator==(Vec3D const &rhs) const
Compare if vectors are equal.
Vec3D & operator-=(Vec3D const &v)
Overload -= operator to implement in-place vector subtraction.
bool operator!=(Vec3D const &rhs) const
Compare if vectors are not equal.
double norm2() const
Calculate square of norm of vector.
double r[3]
cartesian coordinates.
Vec3D()
Constructor, initializes to zero.
Vec3D & normalize()
Normalize vector, norm equals 1.0 afterwards.
Vec3D & operator=(Vec3D const &rhs)
Overload = operator.
double l1norm() const
Calculate l1 norm of vector (taxicab metric).
Vec3D & operator/=(double const a)
Overload /= operator to implement division by scalar.
double operator*(Vec3D const &v) const
Overload * operator to implement scalar product.
double & operator[](std::size_t const index)
Overload [] operator to return coordinate by index.
Vec3D & operator+=(Vec3D const &v)
Overload += operator to implement in-place vector addition.
Vec3D cross(Vec3D const &v) const
Cross product, argument vector is second in product.
Vec3D & operator*=(double const a)
Overload *= operator to implement multiplication with scalar.
double norm() const
Calculate norm of vector.