Learn R Programming

rotations (version 1.6.5)

Arithmetic: Arithmetic operators on SO(3)

Description

These binary operators perform arithmetic on rotations in quaternion or rotation matrix form (or objects which can be coerced into them).

Usage

# S3 method for SO3
+(x, y)

# S3 method for SO3 -(x, y = NULL)

# S3 method for Q4 +(x, y)

# S3 method for Q4 -(x, y = NULL)

Value

+

the result of rotating the identity frame through x then y

-

the difference of the rotations, or the inverse rotation of only one argument is provided

Arguments

x

first argument

y

second argument (optional for subtraction)

Details

The rotation group SO(3) is a multiplicative group so ``adding" rotations \(R_1\) and \(R_2\) results in \(R_1+R_2=R_2R_1\). Similarly, the difference between rotations \(R_1\) and \(R_2\) is \(R_1-R_2=R_2^\top R_1\). With this definition it is clear that \(R_1+R_2-R_2=R_2^\top R_2R_1=R_1\). If only one rotation is provided to subtraction then the inverse (transpose) it returned, e.g. \(-R_2=R_2^\top\).

Examples

Run this code
U <- c(1, 0, 0)          #Rotate about the x-axis
R1 <- as.SO3(U, pi/8)    #Rotate pi/8 radians about the x-axis
R2 <- R1 + R1            #Rotate pi/8 radians about the x-axis twice
mis.axis(R2)             #x-axis: (1,0,0)
mis.angle(R2)            #pi/8 + pi/8 = pi/4

R3 <- R1 - R1            #Rotate pi/8 radians about x-axis then back again
R3                       #Identity matrix

R4 <- -R1                #Rotate in the opposite direction through pi/8
R5 <- as.SO3(U, -pi/8)   #Equivalent to R4

M1 <- matrix(R1, 3, 3)   #If element-wise addition is requred,
M2 <- matrix(R2, 3, 3)   #translate them to matrices then treat as usual
M3 <- M1 + M2

M1 %*% M1                #Equivalent to R2
t(M1) %*% M1             #Equivalent to R3
t(M1)                    #Equivalent to R4 and R5

#The same can be done with quaternions: the identity rotation is (1, 0, 0, 0)
#and the inverse rotation of Q=(a, b, c, d) is -Q=(a, -b, -c, -d)

Q1 <- as.Q4(R1)
Q2 <- Q1 + Q1
mis.axis(Q2)
mis.angle(Q2)

Q1 - Q1                  #id.Q4 = (1, 0, 0, 0)

Run the code above in your browser using DataLab