Vector math operations
Usage
vector_length(x)
crossprod(x, ...)
# S3 method for class 'spherical'
crossprod(x, y = NULL)
# S3 method for class 'spherical'
x %*% y
rotate(x, ...)
# S3 method for class 'spherical'
rotate(x, rotaxis, rotangle)
angle(x, y)
# S3 method for class 'spherical'
angle(x, y)
project(x, y)
# S3 method for class 'spherical'
project(x, y)
reject(x, y)
# Default S3 method
reject(x, y)
transform_linear(x, A, norm = FALSE)
Arguments
- x, y
objects of class
"Vec3"
,"Line"
, or"Plane"
.- ...
arguments passed to function call
- rotaxis
Axis of rotation given as object of class
"Vec3"
,"Line"
, or"Plane"
.- rotangle
Angle of rotation in radians for
"Vec3"
objects and in degrees for"Line"
and"Plane"
objects.- A
numeric 3x3 matrix. Transformation matrix.
- norm
logical. If
TRUE
, the transformed vectors are normalized to unit length.
Value
objects of same class as x
, i.e. one of "Vec3"
, "Line"
, or
"Plane"
. vector_length()
and %*%
return a real number. angle()
returns a numeric angle (in degrees, unless x
is class "Vec3"
).
Details
vector_length
the length of a vector
crossprod
the cross-product of two vectors, i.e. the vector perpendicular to the 2 vectors. If
y = NULL
is taken to be the sam,e vector asx
.%*%
the dot product of two vectors
rotate
rotation of a vector about a specified vector by a specified angle
angle
angle between two vectors
project
projection of one vector onto the other (changes the vector length of second vector, unless their are unit vectors)
transform_linear
Linear transformation of a vector by a 3x3 matrix
Examples
vec1 <- Vec3(1, 0, 0)
vec2 <- Vec3(0, 0, 1)
vector_length(vec1) # lenght of a vector
#> [1] 1
crossprod(vec1, vec2) # cross product
#> Vector (Vec3) object (n = 1):
#> x y z
#> 0 -1 0
vec1 %*% vec2 # dot product
#> [1] 0
rotate(vec1, vec2, pi / 2) # rotation
#> Vector (Vec3) object (n = 1):
#> x y z
#> 2.220446e-16 1.000000e+00 0.000000e+00
angle(vec1, vec2) # angle between vectors
#> [1] 1.570796
project(vec1, vec2) # projection of a vector
#> Vector (Vec3) object (n = 1):
#> x y z
#> 0 0 0
transform_linear(vec1, matrix(runif(9), 3, 3)) # linear transformation
#> Vector (Vec3) object (n = 1):
#> x y z
#> 0.62397442 0.27313788 0.07167168