Learn R Programming

pcds (version 0.1.4)

dist.pt2set: Distance from a point to a set of finite cardinality

Description

Returns the Euclidean distance between a point x and set of points Y and the closest point in set Y to x. Distance between a point and a set is by definition the distance from the point to the closest point in the set. x should be of finite dimension and Y should be of finite cardinality and x and elements of Y must have the same dimension.

Usage

dist.pt2set(x, Y)

Value

A list with the elements

distance

Distance from point x to set Y

ind.cl.point

Index of the closest point in set Y to the point x

closest.point

The closest point in set Y to the point x

Arguments

x

A vector (i.e., a point in \(R^d\)).

Y

A set of \(d\)-dimensional points.

Author

Elvan Ceyhan

See Also

dp2l and dp2pl

Examples

Run this code
A<-c(0,0); B<-c(1,0); C<-c(1/2,sqrt(3)/2);
Te<-rbind(A,B,C);
dist.pt2set(c(1,2),Te)

X2<-cbind(runif(10),runif(10))
dist.pt2set(c(1,2),X2)

dist.pt2set(C,C)
dist.pt2set(B,C)

x<-runif(1)
y<-as.matrix(runif(10))
dist.pt2set(x,y)  #this works, because x is a 1D point, and y is treated as a set of 10 1D points
#but will give an error message if y<-runif(10) is used above

dat.fr<-data.frame(b=B,c=C)
dist.pt2set(A,dat.fr)

Run the code above in your browser using DataLab