Learn R Programming

pcds (version 0.1.2)

rv.tetraCM: The index of the \(CM\)-vertex region in a tetrahedron that contains a point

Description

Returns the index of the vertex whose region contains point p in a tetrahedron \(th=T(A,B,C,D)\) and vertex regions are based on the center of mass \(CM=(A+B+C+D)/4\) of th. (see the plots in the example for illustrations).

The vertices of the tetrahedron th are labeled as \(1=A\), \(2=B\), \(3=C\), and \(4=C\) also according to the row number the vertex is recorded in th.

If the point, p, is not inside th, then the function yields NA as output. The corresponding vertex region is the simplex with the vertex, \(CM\), and midpoints of the edges adjacent to the vertex.

See also (ceyhan:Phd-thesis,ceyhan:comp-geo-2010;textualpcds).

Usage

rv.tetraCM(p, th)

Arguments

p

A 3D point for which \(CM\)-vertex region it resides in is to be determined in the tetrahedron th.

th

Four 3D points, stacked row-wise, each row representing a vertex of the tetrahedron.

Value

A list with two elements

rv

Index of the \(CM\)-vertex region that contains point, p in the tetrahedron th

th

The vertices of the tetrahedron, where row number corresponds to the vertex index in rv.

References

See Also

rv.tetraCC and rv.triCM

Examples

Run this code
# NOT RUN {
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)
tetra<-rbind(A,B,C,D)

n<-10  #try also n<-20

Dt<-runif.stdtetra(n)$g

rv.tetraCM(Dt[1,],tetra)
rv.tetraCM(Dt[5,],tetra)
rv.tetraCM(c(2,2,2),tetra)

Rv<-vector()
for (i in 1:n)
  Rv<-c(Rv, rv.tetraCM(Dt[i,],tetra)$rv )
Rv

Xlim<-range(tetra[,1],Dt[,1])
Ylim<-range(tetra[,2],Dt[,2])
Zlim<-range(tetra[,3],Dt[,3])
xd<-Xlim[2]-Xlim[1]
yd<-Ylim[2]-Ylim[1]
zd<-Zlim[2]-Zlim[1]

CM<-apply(tetra,2,mean)

plot3D::scatter3D(tetra[,1],tetra[,2],tetra[,3], phi =0,theta=40, bty = "g",
xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05), zlim=Zlim+zd*c(-.05,.05),
          pch = 20, cex = 1, ticktype = "detailed")
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)
#add the data points
plot3D::points3D(Dt[,1],Dt[,2],Dt[,3], add=TRUE)

plot3D::text3D(tetra[,1],tetra[,2],tetra[,3], labels=c("A","B","C","D"), add=TRUE)
plot3D::text3D(CM[1],CM[2],CM[3], labels=c("CM"), add=TRUE)

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<-matrix(rep(CM,6),ncol=3,byrow=TRUE)
plot3D::segments3D(L[,1], L[,2], L[,3], R[,1], R[,2],R[,3], add=TRUE,lty=2)

F1<-int.line.plane(A,CM,B,C,D)
L<-matrix(rep(F1,4),ncol=3,byrow=TRUE); R<-rbind(D4,D5,D6,CM)
plot3D::segments3D(L[,1], L[,2], L[,3], R[,1], R[,2],R[,3],col=2, add=TRUE,lty=2)

F2<-int.line.plane(B,CM,A,C,D)
L<-matrix(rep(F2,4),ncol=3,byrow=TRUE); R<-rbind(D2,D3,D6,CM)
plot3D::segments3D(L[,1], L[,2], L[,3], R[,1], R[,2],R[,3],col=3, add=TRUE,lty=2)

F3<-int.line.plane(C,CM,A,B,D)
L<-matrix(rep(F3,4),ncol=3,byrow=TRUE); R<-rbind(D3,D5,D6,CM)
plot3D::segments3D(L[,1], L[,2], L[,3], R[,1], R[,2],R[,3],col=4, add=TRUE,lty=2)

F4<-int.line.plane(D,CM,A,B,C)
L<-matrix(rep(F4,4),ncol=3,byrow=TRUE); R<-rbind(D1,D2,D4,CM)
plot3D::segments3D(L[,1], L[,2], L[,3], R[,1], R[,2],R[,3],col=5, add=TRUE,lty=2)

plot3D::text3D(Dt[,1],Dt[,2],Dt[,3], labels=factor(Rv), add=TRUE)

P<-c(.1,.1,.1)
rv.tetraCM(P,tetra)

dat.fr<-data.frame(a=tetra)
rv.tetraCM(P,dat.fr)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab