maxDistanceFromPath.R (799B)
1 #' Find the maximum distance of a flight trajectory from a flight path. 2 #' 3 #' @param trajectory A matrix or SpatialPoints object indicating the trajectory 4 #' of an aircraft. 5 #' @param path A matrix or SpatialPoints object indicating the ordered waypoints 6 #' a pre-defined flight path. 7 #' @return A named vector indicating the horizontal and vertical distance from 8 #' the fligh path at which the aircraft reached the maximum slant (euclidean) 9 #' distance. 10 #' 11 #' @export 12 maxDistanceFromPath <- function(trajectory, path) { 13 distanceFromPathVals <- distanceFromPath(trajectory, path) 14 slantDistanceFromPath <- distanceFromPathVals$horizontal^2 + 15 distanceFromPathVals$vertical^2 16 farthestPoint <- which.max(slantDistanceFromPath) 17 return(unlist(distanceFromPathVals[farthestPoint, ])) 18 }