Learn R Programming

rotations (version 1.5)

as.SO3: Rotation matrices

Description

Creates or tests for objects of class "SO3".

Usage

as.SO3(x, ...)
"as.SO3" (x, theta = NULL, ...)
"as.SO3" (x, ...)
"as.SO3" (x, ...)
"as.SO3" (x, ...)
is.SO3(x)
id.SO3

Arguments

x
object to be coerced or tested; see details for possible forms
theta
vector or single rotation angle; if length(theta)==1 the same theta is used for all axes
...
additional arguments.

Value

as.SO3
coerces provided data into an SO3 type.
is.SO3
returns TRUE or False depending on whether its argument satisfies the conditions to be an rotation matrix. Namely, has determinant one and its transpose is its inverse.

Format

id.SO3 is the identity rotation given by the the 3-by-3 identity matrix.

Details

Construct a single or sample of rotations in 3-dimensions in 3-by-3 matrix form. Several possible inputs for x are possible and they are differentiated based on their class and dimension.

For x an n-by-3 matrix or a vector of length 3, the angle-axis representation of rotations is utilized. More specifically, each rotation matrix can be interpreted as a rotation of some reference frame about the axis $U$ (of unit length) through the angle $\theta$. If a single axis (in matrix or vector format) or matrix of axes are provided for x, then for each axis and angle the matrix is formed through $$R=\exp[\Phi(U\theta)]$$ where $U$ is replace by x. If axes are provided but theta is not provided then the length of each axis is taken to be the angle of rotation, theta.

For x an n-by-4 matrix of quaternions or an object of class "Q4", this function will return the rotation matrix equivalent of x. See Q4 or the vignette "rotations-intro" for more details on quaternions.

For x an n-by-9 matrix, rows are treated as 3-by-3 matrices; rows that don't form matrices in SO(3) are projected into SO(3) and those that are already in SO(3) are returned untouched. See project.SO3 for more on projecting arbitrary matrices into SO(3). A message is printed if any of the rows are not proper rotations.

x a "data.frame" is translated into a matrix of the same dimension and the dimensionality of x is used to determine the data type: angle-axis, quaternion or rotation. As demonstrated below, is.SO3 may return TRUE for a data frame, but the functions defined for objects of class "SO3" will not be called until as.SO3 has been used.

Examples

Run this code
data(nickel)                   #Select one location to focus on
Loc698 <- subset(nickel, location == 698)

is.SO3(Loc698[,5:13])          #Some of the rows are not rotations due to rounding or entry errors
                               #as.SO3 will project matrices not in SO(3) to SO(3)

Rs <- as.SO3(Loc698[,5:13])    #Translate the Rs data.frame into an object of class 'SO3'
                               #Rows 4, 6 and 13 are not in SO(3) so they are projected to SO(3)

mean(Rs)                       #Estimate the central orientation with the average
median(Rs)                     #Re-estimate central orientation robustly
Qs <- as.Q4(Rs)                #Coerse into "SO3" format, see ?as.SO3 for more

#Visualize the location, there appears to be two groups
## Not run: 
# plot(Rs, col = c(1, 2, 3))## End(Not run)

Run the code above in your browser using DataLab