# NOT RUN {
c1<-.4; c2<-.6;
A<-c(0,0); B<-c(1,0); C<-c(c1,c2);
Tb<-rbind(A,B,C)
n<-10 #try also n<-20
set.seed(1)
dat<-runif.bastri(n,c1,c2)$g
M<-as.numeric(runif.bastri(1,c1,c2)$g) #try also M<-c(.6,.3)
r<-2
P<-c(.4,.2)
Gam1PEbastri(P,dat,r,c1,c2,M)
Gam1PEbastri(P,P,r,c1,c2,M)
Gam1PEbastri(dat[1,],dat,r,c1,c2,M)
Gam1PEbastri(c(1,1),dat,r,c1,c2,M)
Gam1PEbastri(c(1,1),dat,r,c1,c2,M,ch.data.pnt = FALSE)
#gives an error message if ch.data.pnt = TRUE since point p=c(1,1) is not a data point in Dt
Gam1PEbastri(c(1,1),c(1,1),r,c1,c2,M)
#or try
Rv<-rv.bastri.cent(dat[1,],c1,c2,M)$rv
Gam1PEbastri(dat[1,],dat,r,c1,c2,M,Rv)
Gam1PEbastri(c(2,1),dat,r,c1,c2,M)
Gam1PEbastri(c(.2,.1),dat,r,c1,c2,M)
gam.vec<-vector()
for (i in 1:n)
{gam.vec<-c(gam.vec,Gam1PEbastri(dat[i,],dat,r,c1,c2,M))}
ind.gam1<-which(gam.vec==1)
ind.gam1
Xlim<-range(Tb[,1],dat[,1])
Ylim<-range(Tb[,2],dat[,2])
xd<-Xlim[2]-Xlim[1]
yd<-Ylim[2]-Ylim[1]
if (dimension(M)==3) {M<-bary2cart(M,Tb)}
#need to run this when M is given in barycentric coordinates
if (identical(M,circ.cent.tri(Tb)))
{
plot(Tb,pch=".",asp=1,xlab="",ylab="",axes=TRUE,
xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05))
polygon(Tb)
points(dat,pch=1,col=1)
Ds<-rbind((B+C)/2,(A+C)/2,(A+B)/2)
} else
{plot(Tb,pch=".",xlab="",ylab="",axes=TRUE,
xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05))
polygon(Tb)
points(dat,pch=1,col=1)
Ds<-cp2e.bastri(c1,c2,M)}
L<-rbind(M,M,M); R<-Ds
segments(L[,1], L[,2], R[,1], R[,2], lty=2)
points(rbind(dat[ind.gam1,]),pch=4,col=2)
txt<-rbind(Tb,M,Ds)
xc<-txt[,1]+c(-.02,.02,.02,-.02,.03,-.03,.01)
yc<-txt[,2]+c(.02,.02,.02,-.02,.02,.02,-.03)
txt.str<-c("A","B","C","M","D1","D2","D3")
text(xc,yc,txt.str)
P<-c(.4,.2)
Gam1PEbastri(P,dat,r,c1,c2,M)
Gam1PEbastri(P,rbind(dat,dat),r,c1,c2,M)
dat.fr<-data.frame(a=dat)
Gam1PEbastri(P,dat.fr,r,c1,c2,M)
Gam1PEbastri(c(.2,.1),dat,r,c1,c2,M,ch.data.pnt=FALSE)
#gives an error message if ch.data.pnt=TRUE since point p is not a data point in Dt
# }
Run the code above in your browser using DataLab