38 #ifndef INCLUDE_SVECTOR_EMBED_HPP_
39 #define INCLUDE_SVECTOR_EMBED_HPP_
62 Vec2D(
const double xOther,
const double yOther) :
x{xOther},
y{yOther} {}
178 Vec3D(
const double xOther,
const double yOther,
const double zOther)
179 :
x{xOther},
y{yOther},
z{zOther} {}
198 if (
this == &other) {
290 inline double x(
const Vec2D &v) {
return v.
x; }
298 inline void x(
Vec2D &v,
const double xValue) { v.
x = xValue; }
307 inline double x(
const Vec3D &v) {
return v.
x; }
315 inline void x(
Vec3D &v,
const double xValue) { v.
x = xValue; }
324 inline double y(
const Vec2D &v) {
return v.
y; }
332 inline void y(
Vec2D &v,
const double yValue) { v.
y = yValue; }
341 inline double y(
const Vec3D &v) {
return v.
y; }
349 inline void y(
Vec3D &v,
const double yValue) { v.
y = yValue; }
358 inline double z(
const Vec3D &v) {
return v.
z; }
366 inline void z(
Vec3D &v,
const double zValue) { v.
z = zValue; }
379 s = s + std::to_string(vec.
x) +
", " + std::to_string(vec.
y) +
">";
395 return Vec2D{lhs.
x + rhs.
x, lhs.
y + rhs.
y};
410 return Vec2D{lhs.
x - rhs.
x, lhs.
y - rhs.
y};
450 return Vec2D{lhs.
x * rhs, lhs.
y * rhs};
465 return Vec2D{lhs.
x / rhs, lhs.
y / rhs};
477 return lhs.
x == rhs.
x && lhs.
y == rhs.
y;
489 return !(lhs == rhs);
501 return lhs.
x * rhs.
x + lhs.
y * rhs.
y;
512 return std::sqrt(vec.
x * vec.
x + vec.
y * vec.
y);
524 inline double angle(
const Vec2D &vec) {
return std::atan2(vec.
y, vec.
x); }
567 const double xPrime = vec.
x * std::cos(ang) - vec.
y * std::sin(ang);
568 const double yPrime = vec.
x * std::sin(ang) + vec.
y * std::cos(ang);
570 return Vec2D{xPrime, yPrime};
584 s = s + std::to_string(vec.
x) +
", " + std::to_string(vec.
y) +
", " +
585 std::to_string(vec.
z) +
">";
601 return Vec3D{lhs.
x + rhs.
x, lhs.
y + rhs.
y, lhs.
z + rhs.
z};
616 return Vec3D{lhs.
x - rhs.
x, lhs.
y - rhs.
y, lhs.
z - rhs.
z};
631 return Vec3D{-vec.
x, -vec.
y, -vec.
z};
645 return Vec3D{+vec.
x, +vec.
y, +vec.
z};
660 return Vec3D{lhs.
x * rhs, lhs.
y * rhs, lhs.
z * rhs};
675 return Vec3D{lhs.
x / rhs, lhs.
y / rhs, lhs.
z / rhs};
687 return lhs.
x == rhs.
x && lhs.
y == rhs.
y && lhs.
z == rhs.
z;
699 return !(lhs == rhs);
711 return lhs.
x * rhs.
x + lhs.
y * rhs.
y + lhs.
z * rhs.
z;
723 const double newx = lhs.
y * rhs.
z - lhs.
z * rhs.
y;
724 const double newy = lhs.
z * rhs.
x - lhs.
x * rhs.
z;
725 const double newz = lhs.
x * rhs.
y - lhs.
y * rhs.
x;
727 return Vec3D{newx, newy, newz};
738 return std::sqrt(vec.
x * vec.
x + vec.
y * vec.
y + vec.
z * vec.
z);
823 const double xPrime = vec.
x;
824 const double yPrime = vec.
y * std::cos(ang) - vec.
z * std::sin(ang);
825 const double zPrime = vec.
y * std::sin(ang) + vec.
z * std::cos(ang);
827 return Vec3D{xPrime, yPrime, zPrime};
849 const double xPrime = vec.
x * std::cos(ang) + vec.
z * std::sin(ang);
850 const double yPrime = vec.
y;
851 const double zPrime = -vec.
x * std::sin(ang) + vec.
z * std::cos(ang);
853 return Vec3D{xPrime, yPrime, zPrime};
875 const double xPrime = vec.
x * std::cos(ang) - vec.
y * std::sin(ang);
876 const double yPrime = vec.
x * std::sin(ang) + vec.
y * std::cos(ang);
877 const double zPrime = vec.
z;
879 return Vec3D{xPrime, yPrime, zPrime};
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
std::string toString(const Vec2D &vec)
String form.
Definition: embed.hpp:377
A minimal 2D vector representation.
Definition: embed.hpp:48
Vec2D & operator/=(const double &other)
In-place scalar division.
Definition: embed.hpp:150
Vec2D()
No-argument constructor.
Definition: embed.hpp:54
Vec2D & operator=(Vec2D &&) noexcept=default
Move assignment operator.
double y
The y-component of the 2D vector.
Definition: embed.hpp:157
Vec2D & operator*=(const double &other)
In-place scalar multiplication.
Definition: embed.hpp:137
Vec2D & operator-=(const Vec2D &other)
In-place subtraction.
Definition: embed.hpp:124
double x
The x-component of the 2D vector.
Definition: embed.hpp:156
Vec2D(Vec2D &&) noexcept=default
Move constructor.
Vec2D(const Vec2D &other)=default
Copy constructor.
Vec2D(const double xOther, const double yOther)
Initializes a vector given xy components.
Definition: embed.hpp:62
A minimal 3D vector representation.
Definition: embed.hpp:163
Vec3D(const Vec3D &other)=default
Copy constructor.
double z
The z-component of the 3D vector.
Definition: embed.hpp:280
Vec3D & operator-=(const Vec3D &other)
In-place subtraction.
Definition: embed.hpp:243
Vec3D()
No-argument constructor.
Definition: embed.hpp:169
double y
The y-component of the 3D vector.
Definition: embed.hpp:279
Vec3D & operator*=(const double &other)
In-place scalar multiplication.
Definition: embed.hpp:257
Vec3D(Vec3D &&) noexcept=default
Move constructor.
Vec3D(const double xOther, const double yOther, const double zOther)
Initializes a vector given xyz components.
Definition: embed.hpp:178
double x
The x-component of the 3D vector.
Definition: embed.hpp:278
Vec3D & operator/=(const double &other)
In-place scalar division.
Definition: embed.hpp:271
Vec3D & operator=(Vec3D &&) noexcept=default
Move assignment operator.