Rather than the normal way of having latitude/longitude, with a north/south pole radiating lines for longitude, and then latitude lines being parallel circles of various radii, I instead have *two* poles, so a north/south pole and an east/west pole both radiate lines. So both sets of lines being like segments of an orange, coming together at the poles.
As in this rough diagram, the two poles shown as red and blue:
blue pole marked x is also the x axis (+ve to the right)
red pole marked y is also the y axis (+ve going upwards)
+z axis is coming out of the screen towards you
Now, I am managing to get a 3D point from a given lat/long, using these equations:
real_x = worldRadius * cos(latitude) * sin(longitude) real_y = worldRadius * sin(latitude) * cos(longitude) real_z = worldRadius * cos(latitude) * cos(longitude)
However, I also need to be able to do the reverse, from a given 3D point on the sphere, calculate the lat/long. This is giving me great trouble.
I thought this might work, and it does in *some* situations, however in other cases one or the other (or even both) lat and long are out by 180 degrees (and when put into the previous equations come out to a point directly opposite to what they should be):
lat = atan2(real_y, real_z) lng = atan2(real_x, real_z)
Any thoughts? Math is really not my strong point.