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

Started by
2 comments, last by Stoff81 13 years, 5 months ago
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%20&#106avascript.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 lat1 = DEGREES_TO_RADIANS(p.latitude);
float lon1 = DEGREES_TO_RADIANS(p.longitude);
float dAngular = d/PLANET_RADIUS;

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 &#106avascript app and it shows the longitude should be 179(the west hemisphere.<br><br>Can anyone spot whats going &#111;n 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 &#111;ne so i dont know???
Advertisement
Sorry the second link was supposed to be this...http://www.movable-type.co.uk/scripts/latlong.html
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.]
Thanks, ill look into your method, but for now i am going to stick with spherical coords...anyone else seem this problem?

This topic is closed to new replies.

Advertisement