0

I am trying to get the following image to be projected to a sphere using mercator: enter image description here

I have gotten this far using the formula from this : how map 2d grid points (x,y) onto sphere as 3d points (x,y,z)

My code is the following to generate the coordinates from (X,Y):

public void generateSphericalCoords(){
    int R = 400; // Image Radius
    int S = 400; // Sphere Radius

    float longitude = (float)(this.x)/R;
    float latitude = (float) (2*Math.atan(Math.exp((double)(this.y)/R)) - Math.PI/2);
    sphericalX = (int) (S*Math.cos(latitude) * Math.cos(longitude)) + 300;
    sphericalY = (int) (S*Math.cos(latitude) * Math.sin(longitude)) + 300;
    sphericalZ = (int) (S*Math.sin(longitude));
    //System.out.println(sphericalX + " " + sphericalY + " " + sphericalZ);
}

However, instead of getting a perfect sphere, I get this:

enter image description here

What am I doing wrong? Any help would be greatly appreciated.

EDIT:

I have gotten to the following formula:

    float longitude = (float) ((float)(Math.PI*this.x)/R - Math.PI/2);
    float latitude = (float) (Math.PI*2*Math.atan(Math.exp((float)(this.y)/R)));
    sphericalX = (int) (S*Math.cos(latitude) * Math.cos(longitude)) + 300;
    sphericalY = (int) (S*Math.cos(latitude) * Math.sin(longitude)) + 300;
    sphericalZ = (int) (S*Math.sin(longitude));

However, I have gotten an odd ring along the outside edge, as shown:

enter image description here

Community
  • 1
  • 1
Hunter
  • 201
  • 3
  • 17
  • 1
    Shouldn't longitude go from 0 to 2π and latitude from -π/2 to π/2? You're scaling both longitude and latitude between 0 and 1. – biziclop Apr 25 '17 at 23:13
  • Yeah, I guess I am. How would I change my formulas accordingly? I haven't messed around with any cartography or projection. – Hunter Apr 25 '17 at 23:16
  • I haven't either, I'm just thinking about how longitudes and latitudes work on Earth. – biziclop Apr 25 '17 at 23:18
  • Yep. I think that did the trick. Sadly, the image isn't necessarily tileable, so it doesn't mesh well. Thank you. – Hunter Apr 25 '17 at 23:39
  • Yes, in the Mercator projection the top and bottom edges both represent a single point, and thus should be the same colour. And the left and right edges should be joinable. – biziclop Apr 26 '17 at 09:39
  • It looks like you were right, I changed the formula and it started to mesh better. I updated the problem, and you can see where I am at now. – Hunter Apr 26 '17 at 19:45

0 Answers0