flightconflicts

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

commit 779b5fda418fa4b71c19afef9f1652af6acd4d6e
parent 17a7f66bbae83ae6eff7b652d08cf267d78f8172
Author: eamoncaddigan <eamon.caddigan@gmail.com>
Date:   Mon, 12 Sep 2016 14:23:48 -0400

Pulling out flat-Earth approximation code for flexibility/modularity.

Diffstat:
MR/calculateSLoWC.R | 15+++++++--------
AR/trajectoryToXYZ.R | 26++++++++++++++++++++++++++
Aman/trajectoryToXYZ.Rd | 21+++++++++++++++++++++
3 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/R/calculateSLoWC.R b/R/calculateSLoWC.R @@ -22,17 +22,16 @@ calculateSLoWC <- function(trajectory1, trajectory2) { lon0 <- mean(c(trajectory1$longitude, trajectory2$longitude)) lat0 <- mean(c(trajectory1$latitude, trajectory2$latitude)) + t1 <- trajectoryToXYZ(trajectory1, c(lon0, lat0)) + t2 <- trajectoryToXYZ(trajectory2, c(lon0, lat0)) + # Flat Earth approximation of aircraft position and velocity - ac1XYZ <- cbind(lonlatToXY(trajectory1$longitude, trajectory1$latitude, - lon0, lat0), - trajectory1$altitude) - ac2XYZ <- cbind(lonlatToXY(trajectory2$longitude, trajectory2$latitude, - lon0, lat0), - trajectory2$altitude) + ac1XYZ <- t1$position + ac2XYZ <- t2$position # Convert bearing/speed to velocity vector. - ac1Velocity <- bearingToXY(trajectory1$bearing, trajectory1$groundspeed) - ac2Velocity <- bearingToXY(trajectory2$bearing, trajectory2$groundspeed) + ac1Velocity <- t1$velocity + ac2Velocity <- t2$velocity # Distance between aircraft dXYZ <- ac2XYZ - ac1XYZ diff --git a/R/trajectoryToXYZ.R b/R/trajectoryToXYZ.R @@ -0,0 +1,26 @@ +#' Convert trajectories to Easting/Northing representation. +#' +#' @param trajectory A flighttrajectory object. +#' @param origin A length 2 numeric vector giving the origin lon/lat for the +#' conversion. +#' @return A flattrajectory object. +trajectoryToXYZ <- function(trajectory, origin) { + if (!is.flighttrajectory(trajectory)) { + stop("'trajectory' must be an instance of flighttrajectory") + } + if (!is.numeric(origin) || length(origin) != 2) { + stop("'origin' must be a numeric vector of length 2") + } + + trajectoryXY <- lonlatToXY(trajectory$longitude, trajectory$latitude, + origin[1], origin[2]) + + velocityXY <- bearingToXY(trajectory$bearing, trajectory$groundspeed) + + flattrajectory <- list(origin = origin, + position = cbind(trajectoryXY, trajectory$altitude), + velocity = velocityXY) + class(flattrajectory) <- "flattrajectory" + + return(flattrajectory) +} diff --git a/man/trajectoryToXYZ.Rd b/man/trajectoryToXYZ.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/trajectoryToXYZ.R +\name{trajectoryToXYZ} +\alias{trajectoryToXYZ} +\title{Convert trajectories to Easting/Northing representation.} +\usage{ +trajectoryToXYZ(trajectory, origin) +} +\arguments{ +\item{trajectory}{A flighttrajectory object.} + +\item{origin}{A length 2 numeric vector giving the origin lon/lat for the +conversion.} +} +\value{ +A flattrajectory object. +} +\description{ +Convert trajectories to Easting/Northing representation. +} +