13 #ifndef INCLUDE_SVECTOR_FUNCTIONS_HPP_
14 #define INCLUDE_SVECTOR_FUNCTIONS_HPP_
20 #include <initializer_list>
39 template <std::
size_t D,
typename T>
42 for (std::size_t i = 0; i < D; i++) {
65 template <std::
size_t D,
typename T>
68 for (std::size_t i = 0; i < std::min(D, vector.size()); i++) {
92 template <std::
size_t D,
typename T>
113 inline void x(
Vector2D &v,
const double xValue) { v[0] = xValue; }
130 inline void x(
Vector3D &v,
const double xValue) { v[0] = xValue; }
147 inline void y(
Vector2D &v,
const double yValue) { v[1] = yValue; }
164 inline void y(
Vector3D &v,
const double yValue) { v[1] = yValue; }
181 inline void z(
Vector3D &v,
const double zValue) { v[2] = zValue; }
196 template <
typename T, std::
size_t D>
200 for (std::size_t i = 0; i < D; i++) {
201 result += lhs[i] * rhs[i];
218 T sum_of_squares = 0;
220 for (std::size_t i = 0; i < D; i++) {
221 sum_of_squares += v[i] * v[i];
224 return std::sqrt(sum_of_squares);
242 template <
typename T, std::
size_t D>
290 const double xPrime =
x(v) * std::cos(ang) -
y(v) * std::sin(ang);
291 const double yPrime =
x(v) * std::sin(ang) +
y(v) * std::cos(ang);
305 const double newx =
y(lhs) *
z(rhs) -
z(lhs) *
y(rhs);
306 const double newy =
z(lhs) *
x(rhs) -
x(lhs) *
z(rhs);
307 const double newz =
x(lhs) *
y(rhs) -
y(lhs) *
x(rhs);
373 const double xPrime =
x(v);
374 const double yPrime =
y(v) * std::cos(ang) -
z(v) * std::sin(ang);
375 const double zPrime =
y(v) * std::sin(ang) +
z(v) * std::cos(ang);
377 return Vector3D{xPrime, yPrime, zPrime};
399 const double xPrime =
x(v) * std::cos(ang) +
z(v) * std::sin(ang);
400 const double yPrime =
y(v);
401 const double zPrime = -
x(v) * std::sin(ang) +
z(v) * std::cos(ang);
403 return Vector3D{xPrime, yPrime, zPrime};
425 const double xPrime =
x(v) * std::cos(ang) -
y(v) * std::sin(ang);
426 const double yPrime =
x(v) * std::sin(ang) +
y(v) * std::cos(ang);
427 const double zPrime =
z(v);
429 return Vector3D{xPrime, yPrime, zPrime};
432 #ifndef SVECTOR_USE_CLASS_OPERATORS
452 template <
typename T, std::
size_t D>
456 for (std::size_t i = 0; i < D; i++) {
457 tmp[i] = lhs[i] + rhs[i];
482 template <
typename T, std::
size_t D>
486 for (std::size_t i = 0; i < D; i++) {
487 tmp[i] = lhs[i] - rhs[i];
511 template <
typename T,
typename T2, std::
size_t D>
514 for (std::size_t i = 0; i < D; i++) {
515 tmp[i] = lhs[i] * rhs;
539 template <
typename T,
typename T2, std::
size_t D>
542 for (std::size_t i = 0; i < D; i++) {
543 tmp[i] = lhs[i] / rhs;
565 template <
typename T, std::
size_t D>
567 for (std::size_t i = 0; i < D; i++) {
568 if (lhs[i] != rhs[i]) {
592 template <
typename T, std::
size_t D>
594 return !(lhs == rhs);
598 #ifdef SVECTOR_EXPERIMENTAL_COMPARE
599 template <std::
size_t D1, std::
size_t D2,
typename T1,
typename T2>
600 bool operator<(
const Vector<D1, T1> &lhs,
const Vector<D2, T2> &rhs) {
601 return lhs.compare(rhs) < 0;
604 template <std::
size_t D1, std::
size_t D2,
typename T1,
typename T2>
605 bool operator>(
const Vector<D1, T1> &lhs,
const Vector<D2, T2> &rhs) {
606 return lhs.compare(rhs) > 0;
609 template <std::
size_t D1, std::
size_t D2,
typename T1,
typename T2>
610 bool operator<=(
const Vector<D1, T1> &lhs,
const Vector<D2, T2> &rhs) {
611 return lhs.compare(rhs) <= 0;
614 template <std::
size_t D1, std::
size_t D2,
typename T1,
typename T2>
615 bool operator>=(
const Vector<D1, T1> &lhs,
const Vector<D2, T2> &rhs) {
616 return lhs.compare(rhs) >= 0;
Contains a base vector representation.
Contains a 2D vector representation.
Contains a 3D vector representation.
bool operator==(const EmbVec2D &lhs, const EmbVec2D &rhs)
Compares equality of two vectors.
Definition: embed.h:470
float magn(const EmbVec2D &vec)
Gets the magnitude of the vector.
Definition: embed.h:505
EmbVec2D operator-(const EmbVec2D &lhs, const EmbVec2D &rhs)
Vector subtraction.
Definition: embed.h:399
float alpha(const EmbVec3D &vec)
Gets α angle.
Definition: embed.h:752
EmbVec3D rotateGamma(const EmbVec3D &vec, const float ang)
Rotates around z-axis.
Definition: embed.h:844
EmbVec3D rotateAlpha(const EmbVec3D &vec, const float ang)
Rotates around x-axis.
Definition: embed.h:792
float z(const EmbVec3D &v)
Gets the z-component of a 3D vector.
Definition: embed.h:363
float x(const EmbVec2D &v)
Gets the x-component of a 2D vector.
Definition: embed.h:295
float y(const EmbVec2D &v)
Gets the y-component of a 2D vector.
Definition: embed.h:329
EmbVec2D normalize(const EmbVec2D &vec)
Normalizes a vector.
Definition: embed.h:532
EmbVec3D rotateBeta(const EmbVec3D &vec, const float ang)
Rotates around y-axis.
Definition: embed.h:818
bool operator!=(const EmbVec2D &lhs, const EmbVec2D &rhs)
Compares inequality of two vectors.
Definition: embed.h:482
float beta(const EmbVec3D &vec)
Gets β angle.
Definition: embed.h:766
float dot(const EmbVec2D &lhs, const EmbVec2D &rhs)
Calculates the dot product of two vectors.
Definition: embed.h:494
EmbVec2D operator+(const EmbVec2D &lhs, const EmbVec2D &rhs)
Vector addition.
Definition: embed.h:384
bool isZero(const EmbVec2D &vec)
Determines whether a vector is a zero vector.
Definition: embed.h:539
float gamma(const EmbVec3D &vec)
Gets γ angle.
Definition: embed.h:780
EmbVec2D operator/(const EmbVec2D &lhs, const float rhs)
Scalar division.
Definition: embed.h:458
EmbVec2D operator*(const EmbVec2D &lhs, const float rhs)
Scalar multiplication.
Definition: embed.h:443
EmbVec3D cross(const EmbVec3D &lhs, const EmbVec3D &rhs)
Cross product of two vectors.
Definition: embed.h:700
EmbVec2D rotate(const EmbVec2D &vec, const float ang)
Rotates vector by a certain angle.
Definition: embed.h:553
float angle(const EmbVec2D &vec)
Gets the angle of a 2D vector in radians.
Definition: embed.h:518
Vector< D, T > makeVector(std::array< T, D > array)
Creates a vector from an std::array.
Definition: functions.hpp:40
A base vector representation.
Definition: vector.hpp:34
A simple 2D vector representation.
Definition: vector2d.hpp:25
A simple 3D vector representation.
Definition: vector3d.hpp:26