Firefly 3.1.0
Standalone library for vector calculations
Loading...
Searching...
No Matches
firefly::utilities::vector Namespace Reference

Functions

template<vector_type T, vector_type U, std::size_t Length>
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.
 
template<vector_type T, vector_type U, std::size_t Length>
bool are_anti_parallel (firefly::vector< T, Length > const &v1, firefly::vector< U, Length > const &v2)
 Checks if two vectors are anti-parallel.
 
template<vector_type T, vector_type U, std::size_t Length>
bool are_parallel (firefly::vector< T, Length > const &v1, firefly::vector< U, Length > const &v2)
 Checks if two vectors are parallel.
 
template<vector_type T, vector_type U, std::size_t Length>
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.
 
template<vector_type T, vector_type U, std::size_t Length>
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.
 
template<vector_type T, vector_type U, std::size_t Length>
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.
 
template<vector_type T, vector_type U, std::size_t Length>
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.
 
template<vector_type T, vector_type U, std::size_t Length>
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.
 
template<vector_type T, vector_type U, std::size_t Length>
constexpr auto distance (firefly::vector< T, Length > const &vector_a, firefly::vector< U, Length > const &vector_b)
 Computes the Euclidean distance between two vectors.
 
template<vector_type T, vector_type U, std::size_t Length>
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.
 
template<vector_type T>
constexpr auto rotate_2d (firefly::vector< T, 2 > const &vector, double angle_rad)
 Rotates a 2D vector by a given angle (in radians).
 
template<vector_type T, vector_type U, std::size_t Length>
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.
 
template<vector_type T, vector_type U, std::size_t Length>
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.
 

Function Documentation

◆ angle_between()

template<vector_type T, vector_type U, std::size_t Length>
constexpr auto firefly::utilities::vector::angle_between ( firefly::vector< T, Length > const &  v1,
firefly::vector< U, Length > const &  v2,
double  delta = 1e-6 
)
constexpr

Calculates the angle between two vectors in radians.

This function computes the angle between two vectors, v1 and v2, of the same length. It uses the dot product and the norms of the vectors to determine the cosine of the angle.

Template Parameters
TType of the first vector. Must be an arithmetic type.
UType of the second vector. Must be an arithmetic type.
LengthLength of both vectors.
Parameters
v1First vector of type firefly::vector<T, Length>.
v2Second vector of type firefly::vector<U, Length>.
deltaA small tolerance value for numerical stability (default is 1e-6).
Exceptions
std::logic_errorwhen norm is zero. This usually happens when zero vector is passed
Returns
The angle between the two vectors in radians. The result is clamped between -1.0 and 1.0.
Note
Only arithmetic types are allowed for T and U.

◆ are_anti_parallel()

template<vector_type T, vector_type U, std::size_t Length>
bool firefly::utilities::vector::are_anti_parallel ( firefly::vector< T, Length > const &  v1,
firefly::vector< U, Length > const &  v2 
)

Checks if two vectors are anti-parallel.

Two vectors are considered anti-parallel if they are in opposite direction.

Template Parameters
TType of the first vector.
UType of the second vector.
LengthLength of both vectors.
Parameters
v1First vector of type firefly::vector<T, Length>.
v2Second vector of type firefly::vector<U, Length>.
Exceptions
std::logic_errorwhen norm is zero. This usually happens when zero vector is passed
Returns
true if the vectors are anti-parallel, false otherwise.
Note
Only arithmetic types are allowed for T and U.

◆ are_orthogonal()

template<vector_type T, vector_type U, std::size_t Length>
bool firefly::utilities::vector::are_orthogonal ( firefly::vector< T, Length > const &  v1,
firefly::vector< U, Length > const &  v2,
double  delta = 1e-6 
)

Checks if two- vectors are orthogonal.

Two vectors are considered orthogonal if the angle between them is close to 90 degrees (or π/2 radians).

Template Parameters
TType of the first vector.
UType of the second vector.
LengthLength of both vectors.
Parameters
v1First vector of type firefly::vector<T, Length>.
v2Second vector of type firefly::vector<U, Length>.
deltaA small tolerance value for numerical stability (default is 1e-6).
Exceptions
std::logic_errorwhen norm is zero. This usually happens when zero vector is passed
Returns
true if the vectors are orthogonal, false otherwise.
Note
Only arithmetic types are allowed for T and U.

◆ are_parallel()

template<vector_type T, vector_type U, std::size_t Length>
bool firefly::utilities::vector::are_parallel ( firefly::vector< T, Length > const &  v1,
firefly::vector< U, Length > const &  v2 
)

Checks if two vectors are parallel.

Two vectors are considered parallel if they are same or opposite directions.

Template Parameters
TType of the first vector.
UType of the second vector.
LengthLength of both vectors.
Parameters
v1First vector of type firefly::vector<T, Length>.
v2Second vector of type firefly::vector<U, Length>.
Exceptions
std::logic_errorwhen norm is zero. This usually happens when zero vector is passed
Returns
true if the vectors are parallel, false otherwise.
Note
Only arithmetic types are allowed for T and U.

◆ area_parallelogram()

