I know there are other questions similar to this one, but most of them deal with only converting one to the other. But I am searching for a algorithms that convert to and from each other. Simply using one of each has not produced the desired results.
For my purposes a unit sphere is more then acceptable. Any radius value would be 1.
Here are my current methods for performing this, in simple psudocode.
From latitude and longitude to a point on a unit sphere.
x = cos( longitude ) * sin( latitude ) y = sin( longitude ) * sin( latitude ) z = cos( latitude )
From 3D coordinates on a unit sphere to latitude and longitude.
latitude = acos( z ) longitude = atan2( x, y )
However these are not reversible and my trigonometry is not what it should be.
atan
won't return the angle in the correct quadrant, which is whatatan2
is for. – SirGuy