Struct Vector3

Struct Documentation

struct Vector3

General 3-element vector structure.

Public Functions

Vector3() = default

Default constructor: initializes to (0, 0, 0).

inline explicit Vector3(double a, double b = 0.0, double c = 0.0)

Constructor where \( \vec{x}=[a,b,c] \).

inline Vector3(std::initializer_list<double> list)

Constructor where \( \vec{x}=\{a,b,c\} \).

inline explicit Vector3(const std::vector<double> &list)

Constructor where \( \vec{x}=\{a,b,c\} \).

inline Vector3 operator+(const Vector3 &other) const

Component-wise addition of two vectors. \( \vec{w} = \vec{x} + \vec{y} \).

inline Vector3 &operator+=(const Vector3 &that)

In-place component-wise addition of two vectors. \( \vec{x} = \vec{x} + \vec{y} \).

inline Vector3 Shifted(double value) const

Component-wise shift by scalar-value. \( \vec{w} = \vec{x} + \alpha \).

inline Vector3 &Shift(double value)

In-place component-wise shift by scalar value. \( \vec{x} = \vec{x} + \alpha \).

inline Vector3 operator-(const Vector3 &other) const

Component-wise subtraction of two vectors. \( \vec{w} = \vec{x} - \vec{y} \).

inline Vector3 &operator-=(const Vector3 &that)

In-place component-wise subtraction. \( \vec{x} = \vec{x} - \vec{y} \).

inline Vector3 operator*(double value) const

Vector component-wise multiplication by scalar. \( \vec{w} = \vec{x} \alpha \).

inline Vector3 &operator*=(double value)

Vector in-place component-wise multiplication by scalar. \( \vec{x} = \vec{x} \alpha \).

inline Vector3 operator*(const Vector3 &that) const

Vector component-wise multiplication. \( w_i = x_i y_i \).

inline Vector3 &operator*=(const Vector3 &that)

Vector in-place component-wise multiplication. \( x_i = x_i y_i \).

inline Vector3 operator/(double value) const

Vector component-wise division by scalar. \( w_i = \frac{x_i}{\alpha} \).

inline Vector3 &operator/=(double value)

Vector in-place component-wise division by scalar. \( x_i = \frac{x_i}{\alpha} \).

inline Vector3 operator/(const Vector3 &that) const

Vector component-wise division. \( w_i = \frac{x_i}{y_i} \).

inline Vector3 &operator/=(const Vector3 &that)

Vector in-place component-wise division. \( x_i = \frac{x_i}{y_i} \).

inline double operator[](size_t i) const

Returns a copy of the value at the given index.

inline double &operator()(size_t i)

Returns a reference of the value at the given index.

inline Vector3 Cross(const Vector3 &that) const

Vector cross-product. \( \vec{w} = \vec{x} \times \vec{y} \)

inline double Dot(const Vector3 &that) const

Vector dot-product. \( \vec{w} = \vec{x} \bullet \vec{y} \).

inline double Norm() const

Computes the L2-norm of the vector. Otherwise known as the length of a 3D vector.

inline double NormSquare() const

Computes the square of the L2-norm of the vector. Less expensive than a proper L2-norm.

inline void Normalize()

Normalizes the vector in-place. \( \vec{x} = \frac{\vec{x}}{||x||_2} \).

inline Vector3 Normalized() const

Returns a normalized version of the vector. \( \vec{w} = \frac{\vec{x}}{||x||_2} \).

inline Vector3 InverseZeroIfSmaller(double tol) const

Inverse components, setting zero if below tolerance.

Returns a vector v^* where each element is inverted provided that it is greater than the given tolerance, otherwise the offending entry is set to 0.0. \( w_i = \frac{1.0}{x_i} \)

inline Vector3 InverseOneIfSmaller(double tol) const

Inverse components, setting one if below tolerance.

inline Vector3 Inverse() const

Inverts each component without checking for division by zero.

inline void Print() const

Prints the vector to std::cout.

inline std::string PrintStr() const

Returns the vector as a string.

inline bool AbsoluteEquals(const Vector3 &other, const double tol = 1.e-6) const

Absolute equality check with another point.

Public Members

double x = {0.0}

X-component of the vector.

double y = {0.0}

Y-component of the vector.

double z = {0.0}

Z-component of the vector.

Public Static Functions

static inline size_t Size()