#nx is number of X points (target) and ny is number of Y points (nontarget)
nx<-20; ny<-4; #try also nx<-1000; ny<-10;
set.seed(1)
Yp<-cbind(runif(ny),runif(ny))
del<-.4
Xdt<-rsegMT(nx,Yp,del)
Xdt
summary(Xdt)
plot(Xdt)
Yp<-cbind(runif(ny),runif(ny))
del<-.3 #try .5, .75, .85
dat<-rsegMT(nx,Yp,del) #data under CSR in the convex hull of Ypoints
#or use
DTY<-interp::tri.mesh(Yp[,1],Yp[,2],duplicate="remove") #Delaunay triangulation based on Y points
dat<-rsegMT(nx,Yp,del,DTY) #data under CSR in the convex hull of Ypoints
#or use
DTY<-interp::tri.mesh(Yp[,1],Yp[,2],duplicate="remove") #Delaunay triangulation based on Y points
TRY<-interp::triangles(DTY)[,1:3];
dat<-rsegMT(nx,Yp,del,DTr=TRY) #data under CSR in the convex hull of Ypoints
#or use
DTY<-interp::tri.mesh(Yp[,1],Yp[,2],duplicate="remove") #Delaunay triangulation based on Y points
TRY<-interp::triangles(DTY)[,1:3];
dat<-rsegMT(nx,Yp,del,DTY,TRY)$gen.points #data under CSR in the convex hull of Ypoints
Xlim<-range(Yp[,1])
Ylim<-range(Yp[,2])
xd<-Xlim[2]-Xlim[1]
yd<-Ylim[2]-Ylim[1]
#plot of the data in the convex hull of Y points together with the Delaunay triangulation
DTY<-interp::tri.mesh(Yp[,1],Yp[,2],duplicate="remove") #Delaunay triangulation based on Y points
oldpar <- par(no.readonly = TRUE)
par(pty="s")
plot(dat,main=" ", xlab=" ", ylab=" ",xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05),type="n")
interp::plot.triSht(DTY, add=TRUE, do.points=TRUE,col="blue")
points(dat,pch=".",cex=3)
par(oldpar)
Yp<-rbind(c(.3,.2),c(.4,.5),c(.14,.15))
rsegMT(nx,Yp,del)
dat.fr<-data.frame(a=Yp)
rsegMT(nx,dat.fr,del)
Run the code above in your browser using DataLab