rel.vert.tri: The index of the vertex region in a triangle that contains a...

View source: R/AuxDelaunay.R

rel.vert.triR Documentation

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

Description

Returns the index of the related vertex in the triangle, tri, whose region contains point p.

Vertex regions are based on the general center M=(m_1,m_2) in Cartesian coordinates or M=(\alpha,\beta,\gamma) in barycentric coordinates in the interior of the triangle tri. Vertices of the triangle tri are labeled according to the row number the vertex is recorded.

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, M, and projections from M to the edges on the lines joining vertices and M (see the illustration in the examples).

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

Usage

rel.vert.tri(p, tri, M)

Arguments

p

A 2D point for which M-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.

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.

Value

A list with two elements

rv

Index of the vertex whose region contains point, p; index of the vertex is the same as the row number in the triangle, tri

tri

The vertices of the triangle, tri, where row number corresponds to the vertex index rv with rv=1 is row 1, rv=2 is row 2, and rv=3 is is row 3.

Author(s)

Elvan Ceyhan

References

\insertAllCited

See Also

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

Examples

## Not run: 
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(1.5,1.6)
rel.vert.tri(P,Tr,M)
#try also rel.vert.tri(P,Tr,M=c(2,2))
#center is not in the interior of the triangle

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

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

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

Ds<-prj.cent2edges(Tr,M)

Xlim<-range(Tr[,1],Xp[,1])
Ylim<-range(Tr[,2],Xp[,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="",
main="Illustration of M-Vertex Regions\n in a Triangle",axes=TRUE,
xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05))
polygon(Tr)
points(Xp,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,-.04,0)
yc<-txt[,2]+c(-.02,.04,.05,-.08)
txt.str<-c("M","D1","D2","D3")
text(xc,yc,txt.str)
text(Xp,labels=factor(Rv))

## End(Not run)


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