nearestTarget: Finds the nearest targets to a set of points within a...

View source: R/nearestTarget.R

nearestTargetR Documentation

Finds the nearest targets to a set of points within a specified radius.

Description

Calculates the distances between a set of points and target locations. It identifies the nearest target for each point and checks if the distance is within a specified radius. If a target is found within the radius, its index and distance are returned; otherwise, -1 is returned for both.

Usage

nearestTarget(points, targets, r)

Arguments

points

A matrix or data frame containing the coordinates of the points with rows representing points.

targets

A matrix or data frame containing the coordinates of the target locations with rows representing targets.

r

A numeric value specifying the radius within which to consider targets.

Value

A data frame with two columns:

nt

Index of the nearest target for each point. If no target is found within the radius, this will be -1.

d

Distance to the nearest target. If no target is found within the radius, this will be -1.

Examples

# Define a set of points and targets
points <- matrix(c(1, 2, 3, 4), ncol = 2)
targets <- matrix(c(2, 3, 5, 6), ncol = 2)
radius <- 2

# Find the nearest targets
nearest_results <- nearestTarget(points, targets, radius)

# Print the results
print(nearest_results)

BioTrajectory documentation built on June 8, 2025, 11:54 a.m.