normalizeVector normalizes a vector to unit length.

normalizeVector(v)

Arguments

v

a vector

Value

normalized vector

Examples

normalizeVector(c(1, 0, 0))
#> [1] 1 0 0
normalizeVector(c(1, 1, 0))
#> [1] 0.7071068 0.7071068 0.0000000
normalizeVector(c(1, 1, 1))
#> [1] 0.5773503 0.5773503 0.5773503
normalizeVector(c(-1, 2, 3))
#> [1] -0.2672612 0.5345225 0.8017837
vectorLength(normalizeVector(c(-1, 2, 3)))
#> [1] 1