Sign in to follow this  
Stoff81

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

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 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 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 this post


Link to post
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 this post


Link to post
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

Sign in to follow this