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
Greetings
JCollie