rotationS2: Compute a Rotation on the 2-dimensional Sphere

View source: R/rotationS2.R

rotationS2R Documentation

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)

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.

Value

a (3\times 3) rotation matrix.

Examples


## 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)



maotai documentation built on March 31, 2023, 6:48 p.m.