Template Class vector3

Nested Relationships

Nested Types

Inheritance Relationships

Base Type

Class Documentation

template<typename T>
class vector3 : public rcppsw::er::stringizable

Base template class encapsulating mathematical actions on a pair of numbers. Is specialized by vector3i, vector3d.

All operations are performed in whatever the template parameter is, so take care if you are trying to do scaling, trigonometric things with integers…

Public Types

using value_type = T

Public Functions

inline constexpr vector3(const T &x, const T &y, const T &z)

Initializes the vector from Cartesian coordinates.

Parameters:
  • x – The X coordinate.

  • y – The Y coordinate.

  • z – The Z coordinate.

inline explicit vector3(const vector2<T> &v)

Initializes the 3D vector from a 2D vector, setting the Z value to 0.0.

inline vector3(const vector2<T> &v, const T &z)

Initialize the 3D vector from a 2D vector.

vector3(void) noexcept = default

Initializes vector to (0,0,0)

inline bool is_pd(void) const

Is the vector is positive definite?

inline bool is_psd(void) const

Is the vector is positive semi-definite?

inline double length(void) const

Returns the length of this vector.

inline vector3 mask(const vector3 &the_mask) const

Mask a vector using another vector, using mask as a boolean mask by treating each non-zero entry as a 1. Should only be used if mask is a unit vector.

template<typename U = T, typename std::enable_if<std::is_floating_point<U>::value, int>::type = 0>
inline vector3 &normalize(void)

Normalizes this vector.

After this method is called, the vector has length 1. If the vector is (0,0), this call results in a division by zero error, and your program will probably crash.

Returns:

A reference to the normalized vector.

inline bool operator!=(const vector3 &other) const

Returns if this vector and the passed one are not equal by checking coordinates for equality.

Should generally not be called if the template parameter type is not an integer, as floating point comparisons in general are unsafe.

inline vector3 operator*(const T &val) const
inline vector3 &operator*=(const T &val)
inline vector3 operator+(const vector3 &other) const
inline vector3 &operator+=(const vector3 &other)
inline vector3<T> operator-(const vector3 &other) const
inline vector3 operator-(void) const
inline vector3 &operator-=(const vector3 &other)
inline vector3 operator/(const T &val) const
inline vector3 &operator/=(const T &val)
template<typename U = T, typename std::enable_if<!std::is_floating_point<U>::value, int>::type = 0>
inline bool operator==(const vector3 &other) const

Returns if this vector and the argument are considered equal, determined by coordinate comparison.

Only available if the template argument is not floating point.

template<typename U = T, typename std::enable_if<std::is_floating_point<U>::value, int>::type = 0>
inline bool operator==(const vector3 &other) const

Returns if this vector and the argument are considered equal, determined by coordinate comparison.

Only available if the template argument is floating point.

template<typename U = T, typename std::enable_if<!std::is_floating_point<U>::value, int>::type = 0>
inline bool operator>(const vector3 &other) const
template<typename U = T, typename std::enable_if<std::is_floating_point<U>::value, int>::type = 0>
inline bool operator>(const vector3 &other) const
inline vector2<T> project_on_xy(void) const

Calculates the projection of this vector onto the XY plane.

inline vector2<T> project_on_xz(void) const

Calculates the projection of this vector onto the XZ plane.

inline vector2<T> project_on_yz(void) const

Calculates the projection of this vector onto the YZ plane.

inline vector3 &scale(const T &factor)

Scales the vector by the specified values.

Parameters:

factor – The scaling factor applied to X,Y,Z.

Returns:

A reference to the scaled vector.

inline vector3 &scale(const T &scale_x, const T &scale_y, const T &scale_z)

Scales the vector by the specified values.

Parameters:
  • scale_x – The scale factor for the X coordinate.

  • scale_y – The scale factor for the Y coordinate.

  • scale_z – The scale factor for the Z coordinate.

Returns:

A reference to the scaled vector.

inline void set(const T &x, const T &y, const T &z)

Sets the vector contents from Cartesian coordinates.

Parameters:
  • x – The new X coordinate.

  • y – The new Y coordinate.

inline T square_length(void) const

Returns the square length of this vector.

inline vector2<T> to_2D(void) const
template<typename U = T, typename std::enable_if<std::is_floating_point<U>::value, int>::type = 0>
inline sphere_vector<T> to_spherical(void) const
inline virtual std::string to_str(void) const override

Return a string representation of a class.

inline void x(const T &x)
inline T x(void)
inline const T &x(void) const
inline radians xangle(void) const

Return angle between this vector and the X axis.

inline void y(const T &y)
inline T y(void)
inline const T &y(void) const
inline radians yangle(void) const

Return the angle between this vector and the Y axis.

inline void z(const T &z)
inline T z(void)
inline const T &z(void) const
inline radians zangle(void) const

Return the angle between this vector and the Z axis.

Public Static Attributes

static constexpr size_t kDIMENSIONALITY = 3
static const vector3<T> X

The positive X axis.

static const vector3<T> Y

The positive Y axis.

static const vector3<T> Z

The positive Z axis.

Friends

inline friend std::ostream &operator<<(std::ostream &stream, const vector3 &v)
inline friend std::istream &operator>>(std::istream &is, vector3<T> &v)

For parsing a vector from a string in the form of "X,Y,Z".

struct componentwise_compare

Needed to compare in mathematical contexts.

Public Functions

template<typename U>
inline bool operator()(const vector3<U> &lhs, const vector3<U> &rhs) const
struct key_compare

Needed for using vectors as keys in a map.

Public Functions

template<typename U, typename std::enable_if<!std::is_floating_point<U>::value, int>::type = 0>
inline bool operator()(const vector3<U> &lhs, const vector3<U> &rhs) const
template<typename U, typename std::enable_if<std::is_floating_point<U>::value, int>::type = 0>
inline bool operator()(const vector3<U> &lhs, const vector3<U> &rhs) const