First we load the `pcds`

package:

`library(pcds)`

Due to geometry invariance of PE- and CS-PCDs for uniform data (which will be the vertices of the PCDs)
in any triangle in 2D space,
most computations (and if needed data generation and simulations) can be done in the standard equilateral triangle,
and for AS-PCD, one can restrict attention to the standard basic triangle.
The *standard equilateral triangle* is \(T_e=T(A,B,C)\) with vertices \(A=(0,0)\), \(B=(1,0)\), and \(C=(1/2,\sqrt{3}/2)\)
and the *standard basic triangle* is \(T_b=T(A,B,C')\) with vertices \(A=(0,0)\), \(B=(1,0)\), and \(C'=(c_1,c_2))\)
with \(0 < c_1 \le 1/2\), \(c_2>0\),
and \((1-c_1)^2+c_2^2 \le 1\).

Most of the PCD functions we will illustrate in this section are counterparts of the functions in Section “VS1_1_2DArtiData” (i.e. one-interval counterparts of the functions for the multiple-triangle setting). Sometimes we will be focusing on the standard equilateral triangle (for speed and ease of computation).

For more detail on the construction and appealing properties of PCDs in triangles, see Ceyhan (2010) and Ceyhan (2012).

We first choose an arbitrary triangle \(T=T(A,B,C)\) with vertices \(A=(1,1)\), \(B=(2,0)\), and \(C=(1.5,2)\), which happens to be an obtuse triangle, and choose an arbitrary point in the interior of this triangle as the center (to construct the vertex or edge regions).

```
<-c(1,1); B<-c(2,0); C<-c(1.5,2);
A<-rbind(A,B,C);
Tr<-5
n
set.seed(1)
<-runif.tri(n,Tr)$g #try also Xp<-cbind(runif(n,1,2),runif(n,0,2))
Xp<-c(1.6,1.2) #try also M<-as.numeric(runif.tri(1,Tr)$g) or M="CC" M
```

Then we generate \(n=\) 5 \(\mathcal{X}\) points inside the triangle \(T\) using the function `runif.tri`

in `pcds`

.
\(\mathcal{X}\) points are denoted as `Xp`

and \(\mathcal{Y}\) points in Section “VS1_1_2DArtiData”
correspond to the vertices of the triangle \(T\).
Hence, if the argument `Yp`

is used for a function for multiple triangles,
it is replaced with `tri`

a \(3 \times 2\) matrix in which rows represent the vertices of the triangle
for a function written for a general triangle,
with `c1,c2`

for a basic triangle,
or omitted for the standard equilateral triangle.

We plot the triangle \(T\) and the \(\mathcal{X}\) points in it using the below code,
and also add the vertex names using the `text`

function from base `R`

.

```
<-range(Tr[,1])
Xlim<-range(Tr[,2])
Ylimplot(Tr,pch=".",xlab="",ylab="",xlim=Xlim,ylim=Ylim+c(0,.1),main="Points in One Triangle")
polygon(Tr)
points(Xp)
#add the vertex names and annotation
<-rbind(Tr)
txt<-txt[,1]+c(-.01,.015,.02)
xc<-txt[,2]+c(.02,.02,.02)
yc<-c("A","B","C")
txt.strtext(xc,yc,txt.str)
```

Alternatively, we can use the `plotDeltri`

function in `pcds`

to obtain the same plot by executing `plotDeltri(Xp,Tr,xlab="x",ylab="y")`

.

Arc-Slice (AS) proximity region for a point is the intersection of the triangle containing the point
and the circle centered the point with radius being
the minimum distance from the point to the vertices of the triangle.
So, we first check whether a point is inside a circle or not by using the function `in.circle`

which returns `TRUE`

if the point is inside the circle, and `FALSE`

otherwise.
This function takes arguments `p,cent,rad,boundary`

where

`p`

is a 2D point to be checked whether it is inside the circle or not,`cent`

a 2D point in Cartesian coordinates which serves as the center of the circle,`rad`

a positive real number which serves as the radius of the circle,`boundary`

a logical parameter (default=`TRUE`

) to include boundary or not, so if it is`TRUE`

, the function checks if the point,`p`

, lies in the closure of the circle (i.e., interior and boundary combined); else, it checks if`p`

lies in the interior of the circle.

```
<-c(1,1); rad<-1; p<-c(1.4,1.2) #try also cent<-runif(2); rad<-runif(1); p<-runif(2);
centin.circle(p,cent,rad)
<-c(.4,-.2)
pin.circle(p,cent,rad)
1] TRUE
[1] FALSE [
```

The circle for an AS proximity region of an \(\mathcal{X}\) point \(x\) is centered at the point \(x\)
with radius being the distance from \(x\) to the closest class \(\mathcal{Y}\) point
(which is the closest vertex of the triangle \(T\) in the one triangle setting).
The radius of a point from one class with respect to points from the other class is provided by the function `radius`

which takes arguments `p,Y`

where

`p`

is the point to find the radius for and`Y`

is the matrix of non-target points.

The function also returns the index and coordinates of the class \(\mathcal{Y}\) point closest to the class \(\mathcal{X}\) point.
This function works for points in other dimensions as well.
See `? radius`

for further description.

```
<-5
ny<-cbind(runif(ny),runif(ny))
Y<-c(1,1);
Aradius(A,Y)
#> $rad
#> [1] 0.3767951
#>
#> $index.of.clYpnt
#> [1] 4
#>
#> $closest.Ypnt
#> [1] 0.6684667 0.8209463
```

The radii of points from one class with respect to points from the other class are found by using the function `radii`

which takes arguments `x,y`

where

`x`

is a set of \(d\)-dimensional points for which the radii are computed. Radius of an`x`

point equals to the distance to the closest`y`

point and`y`

is a set of \(d\)-dimensional points representing the reference points for the balls. That is, radius of an`x`

point is defined as the minimum distance to the`y`

points.

In addition to the radii, the function also returns the indices and coordinates of the class \(\mathcal{Y}\) points closest to the class \(\mathcal{X}\) points.
This function works for points in other dimensions as well.
See `? radii`

for further description.

```
<-6
nx<-5
ny<-cbind(runif(nx),runif(nx))
X<-cbind(runif(ny),runif(ny))
Y<-radii(X,Y)
Rad
Rad#> $radiuses
#> [1] 0.38015546 0.23618472 0.02161322 0.48477828 0.05674010 0.16819521
#>
#> $indices.of.closest.points
#> [1] 4 4 4 4 1 3
#>
#> $closest.points
#> [,1] [,2]
#> [1,] 0.51863426 0.4590657
#> [2,] 0.51863426 0.4590657
#> [3,] 0.51863426 0.4590657
#> [4,] 0.51863426 0.4590657
#> [5,] 0.07067905 0.4068302
#> [6,] 0.31627171 0.2936034
```

The function `NAStri`

is used for the construction of AS proximity regions taking the arguments

`p`

the point for which the AS proximity region is to be found,`tri`

the support triangle,`M`

