Jump to content
The simFlight Network Forums

Getting AC Headding (MAG & True)


StevenK

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

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.