Vectors Aligned
The vectors_aligned function checks if two vectors are pointing in the same direction within a specified tolerance.
This is useful for comparing fiber directions, load directions, or any other vector quantities where alignment matters.
template <typename T>
inline __host__ __device__ bool vectors_aligned(T* vec1, T* vec2, T tolerance)
Parameters
vec1
- First vector (3 components)
vec2
- Second vector (3 components)
tolerance
- Maximum allowed angle in degrees for vectors to be considered aligned
Returns
true: The angle between the vectors is within the specified tolerancefalse: The angle exceeds the tolerance or either vector is near-zero
Example Usage
double fiber1[3] = {1.0, 0.0, 0.0};
double fiber2[3] = {0.99, 0.0, 0.0};
if (mat::vectors_aligned(fiber1, fiber2, 5.0)) {
// Vectors are within 5 degrees of alignment
}
Notes
- Vectors with magnitude less than 1e-10 are considered invalid and will return
false