Jump to content
The simFlight Network Forums

Getting AC Headding (MAG & True)


StevenK
 Share

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • 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.