# How to calculate direction of a point A in respect to a given point B?

• 2013-02-11, 09:48
pooja_1650
How to calculate direction of a point A in respect to a given point B?
Hello,

I am working on an app where I have two points with their latitude and longitude values, say Point A and Point B. I know the distance between them as well. But I want to calculate in which direction the point B is in respect of point A.

After checking it on google, I came to know that what I am looking for is perhaps called [B]Bearing[/B]. To calculate, Bearing itself, the Haversine formula can be used as mentioned at following sites:
[url]http://www.movable-type.co.uk/scripts/latlong.html[/url]

Considering I have calculated bearing points (intial/final), my question is:
1) How to calculate direction (in East/West terms)?

If Bearing is not the right term which I should look for, then how should I find the direction?

Thanks a lot.
• 2013-02-11, 10:55
wizard_hu_
Re: How to calculate direction of a point A in respect to a given point B?
You need what the pages call "initial bearing".
• 2013-02-11, 11:20
pooja_1650
Re: How to calculate direction of a point A in respect to a given point B?
[QUOTE=wizard_hu_;911006]You need what the pages call "initial bearing".[/QUOTE]
But that's what I wanted to ask. How to determine direction from the bearing value which is given in terms of degrees, minutes & seconds?

For example, I tried to check my location (India) from Germany (near to) at the site [url]http://www.movable-type.co.uk[/url]. The following figure shows me the direction. Now the initial bearing value is 75 degress which falls in 0-90 degees range, so should I consider it in North direction?
[ATTACH]1451[/ATTACH]

I mean, it does not look right to me and not the accurate result as well.
• 2013-02-11, 11:42
vineet.jain
Re: How to calculate direction of a point A in respect to a given point B?
You can determine the direction as how they have done here: [url]http://www.packtpub.com/article/windows-phone-7-silverlight-location-services[/url]

Though they calculate course, but i think meaning is somewhat same(so course from Germany to India implies heading East which is correct)
• 2013-02-11, 11:53
pooja_1650
Re: How to calculate direction of a point A in respect to a given point B?
[QUOTE=vineet.jain;911011]You can determine the direction as how they have done here: [url]http://www.packtpub.com/article/windows-phone-7-silverlight-location-services[/url]

Though they calculate course, but i think meaning is somewhat same(so course from Germany to India implies heading East which is correct)[/QUOTE]
Thanks Vineet for the link.
As per their code, my example would result in West direction though it should be WS (west - south). It's not the accurate result but I guess it will work for me for the time being.
• 2013-02-11, 12:13
wizard_hu_
Re: How to calculate direction of a point A in respect to a given point B?
I do not know. Based on Wikipedia I approximated India with Point 1: 28, 77 (New Delhi, integer parts only), and Germany with Point 2: 52, 13 (Berlin, integer degrees again).
And the result is 5842 km, initial bearing 315 degrees. Seems to be correct to me.
(I am talking about [url]http://www.movable-type.co.uk/scripts/latlong.html[/url], by the way)
• 2013-02-11, 12:31
pooja_1650
Re: How to calculate direction of a point A in respect to a given point B?
Ok Wizard. Will check it once again and revert back here.

Thanks to both of you.
• 2013-02-14, 12:37
shpe
Re: How to calculate direction of a point A in respect to a given point B?
I would go like this: atan2(latB-latA,lonB-lonA)
this would have a little error as LAT and LON doesn't measure the same in meters... I calculated for an application that 1"LAT/1"LON=102/73

so probably the right formula would be like this:
atan2(73*(latB-latA),102*(lonB-lonA))

also you have to keep in mind that the earth is round and from LON 1" to LON 350" is just 11" away and not 349" :)
• 2013-02-14, 13:02
wizard_hu_
Re: How to calculate direction of a point A in respect to a given point B?
I would do that too on a deserted island. However since the correct expression is available on the referred pages using spherical geometry, I would stay with that. And yes, after the spherical corrections, the last step indeed uses atan2 ([url]http://www.movable-type.co.uk/scripts/latlong.html#bearing[/url])