Learn R Programming

pcds (version 0.1.8)

rel.verts.triCC: The indices of the \(CC\)-vertex regions in a triangle that contains the points in a give data set.

Description

Returns the indices of the vertices whose regions contain the points in data set Xp in a triangle tri\(=(A,B,C)\) and vertex regions are based on the circumcenter \(CC\) of tri. (see the plots in the example for illustrations).

The vertices of the triangle tri are labeled as \(1=A\), \(2=B\), and \(3=C\) also according to the row number the vertex is recorded in tri. If a point in Xp is not inside tri, then the function yields NA as output. The corresponding vertex region is the polygon whose interior points are closest to that vertex. If tri is equilateral triangle, then \(CC\) and \(CM\) (center of mass) coincide.

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

Usage

rel.verts.triCC(Xp, tri)

Value

A list with two elements

rv

Indices (i.e., a vector of indices) of the vertices whose region contains points in Xp in the triangle tri

tri

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

Arguments

Xp

A set of 2D points representing the set of data points for which indices of the vertex regions containing them are to be determined.

tri

A \(3 \times 2\) matrix with each row representing a vertex of the triangle.

Author

Elvan Ceyhan

References

See Also

rel.verts.triCM, rel.verts.tri, and rel.verts.tri.nondegPE

Examples

Run this code
# \donttest{
A<-c(1,1); B<-c(2,0); C<-c(1.5,2);
Tr<-rbind(A,B,C);

P<-c(.4,.2)
rel.verts.triCC(P,Tr)

n<-20  #try also n<-40
set.seed(1)
Xp<-runif.tri(n,Tr)$g

rel.verts.triCC(Xp,Tr)
rel.verts.triCC(rbind(Xp,c(2,2)),Tr)

(rv<-rel.verts.triCC(Xp,Tr))

CC<-circumcenter.tri(Tr)
D1<-(B+C)/2; D2<-(A+C)/2; D3<-(A+B)/2;
Ds<-rbind(D1,D2,D3)

Xlim<-range(Tr[,1],Xp[,1],CC[1])
Ylim<-range(Tr[,2],Xp[,2],CC[2])
xd<-Xlim[2]-Xlim[1]
yd<-Ylim[2]-Ylim[1]

plot(Tr,pch=".",asp=1,xlab="",ylab="",
main="Scatterplot of data points \n and the CC-vertex regions",
axes=TRUE,xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05))
polygon(Tr)
points(Xp,pch=".",col=1)
L<-matrix(rep(CC,3),ncol=2,byrow=TRUE); R<-Ds
segments(L[,1], L[,2], R[,1], R[,2], lty = 2)

xc<-Tr[,1]
yc<-Tr[,2]
txt.str<-c("rv=1","rv=2","rv=3")
text(xc,yc,txt.str)

txt<-rbind(CC,Ds)
xc<-txt[,1]+c(.04,.04,-.03,0)
yc<-txt[,2]+c(-.07,.04,.06,-.08)
txt.str<-c("CC","D1","D2","D3")
text(xc,yc,txt.str)
text(Xp,labels=factor(rv$rv))
# }

Run the code above in your browser using DataLab