New fixed.angle() Function

(This article was first published on geomorph, and kindly contributed to R-bloggers)


Hello morphometricians,
Below you can find a new fixed angle function addressing the problem discovered by Fabio Machado in the morphmet mail archive. We will include this function in our next schedule update to geomorph.

Cheers,

Erik

CODE:

fixed.angle<-function(A,art.pt=NULL,angle.pts=NULL,rot.pts=NULL,angle=0){
if (length(dim(A))!=3){
stop("Data matrix 1 not a 3D array (see ‘arrayspecs’).") }
if(length(grep("-999",A))!=0){
stop("Data matrix 1 contains missing values. Estimate these first(see ‘estimate.missing’).") }
n<-dim(A)[3]; k<-dim(A)[2]; p<-dim(A)[1]
if (k!=2){
stop("Method presently implemented for two-dimensional data only.")}
if (angle>pi*2){
stop("Additional angle must be specified in radians.")}
if (angle< -pi*2){
stop("Additional angle must be specified in radians.")}
angl<-array(NA,dim=n)
for (i in 1:n){
A[,,i]<-t(t(A[,,i])-A[art.pt,,i])
angl[i]<- acos((A[angle.pts[1],,i]/sqrt(sum(A[angle.pts[1],,i]^2)))%*%(A[angle.pts[2],,i]/sqrt(sum(A[angle.pts[2],,i]^2))))
}
dev.angle<- (angl-mean(angl))+angle
if(A[angle.pts[1],1,1]<0){dev.angle<- -1*dev.angle}
for (i in 1:n){
r = matrix(c(cos(dev.angle[i]),-sin(dev.angle[i]),sin(dev.angle[i]),cos(dev.angle[i])),2)
A[rot.pts,,i] = A[rot.pts,,i]%*%r
}
return(A)
}

To leave a comment for the author, please follow the link and comment on their blog: geomorph.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Mango solutions



RStudio homepage



Zero Inflated Models and Generalized Linear Mixed Models with R

Dommino data lab

Quantide: statistical consulting and training



http://www.eoda.de







ODSC

ODSC

CRC R books series





Six Sigma Online Training





Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)