Coordinate conversion and sphere mapping


I have some issues with mapping converted coordinates to a sphere. I’m using libnoiseforjava and the jMonkeyEngine3.

First my conversion methode:

[java] public Vector2f cartesianToGeo(Vector3f position, float sphereRadius)


sphereRadius = FastMath.sqrt((position.xposition.x)+(position.yposition.y)+(position.z*position.z));

float lat = (float)Math.asin(position.z / sphereRadius) * FastMath.RAD_TO_DEG; //theta

float lon = (float)Math.atan2(position.y, position.x) * FastMath.RAD_TO_DEG; //phi

return new Vector2f(lat, lon);


This is the mapping method from libnoiseforjava:

[java] public double getValue (double lat, double lon)


assert (module != null);

double x, y, z;

double r = Math.cos(Math.toRadians(lat));

x = r * Math.cos (Math.toRadians(lon));

y = Math.sin (Math.toRadians(lat));

z = r * Math.sin (Math.toRadians(lon));

return module.getValue (x, y, z);


And here is what I get (using sphere approximation from octahedron):

It looks like two spheres into one another and on the right is the transition between them with a high count of points. My assumption is, that the getValue method expects latitude and longitude in an area from -90 to 90 degrees. My conversion method only returns values from -180 to 180 degrees. That’s probably the reason why I get two spheres. First: does anybody agree? Or is there another mistake? Second: Is there an easy way to also convert the new geo coordinates to an area from -90 to 90 degrees. Or a better method that gives values in this area from the beginning? My math skills kinda suck :slight_smile:



It does look like it is restricted to one side of the axis. Longitude should allow for -180 to 180 degrees. You can always try coordinates all on the positive side or all on the negative side and see what happens.

1 Like

Thanks for your reply.

Interesting, when I restrict the coordinates to either the positive or the negative x-axis, I get a complete sphere (very imperfect though). So I guess the problem really is, that lat and lon have to be from -90 to 90 and not from -180 to 180. So the problem probably lies in the conversion method. That leads to the more or less simple question: Does someone have an idea to improve the cartesianToGeo(Vector3f position, float sphereRadius) method? (The overwriting of the radius was just for testing purposes, should be one anyway.)

On a real sphere, lat will be +90/-90 and lon will be +180/-180. I don’t know if there are specifics to your sphere that make this different.

1 Like

Mistake on my part. You are both absolutely right.

What I found out so far about my problem is that ( I didn’t know that) perlin noise creates negative values. Thats why the two objectes ( it’s actually on object, explanation follows) are into one another. The area with the accumulation of points might be the result of small input values to the perlin noise. So it could be the equator or the zero meridian?!

greetings and thumbs up