flightconflicts

Tools to analyze conflicts between aircraft.
git clone https://git.eamoncaddigan.net/flightconflicts.git
Log | Files | Refs | README | LICENSE

identifyViolations.R (2052B)


      1 #' Determine whether an NMAC (near mid air collision) has occurred at each time 
      2 #' point.
      3 #' 
      4 #' @param trajectory1 A \code{flighttrajectory} object corresponding to the
      5 #'   first aircraft.
      6 #' @param trajectory2 A \code{flighttrajectory} object corresponding to the
      7 #'   second aircraft.
      8 #' @return The logical vector indicating whether NMAC criteria are met at each 
      9 #'   time point.
     10 #'   
     11 #' @details NMAC is a cylinder +/- 100 ft above and below the ownship with a 
     12 #'   radius of 500 ft.
     13 #'   
     14 #' @export
     15 identifyNMAC <- function(trajectory1, trajectory2) {
     16   if (!flightpathr::is.flighttrajectory(trajectory1) || 
     17       !flightpathr::is.flighttrajectory(trajectory2)) {
     18     stop("Both arguments must be instances of flighttrajectory")
     19   }
     20   if (!isTRUE(all.equal(trajectory1$timestamp, trajectory2$timestamp))) {
     21     stop("Trajectories must have matching time stamps")
     22   }
     23 
     24   horizontalDistanceFt <- geosphere::distHaversine(cbind(trajectory1$longitude,
     25                                                          trajectory1$latitude),
     26                                                    cbind(trajectory2$longitude,
     27                                                          trajectory2$latitude),
     28                                                    r = 20925646)
     29   verticalDistanceFt <- abs(trajectory1$altitude - trajectory2$altitude)
     30 
     31   isNMAC <- (horizontalDistanceFt < 500) | (verticalDistanceFt < 100)
     32 
     33   return(isNMAC)
     34 }
     35 
     36 
     37 
     38 #' Determine whether loss of Well Clear (LoWC) has occurred at each time point.
     39 #' 
     40 #' @param trajectory1 A \code{flighttrajectory} object corresponding to the 
     41 #'   first aircraft.
     42 #' @param trajectory2 A \code{flighttrajectory} object corresponding to the 
     43 #'   second aircraft.
     44 #' @return The logical vector indicating whether Well Clear has been violated at
     45 #'   each time point.
     46 #'   
     47 #' @details This code relies on \code{\link{calculateSLoWC}}, see its
     48 #'   documentation for details.
     49 #'   
     50 #' @export
     51 identifyLoWC <- function(trajectory1, trajectory2) {
     52   return(calculateSLoWC(trajectory1, trajectory2) > 0)
     53 }