# \donttest{
A<-c(0,0,0); B<-c(1,0,0); C<-c(1/2,sqrt(3)/2,0);
D<-c(1/2,sqrt(3)/6,sqrt(6)/3)
set.seed(1)
tetra<-rbind(A,B,C,D)+matrix(runif(12,-.25,.25),ncol=3)
n<-10 #try also n<-20
Cent<-"CC" #try also "CM"
n<-20 #try also n<-100
Xp<-runif.tetra(n,tetra)$g #try also Xp<-cbind(runif(n),runif(n),runif(n))
Ext<-cl2faces.vert.reg.tetra(Xp,tetra,Cent)
Ext
summary(Ext)
plot(Ext)
clf<-Ext$ext
if (Cent=="CC") {M<-circumcenter.tetra(tetra)}
if (Cent=="CM") {M<-apply(tetra,2,mean)}
Xlim<-range(tetra[,1],Xp[,1],M[1])
Ylim<-range(tetra[,2],Xp[,2],M[2])
Zlim<-range(tetra[,3],Xp[,3],M[3])
xd<-Xlim[2]-Xlim[1]
yd<-Ylim[2]-Ylim[1]
zd<-Zlim[2]-Zlim[1]
plot3D::scatter3D(Xp[,1],Xp[,2],Xp[,3], phi =0,theta=40, bty = "g",
main="Closest Pointsin CC-Vertex Regions \n to the Opposite Faces",
xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05), zlim=Zlim+zd*c(-.05,.05),
pch = 20, cex = 1, ticktype = "detailed")
#add the vertices of the tetrahedron
plot3D::points3D(tetra[,1],tetra[,2],tetra[,3], add=TRUE)
L<-rbind(A,A,A,B,B,C); R<-rbind(B,C,D,C,D,D)
plot3D::segments3D(L[,1], L[,2], L[,3], R[,1], R[,2],R[,3], add=TRUE,lwd=2)
plot3D::points3D(clf[,1],clf[,2],clf[,3], pch=4,col="red", add=TRUE)
plot3D::text3D(tetra[,1],tetra[,2],tetra[,3],
labels=c("A","B","C","D"), add=TRUE)
#for center of mass use #Cent<-apply(tetra,2,mean)
D1<-(A+B)/2; D2<-(A+C)/2; D3<-(A+D)/2;
D4<-(B+C)/2; D5<-(B+D)/2; D6<-(C+D)/2;
L<-rbind(D1,D2,D3,D4,D5,D6); R<-rbind(M,M,M,M,M,M)
plot3D::segments3D(L[,1], L[,2], L[,3], R[,1], R[,2],R[,3], add=TRUE,lty=2)
# }
Run the code above in your browser using DataLab