imunano33  0.1.1
svector::Vector3D Class Reference

A simple 3D vector representation. More...

#include <simplevectors.hpp>

Inheritance diagram for svector::Vector3D:
Collaboration diagram for svector::Vector3D:

Public Member Functions

 Vector3D (const double x, const double y, const double z)
 Initializes a vector given xyz components. More...
 
 Vector3D (const Vec3_ &other)
 Copy constructor for the base class.
 
double x () const
 Gets x-component. More...
 
void x (const double &newX)
 Sets x-component. More...
 
double y () const
 Gets y-component. More...
 
void y (const double &newY)
 Sets y-component. More...
 
double z () const
 Gets z-component. More...
 
void z (const double &newZ)
 Sets z-component. More...
 
Vector3D cross (const Vector3D &other) const
 Cross product of two vectors. More...
 
template<typename T >
componentsAs () const
 Converts vector to another object. More...
 
template<typename T >
anglesAs () const
 Converts angles to another object. More...
 
template<AngleDir D>
double angle () const
 Gets a specific angle of the vector. More...
 
template<AngleDir D>
Vector3D rotate (const double &ang) const
 Rotates vector around a certain axis by a certain angle. More...
 
 Vector ()
 No-argument constructor. More...
 
 Vector (const std::initializer_list< T > args)
 Initializes a vector given initializer list. More...
 
 Vector (const Vector< D, T > &other)
 Copy constructor. More...
 
 Vector (Vector< D, T > &&) noexcept=default
 Move constructor. More...
 
- Public Member Functions inherited from svector::Vector< D, T >
 Vector ()
 No-argument constructor. More...
 
 Vector (const std::initializer_list< T > args)
 Initializes a vector given initializer list. More...
 
 Vector (const Vector< D, T > &other)
 Copy constructor. More...
 
 Vector (Vector< D, T > &&) noexcept=default
 Move constructor. More...
 
Vector< D, T > & operator= (const Vector< D, T > &other)
 Assignment operator. More...
 
Vector< D, T > & operator= (Vector< D, T > &&) noexcept=default
 Move assignment operator. More...
 
virtual ~Vector ()=default
 Destructor. More...
 
virtual std::string toString () const
 Returns string form of vector. More...
 
Vector< D, T > operator- () const
 Negative of a vector. More...
 
Vector< D, T > operator+ () const
 Positive of a vector. More...
 
Vector< D, T > & operator+= (const Vector< D, T > &other)
 In-place addition. More...
 
Vector< D, T > & operator-= (const Vector< D, T > &other)
 In-place subtraction. More...
 
Vector< D, T > & operator*= (const T other)
 In-place scalar multiplication. More...
 
Vector< D, T > & operator/= (const T other)
 In-place scalar division. More...
 
dot (const Vector< D, T > &other) const
 Dot product. More...
 
magn () const
 Magnitude. More...
 
Vector< D, T > normalize () const
 Normalizes a vector. More...
 
constexpr std::size_t numDimensions () const
 Gets the number of dimensions. More...
 
bool isZero () const
 Determines whether the current vector is a zero vector. More...
 
const T & operator[] (const std::size_t index) const
 Value of a certain component of a vector. More...
 
T & operator[] (const std::size_t index)
 Sets value of a certain component. More...
 
const T & at (const std::size_t index) const
 Value of a certain component of a vector. More...
 
T & at (const std::size_t index)
 Sets value of a certain component. More...
 
iterator begin () noexcept
 Iterator of first element. More...
 
const_iterator begin () const noexcept
 Const interator of first element. More...
 
iterator end () noexcept
 Interator of last element + 1. More...
 
const_iterator end () const noexcept
 Const interator of last element + 1. More...
 
reverse_iterator rbegin () noexcept
 Reverse iterator to last element. More...
 
const_reverse_iterator rbegin () const noexcept
 Const reverse iterator to last element. More...
 
reverse_iterator rend () noexcept
 Reverse iterator to first element - 1. More...
 
const_reverse_iterator rend () const noexcept
 Const reverse iterator to first element - 1. More...
 

Additional Inherited Members

- Public Types inherited from svector::Vector< D, T >
typedef std::array< T, D >::iterator iterator
 An std::array::iterator.
 
typedef std::array< T, D >::const_iterator const_iterator
 An std::array::const_iterator.
 
typedef std::array< T, D >::reverse_iterator reverse_iterator
 An std::array::reverse_iterator.
 
