c# – Displaying a coordinate grid and markers on the globe in Unity

Please help me with the Earth model in Unity. I don’t understand what’s wrong.
I downloaded the blue marble texture from the NASA website, attached it to a Material, and placed it on a sphere.
I want to display a coordinate grid on the globe and add markers. I created a prefab for the marker and a material for the parallel and meridian lines.
Coordinate transformations:

  public static (float lat, float lon) XYZToLatLon(Vector3 point, float radius)

{
    Vector3 normalized = point.normalized;

     float lat = Mathf.Asin(normalized.y) * Mathf.Rad2Deg;
    
        float lon = Mathf.Atan2(point.z, point.x) * Mathf.Rad2Deg;
    
        if (lon > 180f) lon -= 360f;
        if (lon < -180f) lon += 360f;
    
        return (lat, lon);

}
public static Vector3 LatLonToXYZ(float lat, float lon, float radius)
{
    float latRad = Mathf.Deg2Rad * lat;
    float lonRad = Mathf.Deg2Rad * lon;

    float x = radius * Mathf.Cos(latRad) * Mathf.Cos(lonRad);
    float z = radius * Mathf.Cos(latRad) * Mathf.Sin(lonRad);
    float y = radius * Mathf.Sin(latRad);

    return new Vector3(x, y, z);
}

But I’m getting a clearly incorrect display. For example, Ireland is located above the 60th parallel, and placing a marker there yields coordinates of (62; – 8). There is an error of almost 10 degrees, although the marker at 0;0 is displayed correctly.

enter image description here

What is this connected with, what did I do wrong?

Read more here: Source link