Learn R Programming

maotai (version 0.2.6)

rotationS2: Compute a Rotation on the 2-dimensional Sphere

Description

A vector of unit norm is an element on the hypersphere. When two unit-norm vectors \(x\) and \(y\) in 3-dimensional space are given, this function computes a rotation matrix \(Q\) on the 2-dimensional sphere such that $$y=Qx$$.

Usage

rotationS2(x, y)

Value

a \((3\times 3)\) rotation matrix.

Arguments

x

a length-\(3\) vector. If \(\|x\|\neq 1\), normalization is applied.

y

a length-\(3\) vector. If \(\|y\|\neq 1\), normalization is applied.

Examples

Run this code
# \donttest{
## generate two data points
#  one randomly and another on the north pole
x = stats::rnorm(3)
x = x/sqrt(sum(x^2))
y = c(0,0,1)

## compute the rotation
Q = rotationS2(x,y)

## compare 
Qx = as.vector(Q%*%x)

## print
printmat = rbind(Qx, y)
rownames(printmat) = c("rotated:", "target:")
print(printmat)
# }

Run the code above in your browser using DataLab