Vector operations
Usage
vlength(x)
vsum(x, w = NULL)
vnorm(x)
vscale(x, l)
vcross(x, y)
vdot(x, y)
vrotate(x, rotaxis, rotangle)
vangle(x, y)
vproject(x, y)
vreject(x, y)
Details
vlength(x)
returns the length of a vector x
.
vsum(x)
returns the vector sum of x
. If w
is specified.
vscale(x)
returns a vector x with length l
.
vnorm(x)
returns the normalized vector x
(i.e. vlength(x) = 1
)
vcross(x, y)
returns the cross product of vectors x
and y
which is a new vector perpendicular to both.
vdot(x, y)
returns the dot product (or scalar product) of x and y. vdot(x, y)
is equivalent to x %*% t(y)
vrotate(x, rotaxis, rotangle)
rotates x about a vector by a specified angle.
vproject(x,y)
projects x on vector y, i.e. returns a vector that has same orientation as y but length of x.
vreject(x,y)
Is the vector between x
and the projected vector of x
onto y
(also called the vector resolute of x perpendicular to y)
Examples
vec1 <- cbind(1, 0, 0)
vec2 <- cbind(0, 0, 1)
vlength(vec1)
#> [1] 1
vsum(vec1)
#> [,1] [,2] [,3]
#> [1,] 1 0 0
vnorm(vec1)
#> [,1] [,2] [,3]
#> [1,] 1 0 0
vcross(vec1, vec2)
#> x y z
#> [1,] 0 -1 0
vdot(vec1, vec2)
#> [1] 0
vrotate(vec1, vec2, pi / 2)
#> x y z
#> [1,] 2.220446e-16 1 0
vangle(vec1, vec2)
#> [1] 1.570796
vproject(vec1, vec2)
#> x y z
#> [1,] 0 0 0
vreject(vec1, vec2)
#> x y z
#> [1,] 1 0 0