A<-c(1,1); B<-c(2,0); C<-c(1.6,2);
Tr<-rbind(A,B,C);
P<-c(1.4,1.2)
rv.triCM(P,Tr)
P<-c(.8,.2)
rv.triCM(P,Tr)
P<-c(1.5,1.6)
rv.triCM(P,Tr)
n<-10 #try also n<-20
dat<-runif.tri(n,Tr)$g
Rv<-vector()
for (i in 1:n)
Rv<-c(Rv,rv.triCM(dat[i,],Tr)$rv)
Rv
CM<-(A+B+C)/3
D1<-(B+C)/2; D2<-(A+C)/2; D3<-(A+B)/2;
Ds<-rbind(D1,D2,D3)
Xlim<-range(Tr[,1],dat[,1])
Ylim<-range(Tr[,2],dat[,2])
xd<-Xlim[2]-Xlim[1]
yd<-Ylim[2]-Ylim[1]
plot(Tr,xlab="",ylab="",axes=TRUE,pch=".",xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05))
polygon(Tr)
points(dat,pch=".")
L<-Ds; R<-matrix(rep(CM,3),ncol=2,byrow=TRUE)
segments(L[,1], L[,2], R[,1], R[,2], lty=2)
text(dat,labels=factor(Rv))
txt<-rbind(Tr,CM,D1,D2,D3)
xc<-txt[,1]+c(-.02,.02,.02,-.02,.02,-.01,-.01)
yc<-txt[,2]+c(-.02,-.04,.06,-.02,.02,.06,-.06)
txt.str<-c("rv=1","rv=2","rv=3","CM","D1","D2","D3")
text(xc,yc,txt.str)
rv.triCM(A,Tr)
rv.triCM(CM,Tr)
rv.triCM(D1,Tr)
rv.triCM(D2,Tr)
rv.triCM(D3,Tr)
#right triangle
A<-c(1,1); B<-c(1,2); C<-c(1.5,2);
T3<-rbind(A,B,C);
P<-c(1.1,1.5)
rv.triCM(P,T3)
#isosceles triangle
A<-c(1,1); B<-c(2,1); C<-c(1.5,2);
Tr<-rbind(A,B,C);
P<-c(1.5,1.1)
rv.triCM(P,Tr)
dat.fr<-data.frame(a=Tr)
rv.triCM(P,dat.fr)
Run the code above in your browser using DataLab