is the center to construct the vertex regions with default`M="CC"`

(i.e. the circumcenter),`rv`

the index of the vertex regions that the point`p`

resides in with default`rv=NULL`

and`dec`

a positive integer the number of decimals (default is 4) to round the barycentric coordinates when checking whether the end points fall on the boundary of the triangle`tri`

or not.

`NAStri`

returns the proximity region as end points of the straight line segments on the boundary of the proximity region
(which also fall on the boundary of the triangle),
the end points of the arc slices which are the parts of the defining circle falling in the interior of the triangle
and the angles between the vectors joining `P`

and the end points of the arc slices and the horizontal line crossing the point `P`

.
It is also possible to specify the index of the vertex region for the point `P`

with the argument `rv=k`

for \(k=1,2,3\),
where \(k\) refers to the vertex in \(k\)-th row for the triangle `Tr`

(but this must be computed before such as in the code `Rv<-rv.triCC(P1,Tr)$rv; NAStri(P1,Tr,M,Rv)`

and it must be compatible with
the vertex region for the point `P`

).

```
<-c(1.8,.5)
PNAStri(P,Tr,M)
#> $L
#> [,1] [,2]
#> [1,] 2 0
#> [2,] 2 0
#>
#> $R
#> [,1] [,2]
#> [1,] 1.741176 1.035294
#> [2,] 1.300000 0.700000
#>
#> $arc.slices
#> [,1] [,2]
#> [1,] 1.741176 1.035294
#> [2,] 1.300000 0.700000
#>
#> $Angles
#> [1] 1.680247 2.761086
```

Indicator for the presence of an arc from a (data or \(\mathcal{X}\)) point to another for AS-PCDs is the function `IndNAStri`

.
One can use it for points in the data set or for arbitrary points (as if they were in the data set).
It takes the arguments,

`p1`

a 2D point whose AS proximity region is constructed,`p2`

another 2D point. The function determines whether`p2`

is inside the AS proximity region of`p1`

or not,`tri`

vertices of the support triangle, stacked row-wise, i.e., each row representing a vertex of the triangle,`M`

the center of the triangle to construct the vertex regions with, default is`M="CC"`

i.e., the circumcenter of`tri`

and`rv`

the index of the`M`

-vertex region in`tri`

containing the point, either 1,2,3 or`NULL`

(which is the default).

This function returns \(I(p2 \in N_{AS}(p1))\), that is, returns 1 if `p2`

is in \(N_{AS}(p1)\), 0 otherwise.

```
#between two arbitrary points P1 and P2
<-as.numeric(runif.tri(1,Tr)$g)
P1<-as.numeric(runif.tri(1,Tr)$g)
P2IndNAStri(P1,P2,Tr,M)
#> [1] 0
#between the first two points in Xp
IndNAStri(Xp[1,],Xp[2,],Tr,M)
#> [1] 0
```

AS proximity regions are defined with respect to the
vertices of the triangle (i.e., with respect to the vertex regions they reside in) and
vertex regions in each triangle are based on the center `M`

for circumcenter or \(M=(\alpha,\beta,\gamma)\) in barycentric coordinates in the
interior of the triangle; default is `M="CC"`

i.e., circumcenter of the triangle.

See Ceyhan (2005), Ceyhan (2010), and Ceyhan (2012) for more on AS-PCDs.

Number of arcs of the AS-PCD can be computed by the function `NumArcsAStri`

.
The function `NumArcsAStri`

takes `Xp,tri,M="CC"`

as its arguments
where `Xp`

is the data set, and the others are as above
and returns the list of

`num.arcs`

: Number of arcs of the AS-PCD,`num.in.tri`

: Number of`Xp`

points in the triangle`tri`

,`ind.in.tri`

: The vector of indices of the`Xp`

points that reside in the triangle.

```
NumArcsAStri(Xp,Tr) #with default M="CC"; try also NumArcsAStri(Xp,Tr,M)
#> $num.arcs
#> [1] 10
#>
#> $num.in.tri
#> [1] 5
#>
#> $ind.in.tri
#> [1] 1 2 3 4 5
```

The arc density of the AS-PCD can be computed by the function `ASarcdens.tri`

.
It takes the arguments `Xp,tri,M="CC",tri.cor`

where `Xp`

is the data set (or \(\mathcal{X}\) points)
`tri,M="CC"`

are as above.
Arc density can be adjusted (or corrected) for the points outside the triangle by using the option `tri.cor=T`

,
default option is `tri.cor=FALSE`

.

```
ASarcdens.tri(Xp,Tr,M)
#> [1] 0.5
```

The incidence matrix of the AS-PCD for the one triangle case can be found by `IncMatAStri`

,
using the `IncMatAStri(Xp,Tr,M)`

command.
It takes the same arguments as the function `NumArcsAStri`

.

Plot of the arcs in the digraph AS-PCD, which is based on the \(M\)-vertex regions with \(M=(\) 1.6,1.2 \()\),
can be obtained by the function `plotASarcs.tri`

, which is the one-tri counterpart of the function `plotASarcs`

.
It takes arguments `Xp,tri,M="CC"`

(as in `NumArcsAStri`

) and other options for the plot function.
See the help page for the function using `? plotASarcs.tri`

.

Plot of the arcs of the above AS-PCD,
together with the vertex regions (with the option `vert.reg = TRUE`

).

`plotASarcs.tri(Xp,Tr,M,xlab="",ylab="",vert.reg = TRUE)`

Or, one can use the default center `M="CC"`

, and can add vertex names and text to the figure (with vertex regions)
using the below code.
The part `M = as.numeric(ArcsAStri(Xp,Tr)$param)`

is optional,
for the below annotation of the plot since circumcenter is used for the vertex regions.

```
plotASarcs.tri(Xp,Tr,asp=1,xlab="",ylab="",vert.reg = TRUE); M = (ArcsAStri(Xp,Tr)$param)$c
<-circ.cent.tri(Tr)
CC
#determine whether the center used for vertex regions is circumcenter or not
if (identical(M,CC) || identical(M,"CC"))
<-CC
{cent<-(B+C)/2; D2<-(A+C)/2; D3<-(A+B)/2;
D1<-rbind(D1,D2,D3)
Ds<-"CC"
cent.nameelse
} <-M
{cent<-"M"
cent.name<-cent2edges.tri(Tr,M)
Ds
}
#add the vertex names and annotation
<-rbind(Tr,cent,Ds)
txt<-txt[,1]+c(-.02,.02,.02,.05,.05,-0.03,-.01)
xc<-txt[,2]+c(.02,.02,.02,.07,.02,.05,-.06)
yc<-c("A","B","C",cent.name,"D1","D2","D3")
txt.strtext(xc,yc,txt.str)
```

Plot of the AS proximity regions can be obtained by the function `plotASregs.tri`

.
It takes arguments `Xp,tri,M="CC"`

(as in `NumArcsAStri`

) and other options for the plot function.
See the help page for the function using `? plotASregs.tri`

.

