Learn R Programming

pcds (version 0.1.4)

rverts.tri.cent: The indices of the 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 Dt in a triangle tri\(=T(A,B,C)\).

Vertex regions are based on center \(M=(m_1,m_2)\) in Cartesian coordinates or \(M=(\alpha,\beta,\gamma)\) in barycentric coordinates in the interior of the triangle to the edges on the extension of the lines joining M to the vertices or based on the circumcenter of tri. Vertices of triangle tri are labeled as \(1,2,3\) according to the row number the vertex is recorded.

If a point in Dt is not inside tri, then the function yields NA as output for that entry. The corresponding vertex region is the polygon with the vertex, M, and projection points from M to the edges crossing the vertex (as the output of cp2e.tri(Tr,M)) or \(CC\)-vertex region. (see the examples for an illustration).

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

Usage

rverts.tri.cent(Dt, tri, M)

Value

A list with two elements

rv

Indices of the vertices whose regions contains points in Dt.

tri

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

Arguments

Dt

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

Three 2D points, stacked row-wise, each row representing a vertex of the triangle.

M

A 2D point in Cartesian coordinates or a 3D point in barycentric coordinates which serves as a center in the interior of the triangle tri or the circumcenter of tri.

Author

Elvan Ceyhan

References

See Also

rverts.triCM, rverts.triCC and rverts.tri.nd

Examples

Run this code
A<-c(1,1); B<-c(2,0); C<-c(1.5,2);
Tr<-rbind(A,B,C);
M<-c(1.6,1.0)

P<-c(.4,.2)
rverts.tri.cent(P,Tr,M)

P<-c(1.8,.5)
rverts.tri.cent(P,Tr,M)

P<-c(1.5,1.6)
rverts.tri.cent(P,Tr,M)

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

M<-as.numeric(runif.tri(1,Tr)$g)  #try also  #M<-c(1.6,1.0)

rverts.tri.cent(dat,Tr,M)
rverts.tri.cent(rbind(dat,c(2,2)),Tr,M)

rv<-rverts.tri.cent(dat,Tr,M)
rv

ifelse(identical(M,circ.cent.tri(Tr)),
Ds<-rbind((B+C)/2,(A+C)/2,(A+B)/2),Ds<-cp2e.tri(Tr,M))

Xlim<-range(Tr[,1],M[1],dat[,1])
Ylim<-range(Tr[,2],M[2],dat[,2])
xd<-Xlim[2]-Xlim[1]
yd<-Ylim[2]-Ylim[1]

if (dimension(M)==3) {M<-bary2cart(M,Tr)}
#need to run this when M is given in barycentric coordinates

plot(Tr,pch=".",xlab="",ylab="",axes=TRUE,
xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05))
polygon(Tr)
points(dat,pch=".",col=1)
L<-rbind(M,M,M); 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(M,Ds)
xc<-txt[,1]+c(.02,.04,-.03,0)
yc<-txt[,2]+c(.07,.04,.05,-.07)
txt.str<-c("M","D1","D2","D3")
text(xc,yc,txt.str)

text(dat,labels=factor(rv$rv))

P<-c(1.4,1.0)
rverts.tri.cent(P,Tr,M)
rverts.tri.cent(dat,Tr,M)

rverts.tri.cent(rbind(dat,dat),Tr,M)

dat.fr<-data.frame(a=dat)
rverts.tri.cent(dat.fr,Tr,M)

dat.fr<-data.frame(a=Tr)
rverts.tri.cent(dat,dat.fr,M)

Run the code above in your browser using DataLab