"Fseval" = function(tpscoeff, coords1, target) { #thin-plate spline defined on coords1, evaluated on target # if(mode(coords1) == "complex") c1 <- coords1 else { c1a <- coords1 c1 <- complex(real = c1a[, 1], imag = c1a[, 2]) } if(mode(target) == "complex") t1 <- target else { t1a <- target t1 <- complex(real = t1a[, 1], imag = t1a[, 2]) } nland <- length(c1) ntarg <- length(t1) affine <- array(tpscoeff[nland + 1.], ntarg) + tpscoeff[nland + 2.] * Re(t1) + tpscoeff[nland + 3.] * Im(t1) kernels <- array(t1, c(ntarg, nland)) centers <- aperm(array(c1, c(nland, ntarg)), c(2., 1.)) sepmtx <- kernels - centers terms <- Re(sepmtx * Conj(sepmtx)) terms <- ifelse(terms > 0., 0.5 * terms * log(terms), 0.) coeffs <- aperm(array(tpscoeff[1.:nland], c(nland, ntarg)), c(2., 1.)) partials <- terms * coeffs nonaff <- apply(partials, 1., sum) dtarget <- affine + nonaff dtarget <- cbind(Re(dtarget), Im(dtarget)) return(list(affine = affine, nonaff = nonaff, dtarget = dtarget)) }