typedef std::array< T, D >::const_reverse_iterator const_reverse_iterator
 An std::array::const_reverse_iterator.
 
- Protected Attributes inherited from svector::Vector< D, T >
std::array< T, D > m_components
 An array of components for the vector.
 

Detailed Description

A simple 3D vector representation.

Constructor & Destructor Documentation

◆ Vector3D()

svector::Vector3D::Vector3D ( const double  x,
const double  y,
const double  z 
)
inline

Initializes a vector given xyz components.

Parameters
xThe x-component.
yThe y-component.
zThe z-component.

Member Function Documentation

◆ angle()

template<AngleDir D>
double svector::Vector3D::angle ( ) const
inline

Gets a specific angle of the vector.

Each angle is in the range [0, π]. Angle will be in radians.

Specify whether you want the angle from the positive x-axis, the positive y-axis, or the positive z-axis in the template argument.

See also
svector::AngleDir
Note
This method will result in undefined behavior if the vector is a zero vector (if the magnitude equals zero).
Returns
An angle representing the angle you specified.

◆ anglesAs()

template<typename T >
T svector::Vector3D::anglesAs ( ) const
inline

Converts angles to another object.

Converts the angles of vector to an object with a constructor that has three parameters.

For example, this method can be used to convert the angles of a 3D vector into a struct with three variables and a constructor for those three variables.

Returns
Converted value.

◆ componentsAs()

template<typename T >
T svector::Vector3D::componentsAs ( ) const
inline

Converts vector to another object.

Converts components of vector to an object with a constructor that has three parameters.

For example, this method can be used to convert the components of a 3D vector into a struct with three variables and a constructor for those three variables.

Returns
The converted value.

◆ cross()

Vector3D svector::Vector3D::cross ( const Vector3D other) const
inline

Cross product of two vectors.

Parameters
otherThe other vector to cross current vector with.
Returns
The cross product of the two vectors.

◆ rotate()

template<AngleDir D>
Vector3D svector::Vector3D::rotate ( const double &  ang) const
inline

Rotates vector around a certain axis by a certain angle.

Uses the basic gimbal-like 3D rotation matrices for the x-axis, y-axis, and the z-axis.

Specify your rotation in the template argument. When the given template is ALPHA, the vector rotates around the x-axis, when the given template is BETA, the vector rotates around y-axis, and when the given template is GAMMA, the vector rotates around z-axis.

See also
svector::AngleDir
Parameters
angthe angle to rotate the vector, in radians.
Returns
A new, rotated vector.

◆ Vector() [1/4]

svector::Vector< D, T >::Vector
inline

No-argument constructor.

Initializes a zero vector (all components are 0).

◆ Vector() [2/4]

svector::Vector< D, T >::Vector
inline

Initializes a vector given initializer list.

The initializer list should represent the components of the vector in each dimension. If the size of the initializer list is greater than the number of dimensions given, then the vector only initializes with the first D elements in the list, where D is the number of dimensions. If the size of the initializer list is less than the number of dimensions given, then the vector fills the rest of the dimensions with the value 0.

Parameters
argsthe initializer list.

◆ Vector() [3/4]

svector::Vector< D, T >::Vector
inline

Copy constructor.

Copies from another vector to an uninitialized vector.

◆ Vector() [4/4]

svector::Vector< D, T >::Vector
defaultnoexcept

Move constructor.

Uses C++ default move constructor.

◆ x() [1/2]

double svector::Vector3D::x ( ) const
inline

Gets x-component.

Gets the x-component of the vector.

Returns
x-component of vector.

◆ x() [2/2]

void svector::Vector3D::x ( const double &  newX)
inline

Sets x-component.

Sets the x-component of the vector.

Parameters
newXx-value to set

◆ y() [1/2]

double svector::Vector3D::y ( ) const
inline

Gets y-component.

Gets the y-component of the vector.

Returns
y-component of vector.

◆ y() [2/2]

void svector::Vector3D::y ( const double &  newY)
inline

Sets y-component.

Sets the y-component of the vector.

Parameters
newYy-value to set

◆ z() [1/2]

double svector::Vector3D::z ( ) const
inline

Gets z-component.

Gets the z-component of the vector.

Returns
z-component of vector.

◆ z() [2/2]

void svector::Vector3D::z ( const double &  newZ)
inline

Sets z-component.

Sets the z-component of the vector.

Parameters
newZz-value to set

The documentation for this class was generated from the following file: