Skip to contents

Get a random unit vector orthogonal to u.

Usage

rand_ortho_vector(u)

Arguments

u

A unit vector.

Value

A random unit vector orthogonal to u.

Note

This function is stochastic. For reproducibility set a PRNG seed with set.seed.

Examples

r <- stats::runif(3)      # Get a random 3D vector
r <- r / norm(r, "2")     # Normalize it
o <- rand_ortho_vector(r) # Get a random unit vector orthogonal to r
r %*% o            # Check that r and o are orthogonal (result should be ~0)
#>               [,1]
#> [1,] -6.938894e-18