Skip to content

Commit

Permalink
Report correct wind direction
Browse files Browse the repository at this point in the history
fix #16
  • Loading branch information
ilyapoz committed Jan 30, 2014
1 parent 1d58377 commit 8321efb
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions blueskies.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var canopyHeading;
var canopyMode;
var steadyPointLocation;
var windSpeed = 5;
var windDirection = 0;
var windDirection = 0; // We use the azimuth of the wind speed vector here, not the navigational wind direction (i.e. where wind is blowing, not where _from_)
var openingAltitude = 1000;

// UI objects
Expand Down Expand Up @@ -81,6 +81,20 @@ function radToDeg(rad) {
return rad * 180 / Math.PI;
}

function normalizeAngle(angle) {
while( angle > 2 * Math.PI ) {
angle -= 2 * Math.PI;
}
while( angle < 0 ) {
angle += 2 * Math.PI;
}
return angle;
}

function reportedWindDirection(direction) {
return normalizeAngle(direction + Math.PI);
}

function moveCoords(coords, dx, dy) {
var earthRadius = 6378137;
var newLat = coords.lat() + radToDeg(dy / earthRadius);
Expand Down Expand Up @@ -289,11 +303,7 @@ function onKeyDown(e) {
}

// Normalize canopy heading
if (canopyHeading < 0) {
canopyHeading += Math.PI * 2;
} else if (canopyHeading > Math.PI * 2) {
canopyHeading -= Math.PI * 2
}
canopyHeading = normalizeAngle(canopyHeading);
}

function onMapRightClick(event) {
Expand Down Expand Up @@ -332,7 +342,7 @@ function onTimeTick() {
function onWindDirectionSliderValueChange(event, ui) {
windDirection = degToRad(ui.value);
rotateDiv($("#wind-arrow").get(0), windDirection);
$("#wind-direction-value").html(formatHeading(windDirection));
$("#wind-direction-value").html(formatHeading(reportedWindDirection(windDirection)));

updateLandingPattern();
}
Expand Down

0 comments on commit 8321efb

Please sign in to comment.