Here is an R function that does what you describe:
dynmodfunc <- function() {
plot(0:1,0:1,ann=FALSE,type='n')
mypoints <- matrix(ncol=2, nrow=0)
while( length(p <- locator(1, type='p', col='red')) ) {
mypoints <- rbind(mypoints, unlist(p))
plot(mypoints, col='red', ann=FALSE, xlim=0:1, ylim=0:1)
if(nrow(mypoints)>1) {
xspline(mypoints, shape=-1)
}
}
mypoints
}
(out <- dynmodfunc())
You can change the shape
argument to xspline
to change the style of spline. This version returns a 2 column matrix with the x and y values, but that could be changed to another structure if prefered. There are plenty of other things that could be customized as well.
Added function to get the output to paste into Mathematica:
matrix2mathematica <- function(x) {
paste0( '{',
paste0( '{', x[,1], ', ', x[,2], '}', collapse=', '),
'}')
}
cat( matrix2mathematica(out))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…