Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: In trueWind.js derived values are now set to null in case that the input is null. #138

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading