Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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
Thanks, ill look into your method, but for now i am going to stick with spherical coords...anyone else seem this problem?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!