Latitude and Longitude on Globe

Hello, I am working on a project in which I need to obtain the latitude and longitude coordinates on a globe. This is how I am currently finding these coordinates:

float lat = Mathf.Acos((hit.point.y)/((Mathf.Sqrt((radius^2)+(Mathf.Pow(hit.point.y, 2))))));
float long = Mathf.Atan2(hit.point.x,hit.point.z);

I think this may be correct to an extent, however, I am also hoping to take into account the rotation of the sphere. Users are able to rotate the globe in any direction so we would like to get the proper coordinates for where they end up. For example, if you clicked on North America (Florida) right now, you would get 29 latitude and -81 longitude. Then, when rotating to Australia, clicking on the same point on the screen, you would again get 29 and -81. Instead, I would like for the click on Australia to get -25 and 125, as it should be on a real globe. Does anyone have any advice on this?

Your calculations are in world space which’ll need to be transformed for rotation. You can do this with Transform.InverseTransformPoint (which’ll also account for translation);

var localPoint = Globe.transform.InverseTransformPoint(hit.point);
var latitude = Mathf.Asin(localPoint.y * 2f) * Mathf.Rad2Deg;
var longitude = Mathf.Atan2(localPoint.x, -localPoint.z) * Mathf.Rad2Deg;

We should perhaps change this sub-forum topic to be Physics & Math too. :wink: