rotate: Rotates 3D vectors using quaternions

Description Usage Arguments Value Author(s) See Also Examples

Description

Rotates a three-column matrix whose rows are vectors in 3D space, using quaternions

Usage

1
rotate(x, H)

Arguments

x

A matrix of three columns whose rows are points in 3D space

H

A quaternion. Does not need to have unit modulus

Value

Returns a matrix of the same size as x

Author(s)

Robin K. S. Hankin

See Also

orthogonal

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
data(bunny)
par(mfrow=c(2,2))
par(mai=rep(0,4))
p3d(rotate(bunny,Hi),box=FALSE)
p3d(rotate(bunny,H1-Hi+Hj),box=FALSE)
p3d(rotate(bunny,Hk),box=FALSE)
p3d(rotate(bunny,Hall),box=FALSE)

o <- function(w){diag(3)-2*outer(w,w)/sum(w^2)}  # Householder
O <- o(1:3) %*% o(3:1)

rotate(bunny,as.quaternion(O))
bunny %*% t(O)    # should be the same; note transpose

onion documentation built on Feb. 11, 2021, 9:06 a.m.