Calculating longitude distortion on approach to poles? - unity3d

I'm working on a game in which players are trying to target points on a sphere.
As targets approach the poles, the game should become more forgiving in longitude because the ratio of longitude distance to latitude distance grows. At the poles, the game should be infinitely forgiving in longitude.
What formula am I looking for that tells me how much longitudinal distance equals 1 unit of latitudinal distance for a particular latitude? Assume that longitude and latitude are expressed as floats ranging from 0-1, and at the equator (0.5) longitude equals latitude.

Formula is rather simple (for usual spherical coordinates with -Pi/2..Pi/2 latitude range):
Lon_Lat_Ratio = Cos(Latitude)
But your parametrization is different, so
Lon_Lat_Ratio = Sin(Latitude_01 * Pi)
Ratio is 1 on equator and 0 at poles

Related

Question about Matlab's aerospace toolbox's gravitysphericalharmonic library

I'm currently trying to learn how to use the gravity models that Matlab's 'gravitysphericalharmonics' library has. In this documentation: https://www.mathworks.com/help/aerotbx/ug/gravitysphericalharmonic.html#mw_3bdd1e99-46be-4fd5-8b7c-6dd710546616
It gives us two examples:
Calculate the gravity in the x-axis at the equator on the surface of Earth. This example uses the default 120 degree model of EGM2008 with default warning actions.
gx = gravitysphericalharmonic([-6378.137e3 0 0])
Calculate the gravity at 25,000 m over the south pole of Earth.
[gx, gy, gz] = gravitysphericalharmonic([0 0 -6381.751e3],'EGM96','Error')
Here's my question, how did they get -6381.751e3 for the second question if they're just finding the gravity 25,000m above the surface of Earth? If Earth's radius is ~6378.137e3 meters, then calculating the gravity at 25,000m above Earth would just be the radius + 25,000 meters right?
Lastly, I wanted to just ask someone with more knowledge about this module why it was -6378.137e3 m for the first question. If we're taking the coordinate from just the surface of Earth, wouldn't that number have to be positive?
Sorry if this doesn't make any sense, I'm new to this stuff and I really want to learn! Thanks!
The first example uses a 3D position vector, in a coordinate system with its origin at the center of the planet (Earth). The position vector[-6378.137e3 0 0] is on the equator, as is [6378.137e3 0 0] (they are on opposite sides of the world). Any other position vector with magnitude 6378.137e3 and a Z component (the third number) of 0 would also be on the equator.
The Earth is not a perfect sphere; it is an oblate spheroid. The radius at the equator is 6378.137 km, but the radius at the poles is 6356.752 km. Their documentation is not great here, but they have arrived at the position vector in the second example by taking this polar radius and increasing the magnitude of the vector by 15 km. The Z component is negative because this example is at the South Pole; if the Z component were positive, it would be at the North Pole. Because it is negative, they have to add -15 km to get to a point that is 15 km above the surface (but if you were looking at a globe, and holding the globe so that north is up, that point would be below the globe).
They have probably used examples with negative values in the position vector precisely to ensure that people ask themselves the kinds of questions that you are asking.
The aerospace toolbox also provides a function ecef2lla to convert these position vectors into latitude, longitude, and altitude, which may help you understand them.

Calculate longitude on the 0 degree latitude line, knowing the starting point (latitude,longitude) and azimuth on ellipsoid Earth model

Input:
Observer (Lat,Lon WGS84 coordinates) and an azimuth angle (degrees)
Output:
By considering only the 0 degrees latitude line, I am trying to get the intersection longitude point from the observer point with the given azimuth. I am considering the ellipsoid Earth model.
If you have the Mapping Toolbox available, you can use the track1 function. See the Mathworks documentation at http://www.mathworks.com/help/map/ref/track1.html?refresh=true.
Basic formula is
lon(lat, lon, Z) = lon - atan(sin(lat)*tan(Z))
(Beware that your calculator uses degrees)

Finding distance between two points using latitude and longitude in Degree Minutes Seconds format

