24template <vector_type T, vector_type U, std::
size_t Length>
26 double delta = 1e-6) {
27 static_assert(std::is_arithmetic_v<T> && std::is_arithmetic_v<U>,
"Only arithmetic types are allowed.");
28 if (v1.
norm() == 0 || v2.
norm() == 0) {
33 return rad < delta ? 0.0 : rad;
53template <vector_type T, vector_type U, std::
size_t Length>
55 static_assert(std::is_arithmetic_v<T> && std::is_arithmetic_v<U>,
"Only arithmetic types are allowed.");
76template <vector_type T, vector_type U, std::
size_t Length>
78 static_assert(std::is_arithmetic_v<T> && std::is_arithmetic_v<U>,
"Only arithmetic types are allowed.");
100template <vector_type T, vector_type U, std::
size_t Length>
102 static_assert(std::is_arithmetic_v<T> && std::is_arithmetic_v<U>,
"Only arithmetic types are allowed.");
120template <vector_type T, vector_type U, std::
size_t Length>
123 static_assert(std::is_arithmetic_v<T> && std::is_arithmetic_v<U>,
"Only arithmetic types are allowed.");
124 return v1.
cross(v2).norm();
141template <vector_type T, vector_type U, std::
size_t Length>
143 static_assert(std::is_arithmetic_v<T> && std::is_arithmetic_v<U>,
"Only arithmetic types are allowed.");
159template <vector_type T, vector_type U, std::
size_t Length>
162 return target_vector * ((source_vector * target_vector) / (target_vector * target_vector));
177template <vector_type T, vector_type U, std::
size_t Length>
180 return source_vector -
projection(source_vector, target_vector);
195template <vector_type T, vector_type U, std::
size_t Length>
198 return (vector_a - vector_b).norm();
213template <vector_type T, vector_type U, std::
size_t Length>
216 return projection(source_vector, target_vector) * 2 - source_vector;
229template <vector_type T>
231 T x =
vector[0] * std::cos(angle_rad) -
vector[1] * std::sin(angle_rad);
232 T y =
vector[0] * std::sin(angle_rad) +
vector[1] * std::cos(angle_rad);
249template <vector_type T, vector_type U, std::
size_t Length>
252 return source_vector.
dot(target_vector) / target_vector.
norm();
268template <vector_type T, vector_type U, std::
size_t Length>
271 return vector_a * (1 - t) + vector_b * t;
Represents a mathematical vector in n-dimensional space.
Definition vector.hpp:148
constexpr auto norm() const
Computes the Euclidean magnitude (Length) of the vector.
Definition vector.hpp:630
constexpr auto dot(vector< U, Length > const &other) const
Calculates the dot product of two vectors.
Definition vector.hpp:447
constexpr auto to_normalized() const
Normalizes the vector.
Definition vector.hpp:649
constexpr auto cross(vector< U, Length > const &other) const
Calculates the cross product of two 3D vectors.
Definition vector.hpp:465
Definition utilities.hpp:3
constexpr auto scalar_projection(firefly::vector< T, Length > const &source_vector, firefly::vector< U, Length > const &target_vector)
Computes the scalar projection of a source vector onto a target vector.
Definition utilities.hpp:250
constexpr auto angle_between(firefly::vector< T, Length > const &v1, firefly::vector< U, Length > const &v2, double delta=1e-6)
Calculates the angle between two vectors in radians.
Definition utilities.hpp:25
constexpr auto rotate_2d(firefly::vector< T, 2 > const &vector, double angle_rad)
Rotates a 2D vector by a given angle (in radians).
Definition utilities.hpp:230
constexpr auto reflection(firefly::vector< T, Length > const &source_vector, firefly::vector< U, Length > const &target_vector)
Reflects a source vector across a target vector.
Definition utilities.hpp:214
constexpr auto projection(firefly::vector< T, Length > const &source_vector, firefly::vector< U, Length > const &target_vector)
Projects a source vector onto a target vector.
Definition utilities.hpp:160
bool are_parallel(firefly::vector< T, Length > const &v1, firefly::vector< U, Length > const &v2)
Checks if two vectors are parallel.
Definition utilities.hpp:77
constexpr auto distance(firefly::vector< T, Length > const &vector_a, firefly::vector< U, Length > const &vector_b)
Computes the Euclidean distance between two vectors.
Definition utilities.hpp:196
bool are_orthogonal(firefly::vector< T, Length > const &v1, firefly::vector< U, Length > const &v2, double delta=1e-6)
Checks if two- vectors are orthogonal.
Definition utilities.hpp:101
constexpr auto rejection(firefly::vector< T, Length > const &source_vector, firefly::vector< U, Length > const &target_vector)
Rejects a source vector from a target vector.
Definition utilities.hpp:178
constexpr auto area_triangle(firefly::vector< T, Length > const &v1, firefly::vector< U, Length > const &v2)
Computes the area of the triangle formed by two vectors.
Definition utilities.hpp:142
constexpr auto area_parallelogram(firefly::vector< T, Length > const &v1, firefly::vector< U, Length > const &v2)
Computes the area of the parallelogram formed by two vectors.
Definition utilities.hpp:121
constexpr auto lerp(firefly::vector< T, Length > const &vector_a, firefly::vector< U, Length > const &vector_b, double t)
Performs linear interpolation (Lerp) between two vectors.
Definition utilities.hpp:269
bool are_anti_parallel(firefly::vector< T, Length > const &v1, firefly::vector< U, Length > const &v2)
Checks if two vectors are anti-parallel.
Definition utilities.hpp:54