## Keyboard shortcuts

Press `←` or `→` to navigate between chapters

Press `S` or `/` to search in the book

Press `?` to show this help

Press `Esc` to hide this help

# 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 tolerance
- `false`: 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`