View source: R/findOptimalPointAlignment.R

findOptimalPointAlignment | R Documentation |

This function translates and rotates one point set, optimally aligning it with another point set.

findOptimalPointAlignment(m1, m2, sign = NULL)

`m1` |
a point set matrix |

`m2` |
a second point set matrix of the same dimensions as |

`sign` |
Used for debugging. |

This function optimally aligns point set `m2`

with point set `m1`

. `m1`

and `m2`

must contain the exact same landmarks or points in the same order. Points present in `m2`

but not `m1`

should be `NA`

in `m1`

. They do not need to be `NA`

in `m2`

; all translations and rotations will be applied to all points in `m2`

even though only shared points will be used in the alignment.

The function first centers the centroid `m2`

about the centroid of `m1`

. The function `svd()`

is then used to find the 3D rotation matrix that optimally aligns `m2`

to `m1`

based on common points. The positions of points in `m2`

relative to one another are unchanged. Thus, optimal rotation is constrained to already translated point sets. Depending on the point sets, a better alignment may be possible by allowing translation and rotation to be optimized simultaneously.

This function is called by `unifyLandmarks`

to align landmark sets and by `dltTestCalibration`

to test accuracy in reconstructed calibration grids.

`m2`

after alignment.

Modified from `unifyVD()`

by Annat Haber.

Annat Haber, Aaron Olsen

Rohlf, F.J. (1990) "Chapter 10. Rotational fit (Procrustes) Methods." *Proceedings of the Michigan Morphometrics Workshop*. Ed. F. James Rohlf and Fred L. Bookstein. The University of Michigan Museum of Zoology, 1990. 227–236. Info page at lib.umich.edu

`unifyLandmarks`

## MAKE MATRIX OF 3D POINTS m1 <- matrix(c(0,0,0, 1,3,2, 4,2,1, 5,5,3, 1,4,2, 3,6,4), nrow=6, ncol=3) ## COPY TO M2 m2 <- m1 ## MAKE MISSING POINT IN M1 ## ALTHOUGH NOT USED IN THE ALIGNMENT THE CORRESPONDING POINT ## IN M2 IS STILL RETURNED AFTER ALIGNMENT m1[3, ] <- NA ## CENTER M2 ABOUT CE m2 <- m2 %*% rotationMatrixZYX_SM(pi/6, -pi/3, pi/8) ## TRANSLATE M2 m2 <- m2 + matrix(c(2,3,4), nrow=6, ncol=3, byrow=TRUE) ## ALIGN M2 TO M1 m3 <- findOptimalPointAlignment(m1, m2) ## NOTE THAT RETURNED MATRIX IS IDENTICAL TO M1 ## OF COURSE REAL WORLD DATA WILL HAVE SOME ERROR m1 m3

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.