Given a flat (equarectangilar panoramic) image of for instance 6000px x 3000px (spreading 360 degrees wide and 180 degree high). How would I translate for instance x = -10, y=-10 to spherical coordinates (pan/tilt or vertical/horizontal offset) where the center of the image would mean a horizontal/vertical offset of 0?
Is it possible to calculate this, or do you need other variables like the radius, distance or z coordinate?
Edit: What I have so far:
def self.translate_xy_to_spherical(x, y)
h = (x / (6000 / 360)) - 180
v = ((y / (3000 / 180)) - 90) / - 1
[h, v]
end
def self.translate_spherical_to_xy(h, v)
x = ((h + 180) * (6000 / 360))
y = ((v * -1) + 90) * (3000/ 180)
[x, y]
end
If I put in 0,0 in the first method, I get -180,90 which is correct. But if I set 3000,0 I'd expect 0,90 but I get 7,90. Same goes with the other formula (xy to spherical). When I input 0,0 I'd expect 3000,1500 but I get 2880x1440px. There is a small offset, probally because I calculate in a straight line.
Update: The Answer
I've updated the answer from below to take in account that degrees could be bigger than 360 degrees. I use the modulo to fix this:
IMAGE_WIDTH = 6000
IMAGE_HEIGHT = 3000
def self.translate_xy_to_spherical(x, y)
h = (x / (IMAGE_WIDTH / 360.0)) - 180
v = ((y / (IMAGE_HEIGHT / 180.0)) - 90) / -1
[h, v]
end
def self.translate_spherical_to_xy(h, v)
x = (((h % 360) + 180) * (IMAGE_WIDTH / 360.0))
y = (((v % 180) * -1) + 90) * (IMAGE_HEIGHT/ 180.0)
[x, y]
end