I did this programmatically in Node JavaScript ES6:
let calculateHeading = function(nsVelocity, ewVelocity) {
/*
Converts velocity North/South East/West velocity and turns it into a 360 degree compass heading
Input: nsVelocity, ewVelocity
Output: compass heading degree 0 - 360, 0/360 is North
*/
try {
// Calculates the heading in degrees based off north south velcoity and east west velocity
let fnsVelocity = parseFloat(nsVelocity);
let fewVelocity = parseFloat(ewVelocity);
let velocity = calculateVelocity(nsVelocity, ewVelocity);
if (velocity < 0.000001) {
velocity = 1.0;
}
// get angle of vector from x-coordinate in degrees
let rotation = Math.round(Math.acos( Math.abs(fewVelocity) / velocity ) / 0.0174533);
// angle as calculated is a magnitude, always positive
// use the two velocities' signs to adjust angle in four possible quadrants
if (fnsVelocity >= 0.0) {
if (fewVelocity >= 0.0) {
rotation = Math.abs(rotation - 90);
} else {
rotation = rotation + 270;
}
} else {
if (fewVelocity >= 0.0) {
rotation = rotation + 90;
} else {
rotation = rotation + 180;
}
}
return Math.round(rotation);
} catch (e) {
return 0;
}
};
let calculateVelocity = function(velocityNs, velocityEw) {
/*
Calculates velocity from components
Args:
velocityNs: Float north-south velocity knots
velocityEw: Float east-west velocity knots
Returns:
Float velocity knots
*/
try {
var fEwVelocity = parseFloat(velocityEw);
var fNsVelocity = parseFloat(velocityNs);
return Math.round(Math.sqrt(Math.pow(fNsVelocity, 2) + Math.pow(fEwVelocity, 2)));
} catch (e) {
return 0;
}
};