Jump to content
The simFlight Network Forums

Calculate a bearing


Recommended Posts

Hi all

I am writing a program which uses FSCUIPC to control different things like weather etc depending on location. I have an algorithm to calculated distance between two points but wondered if anyone could point me at where to find one to determine the bearing of one location (position of the aircraft) to another (waypoint).

thanks in advance

Link to comment
Share on other sites

... wondered if anyone could point me at where to find one to determine the bearing of one location (position of the aircraft) to another (waypoint).

The formula I use in TrafficLook is very approximate, being normal plane trigonometry. That'd be reasonably close for near waypoints, but progressively worse as distance increases due to the curvature of the Earth. Also, I think my formula would be pretty bad anywhere near the poles (> 60 degrees N or S).

// Everything in double floats, angles in degrees, result is True not Mag

double Wrk = cos(PI * (fabs(MyLat+WayLat))/360.0)*(WayLon-MyLon);

double Bearing = (MyLat == WayLat) ? 90.0 : (180.0 * atan(fabs(Wrk/(WayLat-MyLat))) / PI);

if (MyLat >= WayLat)
{	if (MyLon >= WayLon) Bearing = 180.0 + Bearing;
	else Bearing = 180.0 - Bearing;
}
else if (MyLon > WayLon) Bearing = 360.0 - Bearing;

If you want accurate bearings for longer distances or for anywhere in the world, you need spherical trig. Then I'm rather lost. You can find formulae on the 'net but you need to search.

Regards,

Pete

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.