template<vector_type T, vector_type U, std::size_t Length>
constexpr auto firefly::utilities::vector::area_parallelogram ( firefly::vector< T, Length > const &  v1,
firefly::vector< U, Length > const &  v2 
)
constexpr

Computes the area of the parallelogram formed by two vectors.

Template Parameters
TThe type of the elements in the first vector.
UThe type of the elements in the second vector.
LengthThe number of dimensions of the vectors.
Parameters
v1The first vector.
v2The second vector.
Returns
The area of the parallelogram formed by v1 and v2.
Note
Only arithmetic types are allowed for T and U.

◆ area_triangle()

template<vector_type T, vector_type U, std::size_t Length>
constexpr auto firefly::utilities::vector::area_triangle ( firefly::vector< T, Length > const &  v1,
firefly::vector< U, Length > const &  v2 
)
constexpr

Computes the area of the triangle formed by two vectors.

Template Parameters
TThe type of the elements in the first vector.
UThe type of the elements in the second vector.
LengthThe number of dimensions of the vectors.
Parameters
v1The first vector.
v2The second vector.
Returns
The area of the triangle formed by v1 and v2.
Note
Only arithmetic types are allowed for T and U.

◆ distance()

template<vector_type T, vector_type U, std::size_t Length>
constexpr auto firefly::utilities::vector::distance ( firefly::vector< T, Length > const &  vector_a,
firefly::vector< U, Length > const &  vector_b 
)
constexpr

Computes the Euclidean distance between two vectors.

Template Parameters
TThe type of the elements in the first vector.
UThe type of the elements in the second vector.
LengthThe number of dimensions of the vectors.
Parameters
vector_aThe first vector.
vector_bThe second vector.
Returns
The distance between vector_a and vector_b.

◆ lerp()

template<vector_type T, vector_type U, std::size_t Length>
constexpr auto firefly::utilities::vector::lerp ( firefly::vector< T, Length > const &  vector_a,
firefly::vector< U, Length > const &  vector_b,
double  t 
)
constexpr

Performs linear interpolation (Lerp) between two vectors.

Template Parameters
TThe type of the elements in the first vector.
UThe type of the elements in the second vector.
LengthThe number of dimensions of the vectors.
Parameters
vector_aThe first vector.
vector_bThe second vector.
tThe interpolation parameter, typically in the range [0, 1].
Returns
The interpolated vector between vector_a and vector_b.

◆ projection()

template<vector_type T, vector_type U, std::size_t Length>
constexpr auto firefly::utilities::vector::projection ( firefly::vector< T, Length > const &  source_vector,
firefly::vector< U, Length > const &  target_vector 
)
constexpr

Projects a source vector onto a target vector.

Template Parameters
TThe type of the elements in the source vector.
UThe type of the elements in the target vector.
LengthThe number of dimensions of the vectors.
Parameters
source_vectorThe vector being projected.
target_vectorThe vector onto which the source_vector is projected.
Returns
The projection of source_vector onto target_vector.

◆ reflection()

template<vector_type T, vector_type U, std::size_t Length>
constexpr auto firefly::utilities::vector::reflection ( firefly::vector< T, Length > const &  source_vector,
firefly::vector< U, Length > const &  target_vector 
)
constexpr

Reflects a source vector across a target vector.

Template Parameters
TThe type of the elements in the source vector.
UThe type of the elements in the target vector.
LengthThe number of dimensions of the vectors.
Parameters
source_vectorThe vector being reflected.
target_vectorThe vector across which the source_vector is reflected.
Returns
The reflected vector of source_vector across target_vector.

◆ rejection()

template<vector_type T, vector_type U, std::size_t Length>
constexpr auto firefly::utilities::vector::rejection ( firefly::vector< T, Length > const &  source_vector,
firefly::vector< U, Length > const &  target_vector 
)
constexpr

Rejects a source vector from a target vector.

Template Parameters
TThe type of the elements in the source vector.
UThe type of the elements in the target vector.
LengthThe number of dimensions of the vectors.
Parameters
source_vectorThe vector being rejected.
target_vectorThe vector from which the source_vector is rejected.
Returns
The component of source_vector orthogonal to target_vector.

◆ rotate_2d()

template<vector_type T>
constexpr auto firefly::utilities::vector::rotate_2d ( firefly::vector< T, 2 > const &  vector,
double  angle_rad 
)
constexpr

Rotates a 2D vector by a given angle (in radians).

Template Parameters
TThe type of the elements in the vector.
Parameters
vectorThe 2D vector to rotate.
angle_radThe angle in radians to rotate the vector.
Returns
The rotated vector.

◆ scalar_projection()

template<vector_type T, vector_type U, std::size_t Length>
constexpr auto firefly::utilities::vector::scalar_projection ( firefly::vector< T, Length > const &  source_vector,
firefly::vector< U, Length > const &  target_vector 
)
constexpr

Computes the scalar projection of a source vector onto a target vector.

Template Parameters
TThe type of the elements in the source vector.
UThe type of the elements in the target vector.
LengthThe number of dimensions of the vectors.
Parameters
source_vectorThe vector being projected.
target_vectorThe vector onto which the source_vector is projected.
Returns
The scalar projection of source_vector onto target_vector.