Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hey everyone.

Im trying to get the Magnetic and True heading for the aircraft into C#

 

I have the Offset - 0580

I have also used this Offset - 02A0

 

Both give different results.

I just cant work out the formular to get the correct headding.

 

Anyone mind helping me on this one.

Posted

Hi Steven,

 

Below is the code with all the conversion formulas. As you can see, once you've converted the true heading and magnetic variation to degrees you just need to subtract the magvar from the true heading to get the magnetic heading.

 

Take care when declaring the offsets, note the different sizes and the fact that the true heading is Unsigned.

        private Offset<uint> headingTrue = new Offset<uint>(0x0580);
        private Offset<short> magVar = new Offset<short>(0x02A0);

        private void someMethod()
        {
            // after calling process()
            double headingDegreesTrue = (double)headingTrue.Value * 360.0 / (65536.0 * 65536.0);
            double magVarDegrees = (double)magVar.Value * 360.0 / 65536.0;
            double headingDegreesMagnetic = headingDegreesTrue - magVarDegrees;
            // mag heading may now be < 0 or > 360, so we need to normalise
            headingDegreesMagnetic %= 360;
        }

I've 'spelt it out' there, you can obviously combine some of the steps to make the code shorter.

 

Paul

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.