Jump to content
  • Advertisement
Sign in to follow this  
RonHiler

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

This topic is 3587 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

Alright, so I'm on a perfect sphere at a location with a known latitude and longitude. I then walk some known distance with a known bearing. Where do I end up? What is my new latitude and longitude? Thanks for any insights with this.

Share this post


Link to post
Share on other sites
Advertisement
convert lat/lon to vector from the center of the sphere. Convert distance/bearing to rotation matrix. Multiply M*v. Convert back to lat/lon.

Share this post


Link to post
Share on other sites
This site explained it quite well to me when I needed to do the same calculations:
http://www.movable-type.co.uk/scripts/latlong.html

Share this post


Link to post
Share on other sites
After some pretty extensive testing, I unfortunately ran into another snag, and I hope you guys have a bit more advice.

The circumference of my world is 1024 (unitless). So the radius is 1024/(2PI), or about 162.97 (which I have set to a constant I call WORLDBUILDER_WORLD_RADIUS).

The equations I am using to get a new lat/long based on starting lat/long, distance, and bearing are:

EndLatitude = asin(sin(StartLatitude)*cos(Distance/WORLDBUILDER_WORLD_RADIUS) + cos(StartLatitude)*sin(Distance/WORLDBUILDER_WORLD_RADIUS)*cos(Bearing));

EndLongitude = StartLongitude + atan2(sin(Bearing)*sin(Distance/WORLDBUILDER_WORLD_RADIUS)*cos(StartLatitude), cos(Distance/WORLDBUILDER_WORLD_RADIUS) - sin(StartLatitude)*sin(EndLatitude));

They work *almost* perfectly. But here is the snag.

I set a point at the equator (lat = 0, long = PI) and fed the routine a distance of 512 with a bearing of PI/2 (straight east). As expected, the new point came up exactly half way around the world from where it started (2PI). Cool.

Then I set a point closer to the north pole (lat = 1.0, long = PI) and gave it the same distance and bearing. What I got out of the routine was again, a point exactly half way around the world from where I started (2PI). Boo!

Clearly if someone is walking a distance straight east for 512 units at the equator, they won't end up at the same longitude as someone walking that same distance near the north pole. The latter should have gone a much greater angular distance than the former.

I think my problem is this part of the equation:
Distance/WORLDBUILDER_WORLD_RADIUS
That is the angular distance, but it assumes the radius is equal to the world radius (i.e. it's calculating based on the greatcircle of the two points). I think what I actually need is the radius of the circle along the path used (not sure what that is called) rather than the greatcircle.

I can do that if the two points happen to share the same latitude (I derived the equation for that), but if they do not, I'm at a loss.

To break it all down, given a lat/long pair, a bearing, and a distance travelled on the surface of a sphere, what is the angular distance travelled?

At least, I THINK that's the question. Given the description of my issue, let me know if you think otherwise, and if there is any advice you would give.

Share this post


Link to post
Share on other sites
Wait. When you specify a "bearing", what does it mean exactly? I [and probably Sneftel] thought you were somehow specifying where you are facing initially, and that you then proceed to walk straight, following a great circle.

If this is not the case, you need to explain your problem better.

EDIT: Is this what you are looking for?

Share this post


Link to post
Share on other sites
Quote:
Original post by RonHiler
Clearly if someone is walking a distance straight east for 512 units at the equator, they won't end up at the same longitude as someone walking that same distance near the north pole.
Stand five inches away from the north pole, facing east. Start walking. If you are walking straight, as opposed to walking in a teeny little circle, you will find that you are no longer facing east.

Share this post


Link to post
Share on other sites
No, it's definitely NOT a Rhumb line. Circling into the poles is definitely NOT what I want, hehe.

You guys might be right. On further reflection, I probably DO want to be walking along a great circle. There may not be a bug here at all. I'll have to do some testing involving graphics to make sure. Sorry, I'm having a tough time visualizing the pathing in my head.

Share this post


Link to post
Share on other sites
Assuming you care about shortest paths, you'll be going along great circles. Example: Tokyo is roughly due west of New York. If you get in a plane in New York, the plane will head northwest from New York, going in a straight line, passing over Alaska. By the time it gets to Tokyo, it'll be going southwest.

Share this post


Link to post
Share on other sites
Your equations are correct, you just need to figure out what your inputs actually are.

Latitude:
0 -> You're on the equator
+pi -> You're on the North pole
-pi -> You're on the South pole

Longitude:
Traveling in positive direction -> You're going east
Traveling in negative direction -> You're going west
Traveling (+/-)pi -> You end up on the other side of the world



Bearing:
0 -> You're heading north
+pi/2 -> You're heading west
-pi/2 -> You're heading east
(+/-)pi -> You're heading south

In your algorithm 'bearing' only mean initial bearing. You will travel on a great circle starting in the direction of 'bearing'.

Also, normally when people talk about bearings, the positive bearing is heading east (clockwise), but since this formula is based om radians counter clockwise is the positive bearing.


The reason you end up in almost the same position is because you're going a pi/2 degrees, which is halfway around the world (not all the way as you said).

To figure out what happens do this (or imagine it):
1. On a ball, decide where the equator, north and south pole are.
2. Find a string (shoelace type, not char[] type :) )
3. Decide on a point on the equator. Find the point on the equator half way around the world towards east.
4. Measure the distance between the points with your string.
5. With the same string and distance, place it very near the north pole.
6. On that point, find the direction of east and go the same distance you measured before.
7. You will end up very close to the previous point.




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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!