procuste.R 855 Bytes
Newer Older
Eric Coissac committed
1 2 3 4
#' @include internals.R
#'
NULL

5 6 7 8
#' Rotate the \code{src} matrix to fit into the space of the \code{dest} matrix.
#'
#' The optimal rotation is computed according to the procruste methode.
#' Rotation is based on singular value decomposition (SVD).
9
#' No scaling and no centrering are done, before computing the SVD.
10 11 12 13 14 15 16
#'
#' @param src a numeric matrix to be rotated
#' @param dest a numeric matrix used as reference space
#'
#' @return a numeric matrix
#'
#' @examples
17
#' # Generates two random matrices of size 10 x 15
18 19
#' m1 <- simulate_matrix(10, 15)
#' m2 <- simulate_matrix(10, 20)
20 21
#'
#' # Rotates matrix m1 on m2
22
#' mr <- protate(m1, m2)
23
#'
24 25
#' @author Christelle Gonindard-Melodelima
#' @author Eric Coissac
Eric Coissac committed
26
#' @export
27 28 29 30
protate <- function(src, dest) {
  YX <- crossprod(dest, src)
  svd.YX <- svd(YX)
  rot <- svd.YX$v %*% t(svd.YX$u)
Eric Coissac committed
31 32
  src %*% rot
}