imunano33
0.1.1
|
#include <algorithm>
#include <array>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <initializer_list>
#include <string>
#include <type_traits>
#include <vector>
Go to the source code of this file.
Classes | |
class | svector::Vector< D, T > |
A base vector representation. More... | |
class | svector::Vector2D |
A simple 2D vector representation. More... | |
class | svector::Vector3D |
A simple 3D vector representation. More... | |
Typedefs | |
typedef Vector< 2 > | svector::Vec2_ |
An alias to Vector<2>. | |
typedef Vector< 3 > | svector::Vec3_ |
An alias to Vector<3>. | |
Enumerations | |
enum | svector::AngleDir { svector::ALPHA , svector::BETA , svector::GAMMA } |
Angle enumerator. More... | |
Functions | |
template<std::size_t D, typename T > | |
Vector< D, T > | svector::makeVector (std::array< T, D > array) |
Creates a vector from an std::array. More... | |
template<std::size_t D, typename T > | |
Vector< D, T > | svector::makeVector (std::vector< T > vector) |
Creates a vector from a std::vetor. More... | |
template<std::size_t D, typename T > | |
Vector< D, T > | svector::makeVector (const std::initializer_list< T > args) |
Creates a vector from an initializer list. More... | |
double | svector::x (const Vector2D &v) |
Gets the x-component of a 2D vector. More... | |
void | svector::x (Vector2D &v, const double xValue) |
Sets the x-component of a 2D vector. More... | |
double | svector::x (const Vector3D &v) |
Gets the x-component of a 3D vector. More... | |
void | svector::x (Vector3D &v, const double xValue) |
Sets the x-component of a 3D vector. More... | |
double | svector::y (const Vector2D &v) |
Gets the y-component of a 2D vector. More... | |
void | svector::y (Vector2D &v, const double yValue) |
Sets the y-component of a 2D vector. More... | |
double | svector::y (const Vector3D &v) |
Gets the y-component of a 3D vector. More... | |
void | svector::y (Vector3D &v, const double yValue) |
Sets the y-component of a 3D vector. More... | |
double | svector::z (const Vector3D &v) |
Gets the z-component of a 3D vector. More... | |
void | svector::z (Vector3D &v, const double zValue) |
Sets the z-component of a 3D vector. More... | |
template<typename T , std::size_t D> | |
T | svector::dot (const Vector< D, T > &lhs, const Vector< D, T > &rhs) |
Calculates the dot product of two vectors. More... | |
template<typename T , std::size_t D> | |
T | svector::magn (const Vector< D, T > &v) |
Gets the magnitude of the vector. More... | |
template<typename T , std::size_t D> | |
Vector< D, T > | svector::normalize (const Vector< D, T > &v) |
Normalizes a vector. More... | |
template<typename T , std::size_t D> | |
bool | svector::isZero (const Vector< D, T > &v) |
Determines whether a vector is a zero vector. More... | |
double | svector::angle (const Vector2D &v) |
Gets the angle of a 2D vector in radians. More... | |
Vector2D | svector::rotate (const Vector2D &v, const double ang) |
Rotates a 2D vector by a certain angle. More... | |
Vector3D | svector::cross (const Vector3D &lhs, const Vector3D &rhs) |
Cross product of two vectors. More... | |
double | svector::alpha (const Vector3D &v) |
Gets α angle. More... | |
double | svector::beta (const Vector3D &v) |
Gets β angle. More... | |
double | svector::gamma (const Vector3D &v) |
Gets γ angle. More... | |
Vector3D | svector::rotateAlpha (const Vector3D &v, const double &ang) |
Rotates around x-axis. More... | |
Vector3D | svector::rotateBeta (const Vector3D &v, const double &ang) |
Rotates around y-axis. More... | |
Vector3D | svector::rotateGamma (const Vector3D &v, const double &ang) |
Rotates around z-axis. More... | |
template<typename T , std::size_t D> | |
Vector< D, T > | svector::operator+ (const Vector< D, T > &lhs, const Vector< D, T > &rhs) |
Vector addition. More... | |
template<typename T , std::size_t D> | |
Vector< D, T > | svector::operator- (const Vector< D, T > &lhs, const Vector< D, T > &rhs) |
Vector subtraction. More... | |
template<typename T , typename T2 , std::size_t D> | |
Vector< D, T > | svector::operator* (const Vector< D, T > &lhs, const T2 rhs) |
Scalar multiplication. More... | |
template<typename T , typename T2 , std::size_t D> | |
Vector< D, T > | svector::operator/ (const Vector< D, T > &lhs, const T2 rhs) |
Scalar division. More... | |
template<typename T , std::size_t D> | |
bool | svector::operator== (const Vector< D, T > &lhs, const Vector< D, T > &rhs) |
Compares equality of two vectors. More... | |
template<typename T , std::size_t D> | |
bool | svector::operator!= (const Vector< D, T > &lhs, const Vector< D, T > &rhs) |
Compares inequality of two vectors. More... | |
enum svector::AngleDir |
Angle enumerator.
An enum representing the angle to use for a 3D vector.
This is only used in svector::Vector3D::angle() and svector::Vector3D::rotate().
Enumerator | |
---|---|
ALPHA | Angle between positive x-axis and vector. |
BETA | Angle between positive y-axis and vector. |
GAMMA | Angle between positive z-axis and vector. |
|
inline |
Gets α angle.
α is the angle between the vector and the x-axis.
v | A 3D vector. |
|
inline |
Gets the angle of a 2D vector in radians.
The angle will be in the range (-π, π].
v | A 2D vector. |
|
inline |
Gets β angle.
β is the angle between the vector and the y-axis.
v | A 3D vector. |
Cross product of two vectors.
lhs | The first vector. |
rhs | The second vector, crossed with the first vector. |
|
inline |
Calculates the dot product of two vectors.
D | The number of dimensions. |
T | Vector type. |
lhs | First vector. |
rhs | Second vector. |
|
inline |
Gets γ angle.
γ is the angle between the vector and the z-axis.
v | A 3D vector. |
|
inline |
Determines whether a vector is a zero vector.
D | The number of dimensions. |
T | Vector type. |
|
inline |
Gets the magnitude of the vector.
D | The number of dimensions. |
T | Vector type. |
v | The vector to get magnitude of. |
Vector<D, T> svector::makeVector | ( | const std::initializer_list< T > | args | ) |
Creates a vector from an 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.
D | The number of dimensions. |
T | Vector type. |
args | the initializer list. |
Vector<D, T> svector::makeVector | ( | std::array< T, D > | array | ) |
Creates a vector from an std::array.
D | The number of dimensions. |
T | Vector type. |
array | An array. |
Vector<D, T> svector::makeVector | ( | std::vector< T > | vector | ) |
Creates a vector from a std::vetor.
If the given std::vector has fewer elements than the specified dimensions, then this function will fill up the first elements of the vector with those in the given std::vector. The rest of the elements would be 0.
If the given std::vector has more elements than the specified dimensions, then the resulting vector would ignore the numbers in those dimensions.
D | The number of dimensions. |
T | Vector type. |
vector | A std::vector. |
|
inline |
Normalizes a vector.
Finds the unit vector with the same direction angle as the current vector.
D | The number of dimensions. |
T | Vector type. |
v | The vector to normalize. |
|
inline |
Compares inequality of two vectors.
D | The number of dimensions. |
T | Vector type. |
lhs | The first vector. |
rhs | The second vector. |
|
inline |
Scalar multiplication.
Performs scalar multiplication and returns a new vector representing the product.
D | The number of dimensions. |
T | Vector type. |
T2 | Scalar multiplication type. |
lhs | The first vector. |
rhs | The second vector. |
|
inline |
Vector addition.
Performs vector addition and returns a new vector representing the sum of the two vectors.
D | The number of dimensions. |
T | Vector type. |
lhs | The first vector. |
rhs | The second vector. |
|
inline |
Vector subtraction.
Performs vector subtraction and returns a new vector representing the difference of the two vectors.
D | The number of dimensions. |
T | Vector type. |
lhs | The first vector. |
rhs | The second vector. |
|
inline |
Scalar division.
Performs scalar division and returns a new vector representing the quotient.
D | The number of dimensions. |
T | Vector type. |
T2 | Scalar division type. |
lhs | The first vector. |
rhs | The second vector. |
|
inline |
Compares equality of two vectors.
D | The number of dimensions. |
T | Vector type. |
lhs | The first vector. |
rhs | The second vector. |
|
inline |
Rotates a 2D vector by a certain angle.
The angle should be given in radians. The vector rotates counterclockwise when the angle is positive and clockwise when the angle is negative.
v | A 2D vector. |
ang | the angle to rotate the vector, in radians. |
|
inline |
Rotates around x-axis.
Uses the basic gimbal-like 3D rotation matrices for rotation.
v | A 3D vector. |
ang | The angle to rotate the vector, in radians. |
|
inline |
Rotates around y-axis.
Uses the basic gimbal-like 3D rotation matrices for rotation.
v | A 3D vector. |
ang | The angle to rotate the vector, in radians. |
|
inline |
Rotates around z-axis.
Uses the basic gimbal-like 3D rotation matrices for rotation.
v | A 3D vector. |
ang | The angle to rotate the vector, in radians. |
|
inline |
Gets the x-component of a 2D vector.
v | A 2D Vector. |
|
inline |
Gets the x-component of a 3D vector.
v | A 3D Vector. |
|
inline |
Sets the x-component of a 2D vector.
v | A 2D Vector. |
xValue | The x-value to set to the vector. |
|
inline |
Sets the x-component of a 3D vector.
v | A 3D Vector. |
xValue | The x-value to set to the vector. |
|
inline |
Gets the y-component of a 2D vector.
v | A 2D Vector. |
|
inline |
Gets the y-component of a 3D vector.
v | A 3D Vector. |
|
inline |
Sets the y-component of a 2D vector.
v | A 2D Vector. |
yValue | The y-value to set to the vector. |
|
inline |
Sets the y-component of a 3D vector.
v | A 3D Vector. |
yValue | The y value to set to the vector. |
|
inline |
Gets the z-component of a 3D vector.
v | A 3D Vector. |
|
inline |
Sets the z-component of a 3D vector.
v | A 3D Vector. |
zValue | The z value to set to the vector. |