commit 2140856119d5c29e66a1a8e3061170e0df9939f5
parent fe419c4b3e0452e718c91e3b98822d671969caad
Author: eamoncaddigan <eamon.caddigan@gmail.com>
Date: Mon, 12 Sep 2016 09:53:11 -0400
Rearranging support function for move to separate time to CPA function.
Diffstat:
3 files changed, 45 insertions(+), 12 deletions(-)
diff --git a/R/calculateSLoWC.R b/R/calculateSLoWC.R
@@ -35,6 +35,7 @@ calculateSLoWC <- function(trajectory1, trajectory2) {
lon0, lat0),
trajectory2$altitude)
+ # Convert bearing/speed to velocity vector.
ac1Velocity <- bearingToXY(trajectory1$bearing, trajectory1$groundspeed)
ac2Velocity <- bearingToXY(trajectory2$bearing, trajectory2$groundspeed)
@@ -85,18 +86,6 @@ calculateSLoWC <- function(trajectory1, trajectory2) {
return(vSLoWC)
}
-# Convert a bearing (in degrees) and velocity (in knots) to north and east
-# velocity (in ft / s).
-bearingToXY <- function(bearing, velocity) {
- # Velocity should be in knots. Convert to ft / s
- fps <- velocity * 1.68781
- # Bearing should be degrees from north. Convert to radians.
- theta <- bearing * pi / 180
- # Return x and y components of the velocity in ft / s
- return(cbind(fps * sin(theta),
- fps * cos(theta)))
-}
-
# The Fernandez-Gausti squircular operator.
FGnorm <- function(x, y) {
return(sqrt(x^2 + (1 - x^2) * y^2))
diff --git a/R/lonlatToXY.R b/R/lonlatToXY.R
@@ -30,3 +30,22 @@ lonlatToXY <- function(longitude, latitude, originLongitude, originLatitude) {
return(xyFeet)
}
+
+#' Convert a bearing (in degrees) and velocity (in knots) to north and east
+#' velocity (in ft / s).
+#'
+#' @param bearing A numeric vector giving the instantaneous direction of the
+#' velocity in degrees.
+#' @param speed A numeric vector giving the instantaneous magnitude of the
+#' velocity in knots.
+#' @return A n x 2 matrix giving the north/south and east/west components of the
+#' velocity, in feet/s.
+bearingToXY <- function(bearing, speed) {
+ # Velocity should be in knots. Convert to ft / s
+ fps <- speed * 1.68781
+ # Bearing should be degrees from north. Convert to radians.
+ theta <- bearing * pi / 180
+ # Return x and y components of the velocity in ft / s
+ return(cbind(fps * sin(theta),
+ fps * cos(theta)))
+}
diff --git a/man/bearingToXY.Rd b/man/bearingToXY.Rd
@@ -0,0 +1,25 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/lonlatToXY.R
+\name{bearingToXY}
+\alias{bearingToXY}
+\title{Convert a bearing (in degrees) and velocity (in knots) to north and east
+velocity (in ft / s).}
+\usage{
+bearingToXY(bearing, speed)
+}
+\arguments{
+\item{bearing}{A numeric vector giving the instantaneous direction of the
+velocity in degrees.}
+
+\item{speed}{A numeric vector giving the instantaneous magnitude of the
+velocity in knots.}
+}
+\value{
+A n x 2 matrix giving the north/south and east/west components of the
+ velocity, in feet/s.
+}
+\description{
+Convert a bearing (in degrees) and velocity (in knots) to north and east
+velocity (in ft / s).
+}
+