Hree
Hree

Reputation: 49

Is it accurate to convert latitude and longitude into 3d coordinate on sphere?

In Unity3d, I Created a sphere and i textured it with Earth texture.

I converted latitude and longitude into 3d coorinates and i spawned a cube on that position. the cube is on sphere but it is not accurate. (for example, when i input "51.504815, -0.128506" for london, the cube is spawned at somewhere in france (44.854302, -0.595576))

i know the earth is not sphere but ellipsoid, and is this affect to result? what should i do to get accurate converting result to spawn cube in right place?

below is converting function that i used, and i used another functions on the web, but it returned same result.

private Vector3 GetSphericalCoordinates(double latitude, double longitude)
{
    latitude = latitude * Math.PI / 180D;
    longitude = longitude * Math.PI / 180D;

    double x = radius * Math.Cos(latitude) * Math.Sin(longitude);
    double y = radius * Math.Sin(latitude);
    double z = -radius * Math.Cos(latitude) * Math.Cos(longitude);

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

and latitude, longitude (0, 0), (90, 0) (0, 90)... is exactly on the quadrant. so i wonder why other lat, lng value is incorrect...

thanks in advance.

Upvotes: 0

Views: 488

Answers (1)

Hree
Hree

Reputation: 49

It was not accurate because of mesh count and texture UV set. if you increase mesh count and make texture's UV correct spawned object will be on correct spot.

Upvotes: 0

Related Questions