```
<-c(1.6,1.2) #try also M<-c(1.6620051,0.8136604) or M="CC"
MplotASregs.tri(Xp,Tr,M,vert.reg = T,xlab="",ylab="")
```

The function `ArcsAStri`

is an object of class “`PCDs`

”.
It takes arguments `Xp,tri,M="CC"`

(as in `ASarcdens.tri`

).
The output list is as in the function `ArcsAS`

(see Section “VS1_1_2DArtiData”).
The `plot`

function returns the same plot as in `plotASarcs.tri`

with \(M=(\) 1.6,1.2 \()\),
hence we comment it out below.

```
=c(1.6,1.2) #try also M=c(1.6620051,0.8136604)
M
<-ArcsAStri(Xp,Tr,M) #try also Arcs<-ArcsAStri(Xp,Tr) #uses the default center, namely circumcenter for M
Arcs
Arcs#> Call:
#> ArcsAStri(Xp = Xp, tri = Tr, M = M)
#>
#> Type:
#> [1] "Arc Slice Proximity Catch Digraph (AS-PCD) for 2D Points in the Triangle with Center M = (1.6,1.2)"
summary(Arcs)
#> Call:
#> ArcsAStri(Xp = Xp, tri = Tr, M = M)
#>
#> Type of the digraph:
#> [1] "Arc Slice Proximity Catch Digraph (AS-PCD) for 2D Points in the Triangle with Center M = (1.6,1.2)"
#>
#> Vertices of the digraph = Xp
#> Partition points of the region = Tr
#>
#> Selected tail (or source) points of the arcs in the digraph
#> (first 6 or fewer are printed)
#> [,1] [,2]
#> [1,] 1.265509 0.7442478
#> [2,] 1.687023 0.7682074
#> [3,] 1.687023 0.7682074
#> [4,] 1.687023 0.7682074
#> [5,] 1.380035 1.5548904
#> [6,] 1.267221 0.7722282
#>
#> Selected head (or end) points of the arcs in the digraph
#> (first 6 or fewer are printed)
#> [,1] [,2]
#> [1,] 1.267221 0.7722282
#> [2,] 1.265509 0.7442478
#> [3,] 1.267221 0.7722282
#> [4,] 1.482080 1.1991317
#> [5,] 1.482080 1.1991317
#> [6,] 1.265509 0.7442478
#>
#> Parameters of the digraph
#> $center
#> [1] 1.6 1.2
#>
#> Various quantities of the digraph
#> number of vertices number of partition points
#> 5.0 3.0
#> number of triangles number of arcs
#> 1.0 10.0
#> arc density
#> 0.5
plot(Arcs)
```

To see the code and the plot for the arcs using the `plot.PCDs`

function,
with vertex names and annotation added to the plot,
type `? ArcsAStri`

.

In this section, we use the same triangle \(T\) and generate data as in Section 2.1.

```
#A<-c(1,1); B<-c(2,0); C<-c(1.5,2); Tr<-rbind(A,B,C); n<-5
#set.seed(1); Xp<-runif.tri(n,Tr)$g
<-c(1.6,1.0) #try also M<-as.numeric(runif.tri(1,Tr)$g)
M<-1.5 #try also r<-2 r
```

And choose the expansion parameter \(r=\) 1.5 to illustrate proportional edge (PE) proximity regions and the associated PCDs.

The function `NPEtri`

is used for the construction of PE proximity regions taking the arguments
`p,tri,r,M=c(1,1,1),rv=NULL`

where

`p,tri,rv=NULL`

are as in the function`NAStri`

, and`M`

is the center to construct the vertex regions with default`M=c(1,1,1)`

(i.e. the center of mass),`rv`

the index of the vertex regions that the point`p`

resides in with default`rv=NULL`

and`r`

is the expansion parameter (must be \(\ge 1\)).

`NPEtri`

returns the PE proximity region (i.e., the vertices of the triangular proximity region).

```
<-c(1.8,.5)
PNPEtri(P,Tr,r,M)
#> [,1] [,2]
#> [1,] 2.000 0.00
#> [2,] 1.550 0.45
#> [3,] 1.775 0.90
```

Indicator for the presence of an arc from a (data or \(\mathcal{X}\)) point to another for PE-PCDs is the function `IndNPEtri`

.
One can use it for points in the data set or for arbitrary points (as if they were in the data set).
It takes the arguments, `p1,p2,tri,r,M=c(1,1,1),rv=NULL`

where

-`p1,p2,tri,rv=NULL`

are as in `IndNAStri`

and
- `r,M=c(1,1,1)`

are as in `NPEtri`

.

This function returns \(I(p2 \in N_{PE}(p1))\),
that is, returns 1 if `p2`

is in \(N_{PE}(p1)\), 0 otherwise.

```
<-as.numeric(runif.tri(1,Tr)$g)
P1<-as.numeric(runif.tri(1,Tr)$g)
P2IndNPEtri(P1,P2,Tr,r,M)
#> [1] 1
IndNPEtri(Xp[1,],Xp[5,],Tr,r,M) #try also IndNPEtri(Xp[5,],Xp[1,],Tr,r,M)
#> [1] 0
```

Number of arcs of the PE-PCD can be computed by the function `NumArcsPEtri`

,
which takes arguments `Xp,tri,r,M=c(1,1,1)`

where `Xp`

is the data set, and the others are as above.
The output is as in `NumArcsAStri`

.

```
NumArcsPEtri(Xp,Tr,r,M)
#> $num.arcs
#> [1] 7
#>
#> $num.in.tri
#> [1] 5
#>
#> $ind.in.tri
#> [1] 1 2 3 4 5
```

The arc density of the PE-PCD can be computed by the function `PEarcdens.tri`

.
It takes the arguments `Xp,tri,r,M,tri.cor`

where `Xp`

is the data set (or \(\mathcal{X}\) points)
`r,tri,M`

are as above
and returns output as list with elements

`arc.dens`

, arc density of PE-PCD whose vertices are the 2D numerical data set,`Xp`

,`std.arc.dens`

, the arc density standardized by the mean and asymptotic variance of the arc density of PE-PCD for uniform data in the triangle`tri`

, and`caveat`

a warning as`"The standardized arc density is only correct when M is the center of mass in the current version"`

.

Arc density can be adjusted (or corrected) for the points outside the triangle by using the option `tri.cor=TRUE`

as in the `ASarcdens.tri`

.
Moreover, the standardized arc density is only correct when \(M\) is the center of mass in the current version.

```
PEarcdens.tri(Xp,Tr,r,M)
#> $arc.dens
#> [1] 0.35
```

The incidence matrix of the PE-PCD for the one triangle case can be found by the function `IncMatPEtri`

, using e.g. the `IncMatPEtri(Xp,Tr,r,M)`

command.
It takes the same arguments as the function `NumArcsPEtri`

.

Plot of the arcs in the digraph PE-PCD, which is based on the \(M\)-vertex regions with \(M=\)(1.6,1),
can be obtained by the function `plotPEarcs.tri`

