# From Spherical To ellipsoid coordinates

Hi everyone, just few questions about coordinate in unity, i’m working on a project to represent the earth, we were working on a spherical earth and we put objects on it thanks to those lines :

At the last line, we multiply the coordinate of our objects by the radius of our earth to put the object on the surface.

But now, we are moving from spherical earth to ellipsoidale earth, so, i have not one radius but three radius, and i have no idea about how to change the last line to make it works, any ideas?

Thanks.

If I understand the question correctly, could this be the answer: Geodetic coordinates - Wikipedia?

2 Likes

I’m not sure that’s what i want, i don’t think so, my question is : to place my object in my scene, i multiply my x,y,z coordinate by the radius ( because i have a spherical earth), and now, i have an ellipsoidale one, so, do i have to multiply my x coordinate by the x radius, same for y and z ??

I think you need to you need to use the formula from the “Conversion” section. In there, your latitude is noted as φ and your longitude as λ. h is the height above the ellipsoid’s surface and a and b are the equatorial radii.

For the WGS84 ellipsoid model, the values are:
a = 6,378,137 meters
b = 6,356,752.3142 meters

1 Like

Thanks you for all this information, the problem is, i have no idea about my h value, moreover, if i have my new X , Y and Z with those equations, in line 30 i replace x by xX, y by yY etc ?

Because the thing is i multiply by radius in my code with spherical earth so im quite lost here …

To go from latitude / longitude to points on a sphere or ellipsoid:

See the expression starting on line 65 above:

``````Vector3 sphericalPoint = new Vector3 (
Mathf.Cos (longitude) *
Mathf.Cos( latitude) * dimensions.x,
Mathf.Sin( latitude) * dimensions.y,
Mathf.Sin (longitude) *
Mathf.Cos( latitude) * dimensions.z);
``````

In the above case obviously latitude and longitude are in radians, not degrees.

To make it not a sphere but an ellipsoid, make the `dimensions` vector non-uniform.

Thanks for the answer but i already have all the sphere part in my code and it works perfectly in my spherical earth, but to go into ellipsoidale mode i have 3 radius, so what do i have to change? this is my code :

You’ve already posted an image of code above. Please use code-tags when posting code so devs helping you have access to the text.

Thanks.

1 Like

For (almost) all intents and purposes you can just use the very simple version where you supply an equatorial and a polar radius, and just create a non-uniform scale of your sphere:

`return new Vector3(x*radius_equatorial, y*radius_polar, z*radius_equatorial);`

, and you can take both radii from either the WGS84 or any other model.

If you REALLY need precise geolocation, you’d have to implement the full ellipsoid models, as Augustinas has posted above.

Yes thats what i did :

I will keep that for now but yeah, i would like to be more precise

Np.

So code tags?

1 Like

An alternative and elegant solution would be to grab the vertice positions of the sphere; you check their position. If it goes up on the Y that’s your longitude for each column on the Y emanating from a North Pole circle to a South Pole circle and for each row on the X moving clockwise accounting for left and right hemispheres, this is your latitude.

making a sphere out of circles within circles in your 3D software can help sort the vert list: or else by generating a sphere by code you can also obtain precision. As if you know the vertex point, in order of both column and row if you asked for that vertex latitudes as say 74.5 then you can place the position at the average in-between the 74 and 75 columns vertex positions somewhere on the edge. Even if the sphere was warped into an ellipse it should still return a precise result using the same input. For example Long 32.5 lat 27.25

1 Like

Oh sorry i thought you said i posted the same picture twice, how can i use code tags ?

1 Like

I doubted my advice so I had to test it, but after a quick test, I was able to get the latitude values of rows, but the longitude is more difficult when done this way. But if the sphere was created from multiple 180* vertex arch, which themselves were created in sequential order, or that itself was ordered by height at creation, and then rotated around the pole origin to create the sphere. Then you could have long and lat in the object purely by design. Which may allow for warping.

after making a segmented casing for my sphere, i referenced the segmented casing of my sphere to get the average of the points. This allow me to move a red square around, while a green square highlights my technical V coordinate (they are inactive but static like the above image), the red square calculates the correct LONG and LAT lerp based on my technical V coordinates and their neighbours. for example LAT 16.25, LONG 11.7044

By segmented i mean like this

It is just a carrier of information of the boundary. Each segment is an object unique mesh, with grouped points. I access these points, and use those to lerp the correct coordinate position.

1 Like