rel.vert.triCM: The index of the CM-vertex region in a triangle that contains...

View source: R/AuxDelaunay.R

rel.vert.triCMR Documentation

The index of the CM-vertex region in a triangle that contains a given point

Description

Returns the index of the vertex whose region contains point p in the triangle tri=(y_1,y_2,y_3) with vertex regions are constructed with center of mass CM=(y_1+y_2+y_3)/3 (see the plots in the example for illustrations).

The vertices of triangle, tri, are labeled as 1,2,3 according to the row number the vertex is recorded in tri. If the point, p, is not inside tri, then the function yields NA as output. The corresponding vertex region is the polygon with the vertex, CM, and midpoints of the edges adjacent to the vertex.

See (\insertCiteceyhan:Phd-thesis,ceyhan:comp-geo-2010,ceyhan:mcap2012;textualpcds)

Usage

rel.vert.triCM(p, tri)

Arguments

p

A 2D point for which CM-vertex region it resides in is to be determined in the triangle tri.

tri

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

Value

A list with two elements

rv

Index of the CM-vertex region that contains point, p in the triangle tri.

tri

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

Author(s)

Elvan Ceyhan

References

\insertAllCited

See Also

rel.vert.tri, rel.vert.triCC, rel.vert.basic.triCM, rel.vert.basic.triCC, rel.vert.basic.tri, and rel.vert.std.triCM

Examples

## Not run: 
A<-c(1,1); B<-c(2,0); C<-c(1.6,2);
Tr<-rbind(A,B,C);
P<-c(1.4,1.2)
rel.vert.triCM(P,Tr)

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

Rv<-vector()
for (i in 1:n)
  Rv<-c(Rv,rel.vert.triCM(Xp[i,],Tr)$rv)
Rv

CM<-(A+B+C)/3
D1<-(B+C)/2; D2<-(A+C)/2; D3<-(A+B)/2;
Ds<-rbind(D1,D2,D3)

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

plot(Tr,xlab="",ylab="",axes=TRUE,pch=".",xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05))
polygon(Tr)
points(Xp,pch=".")
L<-Ds; R<-matrix(rep(CM,3),ncol=2,byrow=TRUE)
segments(L[,1], L[,2], R[,1], R[,2], lty = 2)
text(Xp,labels=factor(Rv))

txt<-rbind(Tr,CM,D1,D2,D3)
xc<-txt[,1]+c(-.02,.02,.02,-.02,.02,-.01,-.01)
yc<-txt[,2]+c(-.02,-.04,.06,-.02,.02,.06,-.06)
txt.str<-c("rv=1","rv=2","rv=3","CM","D1","D2","D3")
text(xc,yc,txt.str)

## End(Not run)


elvanceyhan/pcds documentation built on June 29, 2023, 8:12 a.m.