if (FALSE) # Takes too long.
set.seed(42)
x <- runif(20)
y <- runif(20)
dxy <- deldir(x,y,rw=c(0,1,0,1))
cxy1 <- cvt(dxy,verb=TRUE)
plot(cxy1$tiles)
with(cxy1$centroids,points(x,y,pch=20,col="red"))
cxy2 <- cvt(dxy,stopcrit="m",verb=TRUE)
plot(cxy2$tiles)
with(cxy2$centroids,points(x,y,pch=20,col="red"))
# Visually indistinguishable from the cxy1 plot.
# But ...
all.equal(cxy1$centroids,cxy2$centroids) # Not quite.
cxy3 <- cvt(dxy,stopcrit="m",verb=TRUE,maxit=250)
all.equal(cxy1$centroids,cxy3$centroids) # Close, but no cigar.
cxy4 <- cvt(dxy,verb=TRUE,tol=1e-14)
cxy5 <- cvt(dxy,stopcrit="m",verb=TRUE,maxit=600)
all.equal(cxy4$centroids,cxy5$centroids) # TRUE
# Takes a lot of iterations or a really small tolerance
# to get "good" convergence. But this is almost surely
# of no practical importance.
txy <- tile.list(dxy)
cxy6 <- cvt(txy)
all.equal(cxy6$centroids,cxy1$centroids) # TRUE
Run the code above in your browser using DataLab