# Given: Latitude/Longitude/Bearing/Distance, Where am I? PROBLEM

This topic is 2804 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey Guys,

I have been using the thread athttp://www.gamedev.net/community/forums/topic.asp?topic_id=504860 and it has been a real life saver for me. The information given here: file:///Users/tomstoffer/Projects/OvC/trunk/code/Research/Calculate%20distance%20and%20bearing%20between%20two%20Latitude%20Longitude%20points%20using%20Haversine%20formula%20in%20javascript.html is priceless.

I am having a small problem with one of the functions though and i cant work out what is going on. It is the funtion which gets a new latitude/longitude given a bearing and a distance.

Here is how i have written it in Objective C :

- (SCoord) getDestPosWithCurPos:(SCoord)p bearing:(float)b distance:(float)d {

float dLat = RADIANS_TO_DEGREES(asinf(sinf(lat1)*cosf(dAngular) + cosf(lat1)*sinf(dAngular)*cosf(b)));
float x = sinf(b)*sinf(dAngular)*cosf(lat1);
float y = cosf(dAngular)-sinf(lat1)*sinf(dLat);
float atan = atan2(x, y);
float dLon = RADIANS_TO_DEGREES(lon1 + atan);

SCoord dPos = SCoordMake(dLat, dLon);
return dPos;
}

It is working correctly for the most part except if i have a case where the path crosses over a poll. Say for instnace i have parameters of (-89, 1), (pi) bearing, (100)distance with radius of planet being 6371

My output coords are (-86, 1) the latitude is correct but the longitude is still showing on the east hemisphere. I have entered in these same values on the Movable types javascript app and it shows the longitude should be 179(the west hemisphere.

Can anyone spot whats going on here, im stuck. Im thinkin that as the bearing is pi, x is gonna be 0. Seems thats where the problem is coming from but my formulas is the same as the movable types one so i dont know???

##### Share on other sites
Sorry the second link was supposed to be this...http://www.movable-type.co.uk/scripts/latlong.html

##### Share on other sites
You want to walk around on the surface of a sphere?

I'd ditch the spherical coordinates and just represent where I am as a point in 3-space. The rest is described here.

Much simpler.

[EDIT: Maybe you'd be interested in the idea of a Darboux frame; that's really the idea behind the simple equations I gave in the above-referenced forum thread.]

##### Share on other sites
Thanks, ill look into your method, but for now i am going to stick with spherical coords...anyone else seem this problem?

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
17
5. 5

• 14
• 11
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631756
• Total Posts
3002111
×