Coordinate conversion and sphere mapping.

Hey,

I have some issues with mapping converted coordinates to a sphere. I’m using libnoiseforjava and the jMonkeyEngine.
First my conversion methode:

	public Vector2f cartesianToGeo(Vector3f position, float sphereRadius)
	{
	        sphereRadius = FastMath.sqrt((position.x*position.x)+(position.y*position.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:

   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):


http://img685.imageshack.us/img685/392/sphere.jpg

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:

Greetings

JCollie

What are you trying to do?

I want to map noise to a sphere. (The module.getValue(x, y, z) method in the mapping method refers to a perlin noise. This function should be fine)

If you’re not trying to “warp” noise, then simply sample in cartesian space. If you want to correct for imperfect spheres (because of tris) then a normalization map will do…or simply compute the correction in the shader.

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?!