0
\$\begingroup\$

I am trying to align a marker sphere to certain places on a bigger Earth sphere based on the inputted latitude and longitude.

The following is my code for this conversion, this code is based on the code here

void createLand()
{
    double radius = radiusEarth / 2;

    double latitude_rad = latitude * Math.PI / 180;
    double longitude_rad = longitude * Math.PI / 180;

    double xPos = (radius * Math.Sin(latitude_rad) * Math.Cos(longitude_rad));
    double yPos = (radius * Math.Cos(latitude_rad));
    double zPos = (radius * Math.Sin(latitude_rad) * Math.Sin(longitude_rad));

    // move ObjectMarker to position
    ObjectMarker.position = new Vector3((float)xPos, (float)yPos, (float)zPos);
} 

radiusEarth = 6371f

I am also using a Mercator projection texture for my Earth object.

Here is what it looks like for the coordinates of London, UK, 51.509865, -0.118092.

Output for London's coordinates.

As you can see, the marker is in almost the correct position but not quite there.

Here is what it looks like for the coordinates of Chennai, India, 13.067439, 80.237617.

Output for Chennai's coordinates

As you can see here, the marker is completely off, it's been placed somewhere on top of Russia, although it does seem to be directly on top of Chennai.

Is there any way I can fix this and make the marker more accurate?

\$\endgroup\$
2
  • \$\begingroup\$ You have two problems here: one, you're using a spherical coordinate system where a latitude of zero is at a pole instead of the equator. Two, you have not correctly projected your Mercator texture to the sphere's surface, resulting in distorted land masses. \$\endgroup\$
    – DMGregory
    Commented Jan 11, 2020 at 17:27
  • \$\begingroup\$ @DMGregory, is there a way to fix the coordinates system calculation? Also it would be great if you could assist me with how to properly project the texture to the sphere. Thanks. \$\endgroup\$
    – SidS
    Commented Jan 11, 2020 at 19:17

0

You must log in to answer this question.

Browse other questions tagged .