# \donttest{
A<-c(1,1); B<-c(2,0); C<-c(1.5,2);
Tr<-rbind(A,B,C);
M<-as.numeric(runif.tri(1,Tr)$g) #try also M<-c(.6,.2)
P1<-as.numeric(runif.tri(1,Tr)$g) #try also P1<-c(1.3,1.2)
NAStri(P1,Tr,M)
#or try
Rv<-rel.vert.triCC(P1,Tr)$rv
NAStri(P1,Tr,M,Rv)
NAStri(c(3,5),Tr,M)
P2<-c(1.5,1.4)
NAStri(P2,Tr,M)
P3<-c(1.5,.4)
NAStri(P3,Tr,M)
if (dimension(M)==3) {M<-bary2cart(M,Tr)}
#need to run this when M is given in barycentric coordinates
CC<-circumcenter.tri(Tr) #the circumcenter
if (isTRUE(all.equal(M,CC)) || identical(M,"CC"))
{cent<-CC
D1<-(B+C)/2; D2<-(A+C)/2; D3<-(A+B)/2;
Ds<-rbind(D1,D2,D3)
cent.name<-"CC"
rv<-rel.vert.triCC(P1,Tr)$rv
} else
{cent<-M
cent.name<-"M"
Ds<-prj.cent2edges(Tr,M)
rv<-rel.vert.tri(P1,Tr,M)$rv
}
RV<-Tr[rv,]
rad<-Dist(P1,RV)
Int.Pts<-NAStri(P1,Tr,M)
#plot of the NAS region
Xlim<-range(Tr[,1],P1[1]+rad,P1[1]-rad)
Ylim<-range(Tr[,2],P1[2]+rad,P1[2]-rad)
xd<-Xlim[2]-Xlim[1]
yd<-Ylim[2]-Ylim[1]
plot(A,pch=".",asp=1,xlab="",ylab="",xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05))
#asp=1 must be the case to have the arc properly placed in the figure
polygon(Tr)
points(rbind(Tr,P1,rbind(Int.Pts$L,Int.Pts$R)))
L<-rbind(cent,cent,cent); R<-Ds
segments(L[,1], L[,2], R[,1], R[,2], lty=2)
interp::circles(P1[1],P1[2],rad,lty=2)
L<-Int.Pts$L; R<-Int.Pts$R
segments(L[,1], L[,2], R[,1], R[,2], lty=1,col=2)
Arcs<-Int.Pts$a;
if (!is.null(Arcs))
{
K<-nrow(Arcs)/2
for (i in 1:K)
{A1<-Int.Pts$arc[2*i-1,]; A2<-Int.Pts$arc[2*i,];
angles<-angle.str2end(A1,P1,A2)$c
test.ang1<-angles[1]+(.01)*(angles[2]-angles[1])
test.Pnt<-P1+rad*c(cos(test.ang1),sin(test.ang1))
if (!in.triangle(test.Pnt,Tr,boundary = TRUE)$i) {angles<-c(min(angles),max(angles)-2*pi)}
plotrix::draw.arc(P1[1],P1[2],rad,angle1=angles[1],angle2=angles[2],col=2)
}
}
#proximity region with the triangle (i.e., for labeling the vertices of the NAS)
IP.txt<-intpts<-c()
if (!is.null(Int.Pts$a))
{
intpts<-unique(round(Int.Pts$a,7))
#this part is for labeling the intersection points of the spherical
for (i in 1:(length(intpts)/2))
IP.txt<-c(IP.txt,paste("I",i+1, sep = ""))
}
txt<-rbind(Tr,P1,cent,intpts)
txt.str<-c("A","B","C","P1",cent.name,IP.txt)
text(txt+cbind(rep(xd*.02,nrow(txt)),rep(-xd*.03,nrow(txt))),txt.str)
P1<-c(.3,.2)
NAStri(P1,Tr,M)
# }
Run the code above in your browser using DataLab