Skip to content

Commit

Permalink
Update / Consolidate course data calculations (#62)
Browse files Browse the repository at this point in the history
* Add DTG calculation

* Add geodesy library

* Add XTE calculation

* fix typo

* Add geodesy library

* Add XTE calculation

* create `courseData.js` to hold course calculations

* consolidate DTG calc

* Update VMG calc `group` value
  • Loading branch information
panaaj authored Oct 9, 2020
1 parent 6a4477a commit 1c94e76
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 36 deletions.
73 changes: 73 additions & 0 deletions calcs/courseData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const LatLon = module.require('@panaaj/sk-geodesy/latlon-spherical')
.LatLonSpherical

module.exports = function (app) {
return {
group: 'course data',
optionKey: 'dtg',
title:
'Course DTG, XTE, BRG, etc (based on courseGreatCircle.nextPoint / previousPoint)',
derivedFrom: [
'navigation.courseGreatCircle.nextPoint.position',
'navigation.courseGreatCircle.previousPoint.position',
'navigation.position'
],
calculator: function (
nextPointPosition,
previousPointPosition,
vesselPosition
) {
let pos = vesselPosition
? new LatLon(vesselPosition.latitude, vesselPosition.longitude)
: null

let pathStart = previousPointPosition
? new LatLon(
previousPointPosition.latitude,
previousPointPosition.longitude
)
: null

let pathEnd = nextPointPosition
? new LatLon(nextPointPosition.latitude, nextPointPosition.longitude)
: null

// ** Cross track Error **
let xte =
!pos || !pathStart || !pathEnd
? null
: pos.crossTrackDistanceTo(pathStart, pathEnd)

// The bearing of a line between previousPoint and nextPoint, relative to true north.
let trkBearingTrue =
!pos || !pathStart || !pathEnd
? null
: pathStart.initialBearingTo(pathEnd)

// ** Distance from vessel to nextPoint **
let dtg = !pos || !pathEnd ? null : pos.distanceTo(pathEnd)

// The bearing of a line between the vessel's current position and nextPoint, relative to true north
let brg = !pos || !pathEnd ? null : pos.initialBearingTo(pathEnd)

return [
{
path: 'navigation.courseGreatCircle.crossTrackError',
value: xte
},
{
path: 'navigation.courseGreatCircle.bearingTrackTrue',
value: trkBearingTrue
},
{
path: 'navigation.courseGreatCircle.nextPoint.distance',
value: dtg
},
{
path: 'navigation.courseGreatCircle.nextPoint.bearingTrue',
value: brg
}
]
}
}
}
34 changes: 0 additions & 34 deletions calcs/distanceToGo.js

This file was deleted.

2 changes: 1 addition & 1 deletion calcs/vmg.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = function (app) {
return {
group: 'vmg',
group: 'course data',
optionKey: 'vmg_Course',
title:
'Velocity Made Good to Course (based on courseGreatCircle.nextPoint.bearingTrue heading true and speedOverGround)',
Expand Down
2 changes: 1 addition & 1 deletion calcs/vmg_wind.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = function (app) {
return {
group: 'vmg',
group: 'course data',
optionKey: 'vmg_Wind',
title:
'Velocity Made Good to wind (based on wind.directionTrue and speedOverGround)',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
}
},
"dependencies": {
"@panaaj/sk-geodesy": "^1.0.0",
"baconjs": "^0.7.88",
"cubic-spline": "^1.0.4",
"geolib": "^2.0.24",
Expand Down

0 comments on commit 1c94e76

Please sign in to comment.