in.triangle: Check whether a point is inside a triangle

View source: R/AuxDelaunay.R

in.triangleR Documentation

Check whether a point is inside a triangle

Description

Checks if the point p lies in the triangle, tri, using the barycentric coordinates, generally denoted as (\alpha,\beta,\gamma).

If all (normalized or non-normalized) barycentric coordinates are positive then the point p is inside the triangle, if all are nonnegative with one or more are zero, then p falls in the boundary. If some of the barycentric coordinates are negative, then p falls outside the triangle.

boundary is a logical argument (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.

Usage

in.triangle(p, tri, boundary = TRUE)

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=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.

Value

A list with two elements

in.tri

A logical output, it is TRUE, if the point, p, is inside the triangle, tri, else it is FALSE.

barycentric

The barycentric coordinates (\alpha,\beta,\gamma) of the point p with respect to the triangle, tri.

Author(s)

Elvan Ceyhan

See Also

in.tri.all and on.convex.hull from the interp package for documentation for in.convex.hull

Examples

## Not run: 
A<-c(1,1); B<-c(2,0); C<-c(1.5,2); p<-c(1.4,1.2)
Tr<-rbind(A,B,C)
in.triangle(p,Tr)

p<-c(.4,-.2)
in.triangle(p,Tr)

#for the vertex A
in.triangle(A,Tr)
in.triangle(A,Tr,boundary = FALSE)

#for a point on the edge AB
D3<-(A+B)/2
in.triangle(D3,Tr)
in.triangle(D3,Tr,boundary = FALSE)

#for a NA entry point
p<-c(NA,.2)
in.triangle(p,Tr)

## End(Not run)


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