, which is the one-tri counterpart of the function `plotPEarcs`

.
It takes arguments `Xp,tri,r,M=c(1,1,1)`

(as in `NumArcsPEtri`

) and other options for the plot function.
See the help page for the function using `? plotPEarcs.tri`

.

Plot of the arcs of the above PE-PCD, together with the vertex regions
(with the option `vert.reg = TRUE`

)
and vertex names added to the figure.

`plotPEarcs.tri(Xp,Tr,r,M,xlab="",ylab="",vert.reg = TRUE)`

```
#add vertex labels and text to the figure (with vertex regions)
ifelse(isTRUE(all.equal(M,circ.cent.tri(Tr))),
<-rbind((B+C)/2,(A+C)/2,(A+B)/2); cent.name="CC"},{Ds<-cent2edges.tri(Tr,M); cent.name="M"})
{Ds
<-rbind(Tr,M,Ds)
txt<-txt[,1]+c(-.02,.02,.02,.02,.04,-0.03,-.01)
xc<-txt[,2]+c(.02,.02,.02,.05,.02,.04,-.06)
yc<-c("A","B","C",cent.name,"D1","D2","D3")
txt.strtext(xc,yc,txt.str)
```

Plots of the PE proximity regions can be obtained by the function `plotPEregs.tri`

.
It takes arguments `Xp,tri,r,M=c(1,1,1)`

(as in `NumArcsPEtri`

) and other options for the plot function.
See the help page for the function using `? plotPEregs.tri`

.

```
<-c(1.6,1.2) #try also M<-c(1.6620051,0.8136604) or M="CC"
MplotPEregs.tri(Xp,Tr,r,M,vert.reg = T,xlab="",ylab="")
```

The function `ArcsPEtri`

is an object of class “`PCDs`

”.
It takes arguments `Xp,tri,r,M=c(1,1,1)`

(as in `NumArcsPEtri`

).
The output list is as in the `ArcsAStri`

except the parameters
of the digraph (center for PE-PCD and the expansion parameter).
The `plot`

function returns the same plot as in `plotPEarcs.tri`

,
hence we comment it out below.

```
<-ArcsPEtri(Xp,Tr,r,M) #or try with the default center Arcs<-ArcsPEtri(Xp,Tr,r); M= (Arcs$param)$cent
Arcs
Arcs#> Call:
#> ArcsPEtri(Xp = Xp, tri = Tr, r = r, M = M)
#>
#> Type:
#> [1] "Proportional Edge Proximity Catch Digraph (PE-PCD) for 2D Points in the Triangle with Expansion Parameter r = 1.5 and Center M = (1.6,1.2)"
summary(Arcs)
#> Call:
#> ArcsPEtri(Xp = Xp, tri = Tr, r = r, M = M)
#>
#> Type of the digraph:
#> [1] "Proportional Edge Proximity Catch Digraph (PE-PCD) for 2D Points in the Triangle with Expansion Parameter r = 1.5 and Center M = (1.6,1.2)"
#>
#> Vertices of the digraph = Xp
#> Partition points of the region = Tr
#>
#> Selected tail (or source) points of the arcs in the digraph
#> (first 6 or fewer are printed)
#> [,1] [,2]
#> [1,] 1.265509 0.7442478
#> [2,] 1.380035 1.5548904
#> [3,] 1.380035 1.5548904
#> [4,] 1.380035 1.5548904
#> [5,] 1.380035 1.5548904
#> [6,] 1.267221 0.7722282
#>
#> Selected head (or end) points of the arcs in the digraph
#> (first 6 or fewer are printed)
#> [,1] [,2]
#> [1,] 1.267221 0.7722282
#> [2,] 1.265509 0.7442478
#> [3,] 1.687023 0.7682074
#> [4,] 1.267221 0.7722282
#> [5,] 1.482080 1.1991317
#> [6,] 1.265509 0.7442478
#>
#> Parameters of the digraph
#> $center
#> [1] 1.6 1.2
#>
#> $`expansion parameter`
#> [1] 1.5
#>
#> Various quantities of the digraph
#> number of vertices number of partition points
#> 5.0 3.0
#> number of triangles number of arcs
#> 1.0 10.0
#> arc density
#> 0.5
plot(Arcs)
```

To see the code and the plot for the arcs using the `plot.PCDs`

function,
with vertex names and annotation added to the plot,
type `? ArcsPEtri`

.

We use the same triangle \(T\) and generated data as Section 2.2.

`<-1.5 tau`

And choose the expansion parameter \(\tau=\) 1.5 to illustrate central similarity proximity regions and the associated PCDs.

The function `NCStri`

is used for the construction of CS proximity regions taking the arguments
`p,tri,t,M=c(1,1,1),re=NULL`

where

`p,tri,M=c(1,1,1)`

are as in the function`NPEtri`

, and`re`

the index of the edge regions that the point`p`

resides in with default`re=NULL`

and`t`

is the expansion parameter (must be \(> 0\)).

`NCStri`

returns the CS proximity region (i.e., the vertices of the triangular proximity region).

```
<-c(1.8,.5)
PNCStri(P,Tr,tau,M)
#> [,1] [,2]
#> [1,] 1.74375 0.9500
#> [2,] 1.51250 0.4875
#> [3,] 1.97500 0.0250
```

Indicator for the presence of an arc from a (data or \(\mathcal{X}\)) point to another for CS-PCDs is the function `IndNCStri`

.
One can use it for points in the data set or for arbitrary points (as if they were in the data set).
It takes the arguments, `p1,p2,tri,t,M,re=NULL`

where `p1,p2,tri,M`

are as in `IndNPEtri`

and `t,re=NULL`

are as in `NCStri`

.
This function returns \(I(p2 \in N_{CS}(p1))\), that is, returns 1 if `p2`

is in \(N_{CS}(p1)\), 0 otherwise.

```
<-as.numeric(runif.tri(1,Tr)$g)
P1<-as.numeric(runif.tri(1,Tr)$g)
P2IndNCStri(P1,P2,Tr,tau,M)
#> [1] 1
IndNCStri(Xp[1,],Xp[2,],Tr,tau,M)
#> [1] 0
```

Number of arcs of the CS-PCD can be computed by the function `NumArcsCStri`

.
The output is as in `NumArcsPEtri`

.

Number of arcs of the CS-PCD can be computed by the function `NumArcsCStri`

,
which takes arguments `Xp,tri,t,M=c(1,1,1)`

where `Xp`

is the data set, and the others are as above.
The output is as in `NumArcsPEtri`

.

```
NumArcsCStri(Xp,Tr,t=.5,M)
#> $num.arcs
#> [1] 0
#>
#> $num.in.tri
#> [1] 5
#>
#> $ind.in.tri
#> [1] 1 2 3 4 5
```

The arc density of the CS-PCD can be computed by the function `CSarcdens.tri`

.
It takes the arguments `Xp,tri,t,M=c(1,1,1),tri.cor=FALSE`

