39 Vec3D(
double x,
double y,
double z);
92 double const&
operator[](std::size_t
const index)
const;
112 double norm2()
const;
191 r[0] = std::move(source.r[0]);
192 r[1] = std::move(source.r[1]);
193 r[2] = std::move(source.r[2]);
235 for (
size_t i=0; i<3; ++i)
237 for (
size_t j=0; j<3; ++j)
239 w.
r[i] += A[j][i] *
r[j];
255 return r[0] * v.
r[0] +
r[1] * v.
r[1] +
r[2] * v.
r[2];
262 if (index < 3)
return r[index];
265 throw std::runtime_error(
"ERROR: 3D vector has only three"
273 if (index < 3)
return r[index];
276 throw std::runtime_error(
"ERROR: 3D vector has only three"
283 if (
r[0] != rhs.
r[0])
return false;
284 if (
r[1] != rhs.
r[1])
return false;
285 if (
r[2] != rhs.
r[2])
return false;
291 return !(*
this == rhs);
296 return sqrt(
r[0] *
r[0] +
r[1] *
r[1] +
r[2] *
r[2]);
301 return r[0] *
r[0] +
r[1] *
r[1] +
r[2] *
r[2];
306 return fabs(
r[0]) + fabs(
r[1]) + fabs(
r[2]);
323 w.
r[0] =
r[1] * v.
r[2] -
r[2] * v.
r[1];
324 w.
r[1] =
r[2] * v.
r[0] -
r[0] * v.
r[2];
325 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.