# NOT RUN {
A<-c(0,0); B<-c(1,0); C<-c(1/2,sqrt(3)/2);
Te<-rbind(A,B,C)
n<-10 #try also n<-20
set.seed(1)
dat<-runifTe(n)$gen.points
M<-as.numeric(runifTe(1)$g) #try also M<-c(.6,.2)
rvTe.cent(dat[1,],M)
rvTe.cent(c(.7,.2),M)
rvTe.cent(c(0,1),M)
Rv<-vector()
for (i in 1:n)
Rv<-c(Rv,rvTe.cent(dat[i,],M)$rv)
Rv
Ds<-cp2e.tri(Te,M)
Xlim<-range(Te[,1],dat[,1])
Ylim<-range(Te[,2],dat[,2])
xd<-Xlim[2]-Xlim[1]
yd<-Ylim[2]-Ylim[1]
if (dimension(M)==3) {M<-bary2cart(M,Te)}
#need to run this when M is given in barycentric coordinates
plot(Te,asp=1,pch=".",xlab="",ylab="",axes=TRUE,
xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05))
polygon(Te)
points(dat,pch=".",col=1)
L<-rbind(M,M,M); R<-Ds
segments(L[,1], L[,2], R[,1], R[,2], lty=2)
txt<-rbind(Te,M)
xc<-txt[,1]+c(-.02,.03,.02,0)
yc<-txt[,2]+c(.02,.02,.03,.05)
txt.str<-c("A","B","C","M")
text(xc,yc,txt.str)
text(dat,labels=factor(Rv))
rvTe.cent(c(.7,.2),M)
# }
Run the code above in your browser using DataLab