Template Class vector3
Defined in File vector3.hpp
Nested Relationships
Nested Types
Inheritance Relationships
Base Type
public rcppsw::er::stringizable
(Class stringizable)
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 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.
-
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 ifmask
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.
-
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.
-
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.
Public Static Attributes
-
static constexpr size_t kDIMENSIONALITY = 3
Friends
-
struct componentwise_compare
Needed to compare in mathematical contexts.
-
struct key_compare
Needed for using vectors as keys in a map.
-
inline constexpr vector3(const T &x, const T &y, const T &z)