I have this method for determining the difference between 2 0-360 compass headers.
Although this works to find out how far (as always, with a positive result), I cannot figure out what needs to be done to enter a character in the output file.
Ideally, if the shortest distance from the starting heading to the ending heading is a clockwise movement, I would like error have a positive sign, if the shortest distance between headings includes counterclockwise movement, I would like error have a negative sign.
A few examples of desired I / O
initial - final - error
0 .................... 30 .......... 30
30 .................... 0 .......... -30
360 .................... 1 .......... 1
1 .................... 360 .......... -1
the code:
/// <summary> /// Calculate the error from a given initial heading to a final heading /// </summary> /// <param name="inital"></param> /// <param name="final"></param> /// <returns></returns> private double GetHeadingError(double initial, double final) { double directionA = final - initial; double directionB = 360 - (final + initial); double error = 0; if (Math.Abs(directionA) < Math.Abs(directionB)) { error = directionA; } else { error = directionB; } return error; }
c # compass-geolocation 360-degrees
chris12892
source share