where `Xp`

is the data set (or \(\mathcal{X}\) points)
`tri,t,M=c(1,1,1),tri.cor=FALSE`

are as above.
Arc density can be adjusted (or corrected) for the points outside the triangle by using the option `tri.cor=TRUE`

as in the `NumArcsPEtri`

.

```
CSarcdens.tri(Xp,Tr,tau,M)
#> $arc.dens
#> [1] 0.35
```

The incidence matrix of the CS-PCD for the one triangle case can be found by `IncMatCStri`

, using the `IncMatCStri(Xp,Tr,tau,M)`

command.
It takes the same arguments as the function `NumArcsCStri`

.

Plot of the arcs in the digraph CS-PCD, which is based on the \(M\)-edge regions with \(M=\)(1.6,1.2).
can be obtained by the function `plotCSarcs.tri`

, which is the one-tri counterpart of the function `plotCSarcs`

.
It takes arguments `Xp,tri,t,M=c(1,1,1)`

(as in `NumArcsPEtri`

) and other options for the plot function.
See the help page for the function using `? plotCSarcs.tri`

.

Plot of the arcs of the above CS-PCD, together with the edge regions
(with the option `edge.reg = TRUE`

)
and vertex names added to the figure.

```
<-1.5 #try also t<-2
tplotCSarcs.tri(Xp,Tr,t,M,xlab="",ylab="",edge.reg = TRUE)
```

```
#add vertex labels and text to the figure (with edge regions)
<-rbind(Tr,M)
txt<-txt[,1]+c(-.02,.02,.02,.03)
xc<-txt[,2]+c(.02,.02,.02,.03)
yc<-c("A","B","C","M")
txt.strtext(xc,yc,txt.str)
```

Plot of the CS proximity regions can be obtained by the function `plotCSregs.tri`

,
the first is for all points, the second is for two \(\mathcal{X}\) points only (for better visualization).
It takes arguments `Xp,tri,t,M=c(1,1,1)`

(as in `NumArcsCStri`

) and other options for the plot function.
See the help page for the function using `? plotCSregs.tri`

.

`plotCSregs.tri(Xp,Tr,t,M,edge.reg=T,xlab="",ylab="")`

The function `ArcsCStri`

is an object of class “`PCDs`

”.
It takes arguments `Xp,tri,t,M=c(1,1,1)`

(as in `NumArcsCStri`

).
The output list is as in the `ArcsPEtri`

.
The `plot`

function returns the same plot as in `plotCSarcs.tri`

,
hence we comment it out below.

```
<-ArcsCStri(Xp,Tr,t,M)
Arcs
Arcs#> Call:
#> ArcsCStri(Xp = Xp, tri = Tr, t = t, M = M)
#>
#> Type:
#> [1] "Central Similarity Proximity Catch Digraph (CS-PCD) for 2D Points in the Triangle with Expansion Parameter t = 1.5 and Center M = (1.6,1.2)"
summary(Arcs)
#> Call:
#> ArcsCStri(Xp = Xp, tri = Tr, t = t, M = M)
#>
#> Type of the digraph:
#> [1] "Central Similarity Proximity Catch Digraph (CS-PCD) for 2D Points in the Triangle with Expansion Parameter t = 1.5 and Center M = (1.6,1.2)"
#>
#> Vertices of the digraph = Xp
#> Partition points of the region = Tr
#>
#> Selected tail (or source) points of the arcs in the digraph
#> (first 6 or fewer are printed)
#> [,1] [,2]
#> [1,] 1.687023 0.7682074
#> [2,] 1.687023 0.7682074
#> [3,] 1.687023 0.7682074
#> [4,] 1.267221 0.7722282
#> [5,] 1.482080 1.1991317
#> [6,] 1.482080 1.1991317
#>
#> Selected head (or end) points of the arcs in the digraph
#> (first 6 or fewer are printed)
#> [,1] [,2]
#> [1,] 1.265509 0.7442478
#> [2,] 1.267221 0.7722282
#> [3,] 1.482080 1.1991317
#> [4,] 1.265509 0.7442478
#> [5,] 1.265509 0.7442478
#> [6,] 1.687023 0.7682074
#>
#> Parameters of the digraph
#> $center
#> [1] 1.6 1.2
#>
#> $`expansion parameter`
#> [1] 1.5
#>
#> Various quantities of the digraph
#> number of vertices number of partition points
#> 5.0 3.0
#> number of triangles number of arcs
#> 1.0 8.0
#> arc density
#> 0.4
plot(Arcs)
```

To see the code and the plot for the arcs using the `plot.PCDs`

function,
with vertex names and annotation added to the plot,
type `? ArcsCStri`

.

We first define the standard equilateral triangle \(T_e=T(A,B,C)\) with vertices \(A=(0,0)\), \(B=(1,0)\), and \(C=(1/2,\sqrt{3}/2)\).

```
<-c(0,0); B<-c(1,0); C<-c(1/2,sqrt(3)/2);
A<-rbind(A,B,C);
Te<-5 #try also n<-10, 50, or 100
nset.seed(1)
<-runif.std.tri(n)$gen.points
Xp<-c(.6,.2) #try also M<-c(1,1,1) M
```

Then we generate data or \(\mathcal{X}\) points of size \(n=\) 5 using the function `runif.std.tri`

in the `pcds`

package,
and choose the arbitrary center \(M=(\) 1.6,1.2 \()\) in the interior of \(T_e\).
Notice that the argument `tri`

is redundant for the functions specific to the standard equilateral triangle,
hence they are omitted for the functions which have counterparts in Section 2.2.

Plot of the triangle \(T_e\) and the \(\mathcal{X}\) points in it can be obtained by the below code,
and we also add the vertex names and
annotation using the `text`

function from base `R`

.
We use `asp=1`

in the below plot so that the standard equilateral triangle is plotted with equal length edges.

```
<-range(Te[,1])
Xlim<-range(Te[,2])
Ylimplot(Te,asp=1,pch=".",xlab="",ylab="",xlim=Xlim,ylim=Ylim,main="Points in Standard Equilateral Triangle")
polygon(Te)
points(Xp)
#add the vertex names and annotation
<-rbind(Te)
txt<-txt[,1]+c(-.02,.02,.02)
xc<-txt[,2]+c(.01,.01,.01)
yc<-c("A","B","C")
txt.strtext(xc,yc,txt.str)
```

Alternatively, we can use the `plotDeltri`

function in `pcds`

to obtain the same plot by executing `plotDeltri(Xp,Te,xlab="x",ylab="y",main="Points in Standard Equilateral Triangle")`

command.

Indicator for the presence of an arc from a (data or \(\mathcal{X}\)) point to another for PE-PCDs is the function `IndNPETe`

.
One can use it for points in the data set or for arbitrary points (as if they were in the data set).
It takes the arguments, `p1,p2,r,M=c(1,1,1),rv=NULL`

as in `IndNPEtri`

.

