/
542c1a6b25808b0e2600017c.js
35 lines (33 loc) · 1.04 KB
/
542c1a6b25808b0e2600017c.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function windComponents(rwy, windDirection, windSpeed) {
var runwayAngle = 0,
rwyParts = rwy.split(''),
windToRunwayAngle = 0,
crosswind = 0,
headwind = 0,
ret = '';
if (rwyParts.length > 1) {
runwayAngle += parseInt(rwyParts[0]) * 100;
runwayAngle += parseInt(rwyParts[1]) * 10;
} else {
runwayAngle += parseInt(rwyParts[0]) * 10;
}
windToRunwayAngle = runwayAngle - windDirection;
windToRunwayAngle = Math.radians(windToRunwayAngle);
crosswind = Math.sin(windToRunwayAngle) * windSpeed;
headwind = Math.cos(windToRunwayAngle) * windSpeed;
if (Math.round(headwind) > 0) {
ret += 'Headwind ';
} else {
ret += 'Tailwind ';
}
ret += Math.round(Math.abs(headwind)) + ' knots. Crosswind ' + Math.round(Math.abs(crosswind)) + ' knots from your ';
if (Math.round(crosswind) > 0) {
ret += 'left.';
} else {
ret += 'right.';
}
return ret;
}
Math.radians = function (degrees) {
return degrees * Math.PI / 180;
};