Learn R Programming

pcds (version 0.1.2)

rv.bastri.cent: The index of the vertex region in a basic triangle that contains a given point

Description

Returns the index of the related vertex in the basic triangle whose region contains point p. The basic triangle is \(T_b=T((0,0),(1,0),(c_1,c_2))\) where \(c_1\) is in \([0,1/2]\), \(c_2>0\) and \((1-c_1)^2+c_2^2 \le 1\)..

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 basic triangle \(T_b\). Vertices of the basic triangle \(T_b\) are labeled according to the row number the vertex is recorded, i.e., as 1=(0,0), 2=(1,0),and \(3=(c_1,c_2)\).

If the point, p, is not inside \(T_b\), 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. That is, rv=1 has vertices \((0,0),D_3,M,D_2\); rv=2 has vertices \((1,0),D_1,M,D_3\); and \(rv=3\) has vertices \((c_1,c_2),D_2,M,D_1\) (see the illustration in the examples).

Any given triangle can be mapped to the basic triangle by a combination of rigid body motions (i.e., translation, rotation and reflection) and scaling, preserving uniformity of the points in the original triangle. Hence basic triangle is useful for simulation studies under the uniformity hypothesis.

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

Usage

rv.bastri.cent(p, c1, c2, M)

Arguments

p

A 2D point for which M-vertex region it resides in is to be determined in the basic triangle \(T_b\).

c1, c2

Positive real numbers which constitute the vertex of the basic triangle adjacent to the shorter edges; \(c_1\) must be in \([0,1/2]\), \(c_2>0\) and \((1-c_1)^2+c_2^2 \le 1\).

M

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

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 basic triangle, \(T_b\)

tri

The vertices of the basic triangle, \(T_b\), where row number corresponds to the vertex index rv with rv=1 is row \(1=(0,0)\), rv=2 is row \(2=(1,0)\), and \(rv=3\) is row \(3=(c_1,c_2)\).

References

See Also

rv.bastriCM, rv.tri.cent, rv.triCC, rv.bastriCC, rv.triCM, and rvTeCM

Examples

Run this code
# NOT RUN {
c1<-.4; c2<-.6
A<-c(0,0); B<-c(1,0); C<-c(c1,c2);
Tb<-rbind(A,B,C);
M<-c(.6,.2)

P<-c(.4,.2)
rv.bastri.cent(P,c1,c2,M)

P<-c(1.8,.5)
rv.bastri.cent(P,c1,c2,M)

P<-c(.5,.26)
rv.bastri.cent(P,c1,c2,M)

n<-10  #try also n<-20
set.seed(1)
dat<-runif.bastri(n,c1,c2)$g

M<-as.numeric(runif.bastri(1,c1,c2)$g)  #try also M<-c(.6,.2)

Rv<-vector()
for (i in 1:n)
{ Rv<-c(Rv,rv.bastri.cent(dat[i,],c1,c2,M)$rv)}
Rv

Ds<-cp2e.bastri(c1,c2,M)

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

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

plot(Tb,pch=".",xlab="",ylab="",axes=TRUE,
xlim=Xlim+xd*c(-.1,.1),ylim=Ylim+yd*c(-.05,.05))
polygon(Tb)
points(dat,pch=".",col=1)
L<-rbind(M,M,M); R<-Ds
segments(L[,1], L[,2], R[,1], R[,2], lty=2)

xc<-Tb[,1]+c(-.04,.05,.04)
yc<-Tb[,2]+c(.02,.02,.03)
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(-.02,.02,.02,-.03)
txt.str<-c("M","D1","D2","D3")
text(xc,yc,txt.str)

text(dat,labels=factor(Rv))

P<-c(.4,.2)
rv.bastri.cent(P,c1,c2,M)

# }

Run the code above in your browser using DataLab