Skip to content

Commit

Permalink
fix: In trueWind.js derived values are now set to null in case that t…
Browse files Browse the repository at this point in the history
…he input is null.

In trueWind.js derived values are now set to null in case that the input is null. Before a AWS of null resulted in a TWS of 0.
  • Loading branch information
chris0348 committed Jul 25, 2024
1 parent dbe9cfd commit 1a96cd9
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions calcs/trueWind.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,33 @@ module.exports = function (app) {
'environment.wind.angleApparent'
],
calculator: function (headTrue, speed, aws, awa) {
var apparentX = Math.cos(awa) * aws
var apparentY = Math.sin(awa) * aws
var angle = Math.atan2(apparentY, -speed + apparentX)
var speed = Math.sqrt(
Math.pow(apparentY, 2) + Math.pow(-speed + apparentX, 2)
)
var angle
var speed
var dir

if (aws < 1e-9) {
angle = awa
}
if (headTrue == null || speed == null || aws == null || awa == null) {
angle = null
speed = null
dir = null
} else {
var apparentX = Math.cos(awa) * aws
var apparentY = Math.sin(awa) * aws
angle = Math.atan2(apparentY, -speed + apparentX)
speed = Math.sqrt(
Math.pow(apparentY, 2) + Math.pow(-speed + apparentX, 2)
)

if (aws < 1e-9) {
angle = awa
}

var dir = headTrue + angle
dir = headTrue + angle

if (dir > Math.PI * 2) {
dir = dir - Math.PI * 2
} else if (dir < 0) {
dir = dir + Math.PI * 2
if (dir > Math.PI * 2) {
dir = dir - Math.PI * 2
} else if (dir < 0) {
dir = dir + Math.PI * 2
}
}

return [
Expand Down

0 comments on commit 1a96cd9

Please sign in to comment.