I am working on a tool to find the distance between two points whose latitude and longitude are given. Its ok when the latitude and longitude is given in Signed Degree Format. But I couldn't find a way to calculate the distance when latitude and longitude is given in Degree Minutes Seconds Format (ex: N 11° 14' 52').Can anybody suggest me a way to find the distance ?
So first convert the DMS coordinates to your degree format.
e.g. 11°14'52" = 11 + 14/60 + 52/3600 = 11.24777778 degrees
and then continue as you did with your destance calculation that you say already works.
Edit:
Note that latitudes in the southern hemisphere and longitudes in the western hemisphere are negative. So the above formula really should be:
sign(degrees) * (abs(degrees) + minutes/60 + seconds/3600)

Calculating a location coordinate a certain distance from another coordinate

I have a CLLoctionCoordinate2D and I want to figure out what the points are a given distance away from it. For an example, lets use 100 miles. So I want to computer the point 100 miles to the north, south, east, and west of it.
East and west are pretty easy. I converted both coordinates to MKMapPoints and used distanceInMeters*MKMapPointsPerMeterAtLatitude(latitude). This works fine for east and west because the latitude is constant.
However, this does not work for north and south. To the north, it underestimates and to the south it underestimates (because MKMapPointsPerMeterAtLatitude is changing as you move). How could I compute these points for the north and south?
There's 60 nautical miles per degree of latitude. This is also true for longitude, but at the equator only. To calculate the distance in longitude in nautical miles, multiply the distance in degrees longitude * 60nm * cos( latitude in radians ).
Do the calculations of your new points (100 miles north, 100 miles south, etc.) in lat lon, not MKMapPoints, then convert your lat/lon (CLLocationCoordinate2D ?) points to MKMapPoints.
Lines of latitude are always a constant angle apart, as measured from the earth's core that's kinda their point. So what you need to do is work out how far apart in terms of miles they are, an then use that to get 100 miles north/south and then get the map points for that. The formula for the distance at the earth's surface will be online somewhere, probably in metres or kilometres.

Convert Latitude / Longitude in Degree/Radians?

How can i convert Latitude and longitude in degree/radians?
Do you guys any formula or any idea?
I want to show it on MapKit.
Thanks.....
Since Latitude and Longitude are measured in degrees, you can use the following formula to convert to radians, and back to degrees:
Radians = Degrees * PI / 180
and on the inverse,
Degrees = Radians * 180 / PI
If you look at earth like a sphere, latitude and longitude are already given in units of degrees. Longitude is expressed as -180 degrees (-pi radians) to 180 degrees (pi radians) with 0 degrees centered at the prime meridian. Latitude is expressed as -90 degrees (-pi/2 radians) to 90 degrees (pi/2 radians) with respect to the equator. This is already a spherical coordinate system (depending on the caveats I give below) with earth's radius approximately 6371 km.
So just convert by multiplying by pi/180 as you would for convert degrees to radians in any normal sense. If you want to use those radians for doing something specific like calculating distances between two lat/lons then you should look at some pre-existing sources.
Similar questions have been asked before, i.e. Convert Lat-Lon to Cartesian Coordinates.
Generally speaking, the 'correct' answer for a lot of conversion quesitons depends on what error is acceptable in your answer (can it be off 1 mile for distances of 20 miles, etc.) and the model of the world is appropriate in your problem domain. The world is better approximated by an ellipsoid (squashed sphere) than a sphere, but it is easier to perform the calculations assuming earth is a sphere and the error introduced can be minimal. Especially if your program is just looking for 'rough' answers that won't be used for, say, engineering projects.
It is likely that the lat-lons you have are given in a coordinate system called WGS-84 which is what most hardware GPS units use, which assumes an ellipsoid model.
Note that I had a lot more sources, but I guess I have low reputation so I can only post two links. I would suggest reading on wikipedia about WGS-84, earth's radius, spherical coordinates, prime meridian, and equator for some visual references.