```
<-as.numeric(runif.tri(1,Te)$g)
P1<-as.numeric(runif.tri(1,Te)$g)
P2=2
rIndNPETe(P1,P2,r,M)
#> [1] 1
IndNPETe(Xp[1,],Xp[2,],r,M)
#> [1] 1
```

Number of arcs of the PE-PCD can be computed by the function `NumArcsPETe`

which
takes the same arguments as the function `NumArcsPEtri`

.
The output is as in `NumArcsPEtri`

.

```
NumArcsPETe(Xp,r=1.25,M)
#> $num.arcs
#> [1] 24
#>
#> $num.in.tri
#> [1] 10
#>
#> $ind.in.tri
#> [1] 1 2 3 4 5 6 7 8 9 10
```

The incidence matrix of the PE-PCD for the one triangle case can be found by `IncMatPETe`

,
using the `IncMatPETe(Xp,r,M)`

command.

We use the same setting for the data points and the center as in Section 2.4.
Notice that the argument `tri`

is redundant for the functions specific to the standard equilateral triangle,
hence they are omitted for the functions which have counterparts in Section 2.3.

Indicator for the presence of an arc from a (data or \(\mathcal{X}\)) point to another for CS-PCDs is the function `IndNPETe`

.

```
<-as.numeric(runif.tri(1,Te)$g)
P1<-as.numeric(runif.tri(1,Te)$g)
P2=1
tauIndNCSTe(P1,P1,tau,M)
IndNCSTe(P1,P2,tau,M)
IndNCSTe(Xp[1,],Xp[2,],tau,M)
```

Number of arcs of the CS-PCD can be computed by the function `NumArcsCSTe`

whose arguments and output are as in `NumArcsCStri`

.

```
set.seed(123)
<-as.numeric(runif.std.tri(1)$g) #try also M<-c(.6,.2)
MNumArcsCStri(Xp,Te,t=1.5,M)
#> $num.arcs
#> [1] 25
#>
#> $num.in.tri
#> [1] 10
#>
#> $ind.in.tri
#> [1] 1 2 3 4 5 6 7 8 9 10
```

The incidence matrix of the CS-PCD for the one triangle case can be found by `IncMatCSTe`

,
using e.g. the `IncMatCSTe(Xp,t=1.5,M)`

command.

The PCDs are constructed using proximity regions, and proximity region of an \(\mathcal{X}\) point depends on its location relative to the \(\mathcal{Y}\) points. In particular, AS- and PE-PCDs depend on the vertex regions and CS-PCDs depend on edge regions. We will illustrate the vertex and edge regions in this section. These regions partition the Delaunay cell (e.g., Delaunay triangle in \(\mathbb R^2\)) based on a center or central point in the triangle.

We first check whether a point is inside a triangle or not which can be done using the function `in.triangle`

,
which takes arguments `p,tri,boundary=FALSE`

where

`p`

, a 2D point to be checked whether it is inside the triangle or not,`tri`

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

, a logical parameter (default=`TRUE`

) to include boundary or not, so if it is`TRUE`

, the function checks if the point,`p`

, lies in the closure of the triangle (i.e., interior and boundary combined); else, it checks if`p`

lies in the interior of the triangle.

The function gives `TRUE`

if the point is inside the triangle, and `FALSE`

otherwise.
It also returns the barycentric coordinates of the point with respect to the triangle.

```
<-c(1,1); B<-c(2,0); C<-c(1.5,2); p<-c(1.4,1.2)
A<-rbind(A,B,C)
Trin.triangle(p,Tr)
#> $in.tri
#> [1] TRUE
#>
#> $barycentric
#> [1] 0.4 0.2 0.4
```

We now illustrate *circumcenter* of a triangle.
The function `circ.cent.tri`

takes `tri`

as its sole argument for a triangle and
returns the circumcenter of the triangle as its output.

```
<-c(1,1); B<-c(2,0); C<-c(1.5,2);
A<-rbind(A,B,C); #the vertices of the triangle Tr
Tr<-circ.cent.tri(Tr)) #the circumcenter
(CC#> [1] 2.083333 1.083333
```

We plot the circumcenter of an obtuse triangle below (so circumcenter is outside of the triangle)
using the below code,
see also the help page with `? circ.cent.tri`

for the code to generate this figure.
Notice that in the code we used `asp=1`

so that lines joining CC to the edges of the triangle
appear perpendicular to the edges.

```
<-(B+C)/2; D2<-(A+C)/2; D3<-(A+B)/2; #midpoints of the edges
D1<-rbind(D1,D2,D3)
Ds
<-range(Tr[,1],CC[1])
Xlim<-range(Tr[,2],CC[2])
Ylim<-Xlim[2]-Xlim[1]
xd<-Ylim[2]-Ylim[1]
yd
par(pty="s")
plot(A,asp=1,pch=".",xlab="",ylab="",main="Circumcenter of a triangle",axes=TRUE,xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05))
polygon(Tr)
points(rbind(CC))
<-matrix(rep(CC,3),ncol=2,byrow=TRUE); R<-Ds
Lsegments(L[,1], L[,2], R[,1], R[,2], lty=2)
<-rbind(Tr,CC,Ds)
txt<-txt[,1]+c(-.08,.08,.08,.12,-.09,-.1,-.09)
xc<-txt[,2]+c(.02,-.02,.03,-.06,.02,.06,-.04)
yc<-c("A","B","C","CC","D1","D2","D3")
txt.strtext(xc,yc,txt.str)
```

The function `circ.cent.bas.tri`

is a special case of `circ.cent.tri`

and takes the argument `c1,c2`

and returns the circumcenter of the standard basic triangle.

The function `cent.nondegPE`

takes arguments `tri,r`

which are the triangle and the expansion parameter for the PE proximity regions, respectively.
It returns the three centers for non-degenerate asymptotic distribution of
domination number of PE-PCDs for \(r \in (1,1.5)\) and the center of mass for \(r=1.5\).
This center is not defined for \(r > 1.5\), as the asymptotic distribution is degenerate in this case.

```
<-c(1,1); B<-c(2,0); C<-c(1.5,2);
A<-rbind(A,B,C);
Tr<-1.35
r<-cent.nondegPE(Tr,r))
(Ms#> [,1] [,2]
#> M1 1.388889 1.0000000
#> M2 1.611111 0.7777778
#> M3 1.500000 1.2222222
```

We plot the non-degeneracy centers for the triangle `Tr`

using the below code,
type also `? cent.nondegPE`

for the code to generate this figure.

```
<-range(Tr[,1])
Xlim<-range(Tr[,2])
Ylim<-Xlim[2]-Xlim[1]
xd<-Ylim[2]-Ylim[1]
yd
plot(Tr,pch=".",xlab="",ylab="",main="Centers of nondegeneracy\n for the PE-PCD in a triangle",axes=TRUE,xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05))
polygon(Tr)
points(Ms,pch=".",col=1)
polygon(Ms,lty=2)
<-Tr[,1]+c(-.02,.02,.02)
xc<-Tr[,2]+c(.02,.02,.03)
yc<-c("A","B","C")
txt.strtext(xc,yc,txt.str)
<-Ms[,1]+c(-.04,.04,.03)
xc<-Ms[,2]+c(.02,.02,.05)
yc<-c(expression(M[1]),"M2","M3")
txt.strtext(xc,yc,txt.str)
```

The function `cent2edges.tri`

returns the projections of a point (e.g., a center) \(M\) inside a triangle to its edges,
i.e., it returns the *intersection point* where the line joining a vertex to \(M\) crosses the opposite edge.
The line segments between \(M\) the intersection points define the \(M\)-vertex regions.

```
<-c(1,1); B<-c(2,0); C<-c(1.5,2);
A<-rbind(A,B,C);
Tr<-c(1.6,1.0) #try also M<-as.numeric(runif.tri(1,Tr)$g)
M<-cent2edges.tri(Tr,M)) #try also cent2edges.tri(Tr,M=c(1,1))
(Ds#> [,1] [,2]
#> [1,] 1.750000 1.0000000
#> [2,] 1.333333 1.6666667
#> [3,] 1.666667 0.3333333
```

We plot the projections of center \(M\) to the edges of the triangle `Tr`

using the below code,
type also `? cent2edges.tri`

for the code to generate this figure.

```
<-range(Tr[,1])
Xlim<-range(Tr[,2])
Ylim<-Xlim[2]-Xlim[1]
xd<-Ylim[2]-Ylim[1]
yd
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="Projection of Center M on the edges of a triangle",axes=TRUE,
xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05))
polygon(Tr)
<-rbind(M,M,M); R<-Ds
Lsegments(L[,1], L[,2], R[,1], R[,2], lty=2)
<-Tr[,1]
xc<-Tr[,2]
yc<-c("rv=1","rv=2","rv=3")
txt.strtext(xc,yc,txt.str)
<-rbind(M,Ds)
txt<-txt[,1]+c(-.02,.04,-.04,-.02)
xc<-txt[,2]+c(-.02,.04,.04,-.06)
yc<-c("M","D1","D2","D3")
txt.strtext(xc,yc,txt.str)
```

The function `cent2edges.bas.tri`

is a special case of `cent2edges.tri`

taking arguments `c1,c2`

instead of `tri`

and returning projections of \(M\) to the edges in the standard basic triangle.

The function `cent.ndPE2edges`

takes arguments

`tri`

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

, a positive real number which serves as the expansion parameter in PE proximity region, must be in \((1,1.5]\) for this function.`cent`

, an index of the center (as \(1,2,3\) corresponding to \(M_1,\,M_2,\,M_3\)) which gives nondegenerate asymptotic distribution of the domination number of PE-PCD for uniform data in`tri`

for expansion parameter`r`

in \((1,1.5]\); default`cent=1`

.

This function returns the projections of nondegeneracy centers (i.e. centers for non-degenerate asymptotic distribution of domination number of PE-PCDs) to its edges, i.e., it returns the intersection point where the line joining a vertex to a non-degeneracy center \(M_i\) crosses the opposite edge. The line segments between \(M_i\) the intersection points will provide the \(M_i\)-vertex regions.

```
<-c(1,1); B<-c(2,0); C<-c(1.5,2);
A<-rbind(A,B,C);
Tr<-1.35
rcent.ndPE2edges(Tr,r,cent=2)
#> [,1] [,2]
#> [1,] 1.825 0.70
#> [2,] 1.250 1.50
#> [3,] 1.650 0.35
```

We plot the projections of the non-degeneracy center \(M_1\) to the edges of a triangle using the below code,
type also `? cent.ndPE2edges`

for the code to generate this figure.

```
<-cent.nondegPE(Tr,r)
Ms=Ms[1,]
M1
<-cent.ndPE2edges(Tr,r,cent=1)
Ds
<-range(Tr[,1])
Xlim<-range(Tr[,2])
Ylim<-Xlim[2]-Xlim[1]
xd<-Ylim[2]-Ylim[1]
yd
plot(Tr,pch=".",xlab="",ylab="",main="Projections from a non-degeneracy center\n to the edges of the triangle",
axes=TRUE,xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05))
polygon(Tr)
points(Ms,pch=".",col=1)
polygon(Ms,lty=2)
<-Tr[,1]+c(-.02,.03,.02)
xc<-Tr[,2]+c(-.02,.04,.04)
yc<-c("A","B","C")
txt.strtext(xc,yc,txt.str)
<-Ms
txt<-txt[,1]+c(-.02,.04,-.04)
xc<-txt[,2]+c(-.02,.04,.04)
yc<-c("M1","M2","M3")
txt.strtext(xc,yc,txt.str)
points(Ds,pch=4,col=2)
<-rbind(M1,M1,M1); R<-Ds
Lsegments(L[,1], L[,2], R[,1], R[,2], lty=2,lwd=2,col=4)
<-Ds
txt<-txt[,1]+c(-.02,.04,-.04)
xc<-txt[,2]+c(-.02,.04,.04)
yc<-c("D1","D2","D3")
txt.strtext(xc,yc,txt.str)
```

The function `in.triangle`

takes arguments

`p`

, a 2D point to be checked whether it is inside the triangle or not,`tri`

, a \(3 \times 2\) matrix with each row representing a vertex of the triangle,`boundary`

, a logical parameter (default=`FALSE`

) to include boundary or not, so if it is`TRUE`

, the function checks if the point,`p`

, lies in the closure of the triangle (i.e., interior and boundary combined) else it checks if`p`

lies in the interior of the triangle.

This function can be used to check whether a point `p`

is inside a triangle `tri`

or not.

On the other hand `in.tri.all`

takes arguments `Xp,tri,boundary`

where
`Xp`

is a 2D data set and `tri,boundary`

are as in the function `in.triangle`

.
This function checks whether all of the points in a data set are inside the triangle or not.

We check `in.tri.all`

with \(n=5\) data points generated uniformly in the unit square and in the triangle.

```
<-c(1,1); B<-c(2,0); C<-c(1.5,2);
A<-c(1.4,1.2)
p<-rbind(A,B,C)
Trin.triangle(p,Tr)
#> $in.tri
#> [1] TRUE
#>
#> $barycentric
#> [1] 0.4 0.2 0.4
#data set and checking all points in it are inside the triangle or not
<-5
n<-cbind(runif(n),runif(n))
Xp1in.tri.all(Xp1,Tr)
#> [1] FALSE
```

The function `is.std.eq.tri`

takes the argument `tri`

(a \(3 \times 2\) matrix for a triangle) and
can be used for checking the triangle `tri`

is standard equilateral triangle or not,
regardless of the order of the vertices.

```
<-c(0,0); B<-c(1,0); C<-c(1/2,sqrt(3)/2);
A<-rbind(A,B,C) #try adding +10^(-16) to each vertex
Teis.std.eq.tri(Te)
#> [1] TRUE
<-c(1,1); B<-c(2,0); C<-c(1.5,2);
A<-rbind(A,B,C);
Tris.std.eq.tri(Tr)
#> [1] FALSE
```

The function `as.bas.tri`

takes the arguments `tri,scaled`

where

-`tri`

is as in `is.std.eq.tri`

and
-`scaled`

is a logical argument for scaling the resulting triangle. If `scaled=TRUE`

, then the resulting triangle is
scaled to be a regular basic triangle, i.e., longest edge having unit length,
else the new triangle \(T(A,B,C)\) is nonscaled. The default is `scaled=FALSE`

.

It converts any triangle to a basic triangle (up to translation and rotation),
so that the output triangle is \(T(A',B',C')\) so that edges in decreasing length are \(A'B'\), \(B'C'\), and \(A'C'\).
The option `scaled`

scales the output triangle when `scaled=TRUE`

so that longest edge \(A'B'\) has unit length
(default is `scaled=FALSE`

).
Most of the times,
the resulting triangle will still need to be translated and/or rotated to be in the standard basic triangle form.

```
<-.4; c2<-.6
c1<-c(0,0); B<-c(1,0); C<-c(c1,c2);
Aas.bas.tri(rbind(B,C,A))
#> $tri
#> [,1] [,2]
#> A 0.0 0.0
#> B 1.0 0.0
#> C 0.4 0.6
#>
#> $desc
#> [1] "Edges (in decreasing length are) AB, BC, and AC"
#>
#> $orig.order
#> [1] 3 1 2
<-c(1,1); y<-c(2,0); z<-c(1.5,2);
xas.bas.tri(rbind(x,y,z))
#> $tri
#> [,1] [,2]
#> A 1.5 2
#> B 2.0 0
#> C 1.0 1
#>
#> $desc
#> [1] "Edges (in decreasing length are) AB, BC, and AC"
#>
#> $orig.order
#> [1] 3 2 1
as.bas.tri(rbind(x,y,z),scaled = TRUE)
#> $tri
#> [,1] [,2]
#> A 0.7276069 0.9701425
#> B 0.9701425 0.0000000
#> C 0.4850713 0.4850713
#>
#> $desc
#> [1] "Edges (in decreasing length are) AB, BC, and AC"
#>
#> $orig.order
#> [1] 3 2 1
```

The function `tri2std.bas.tri`

converts a triangle to the standard basic triangle form,
and its output only returns \(c_1,c_2\) in `$Cvec`

and
also the original order of the vertices in the input triangle
by `$orig.order`

.

```
<-.4; c2<-.6
c1<-c(0,0); B<-c(1,0); C<-c(c1,c2);
Atri2std.bas.tri(rbind(B,C,A))
#> $Cvec
#> [1] 0.4 0.6
#>
#> $orig.order
#> [1] 3 1 2
<-c(1,1); B<-c(2,0); C<-c(1.5,2);
Atri2std.bas.tri(rbind(A,B,C))
#> $Cvec
#> [1] 0.4117647 0.3529412
#>
#> $orig.order
#> [1] 3 2 1
```

Barycentric coordinates are very useful in defining and analyzing the triangular (and simplicial) proximity regions.
So, we provide functions to convert barycentric coordinates to Cartesian coordinates (`bary2cart`

) and vice versa (`cart2bary`

).
Both functions take the arguments `P,tri`

where `P`

is th point to change the coordinates for and `tri`

is the reference triangle
(as a \(3\times2\) matrix).
As the names suggest,
the function `cart2bary`

converts the point `P`

in Cartesian coordinates
to barycentric coordinates with respect to the triangle `tri`

,
and `bary2cart`

converts the point `P`

in barycentric coordinates with respect to the triangle `tri`

to Cartesian coordinates.

```
<-c(1,1); B<-c(2,0); C<-c(1.5,2);
A<-rbind(A,B,C);
Trcart2bary(c(1.4,1.2),Tr)
#> [1] 0.4 0.2 0.4
bary2cart(c(1.4,1.2,1),Tr)
#> [1] 1.4722222 0.9444444
<-(A+B+C)/3; CM
CM#> [1] 1.5 1.0
cart2bary(CM,Tr)
#> [1] 0.3333333 0.3333333 0.3333333
bary2cart(c(1,1,1),Tr)
#> [1] 1.5 1.0
```

The function `ind.del.tri`

takes the arguments

`p`

, a 2D point; the index of the Delaunay triangle in which`p`

resides is to be determined. It is an argument for`ind.del.tri`

.`Yp`

, a set of 2D points from which Delaunay triangulation is constructed,`DTmesh`

, Delaunay triangles based on`Yp`

, default is`NULL`

, which is computed via`interp::tri.mesh`

function in`interp`

package.`interp::triangles`

function returns a triangulation data structure from the triangulation object created by`tri.mesh`

.

This function returns the index of the Delaunay triangle in which the given point resides.

Similarly, the function `indices.del.tri`

takes the arguments `Xp,Yp,DTmesh`

where
`Xp`

is the set of data points for which the indices of the Delaunay
triangles they reside is to be determined and `Yp,DTmesh`

are as in `ind.del.tri`

.
This function returns the indices of triangles for all the points in a data set as a vector.

```
<-10 #number of X points (target)
nx<-5 #number of Y points (nontarget) ny
```

We generate \(n_x=\) 10 \(\mathcal{X}\) points uniformly in the convex hull of \(n_y=\) 5 \(\mathcal{Y}\) points
using the function `runifMT`

in `pcds`

package.

```
set.seed(1)
<-cbind(runif(ny),runif(ny))
Yp
<-runifMT(nx,Yp)$g #data under CSR in the convex hull of Ypoints
Xp#try also Xp<-cbind(runif(nx),runif(nx))
ind.del.tri(Xp[10,],Yp)
#> [1] 2
#or use
<-interp::tri.mesh(Yp[,1],Yp[,2],duplicate="remove") #Delaunay triangulation
DTYind.del.tri(Xp[10,],Yp,DTY)
#> [1] 2
<-indices.del.tri(Xp,Yp,DTY)) #indices of the Delaunay triangles
(tr.ind#> [1] 3 3 1 4 3 2 3 3 2 2
```

We provide the scatterplot of \(\mathcal{X}\) points (labeled according to the Delaunay triangle they reside in),
and the Delaunay triangulation
of \(n_y=\) 5 \(\mathcal{Y}\) points using the below code. Type also `? indices.del.tri`

.

```
<-range(Yp[,1],Xp[,1])
Xlim<-range(Yp[,2],Xp[,2])
Ylim<-Xlim[2]-Xlim[1]
xd<-Ylim[2]-Ylim[1]
yd
in the convex hull of Y points together with the Delaunay triangulation
plot of the data #par(pty="s")
plot(Xp,main="X Points in Delaunay Triangles for Y Points", xlab=" ", ylab=" ",
xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05),pch=".")
::plot.triSht(DTY, add=TRUE, do.points = TRUE,pch=16,col="blue")
interptext(Xp,labels = factor(tr.ind) )
```