I've an equirectangular projection of an image, which I load as a panoramic image where my camera is placed at origin looking at -z. My coordinate system is right handed, i.e x is on right, y is up (north) and z is coming out of screen.
What I want to do is take the selected pixel and convert it to world coordinates xyz.
The formula that I'm using to get the latitude and longitude are:
double centerX = totalWidth/2;
double centerY = totalHeight/2;
double latScaling = centerY / 90;
double lonScaling = centerX / 180;
double longitude = (pixelX-centerX)/lonScaling;
double latitude = -(pixelY-centerY)/latScaling;
totalWidth and totalHeight is the width and height of the equirectangular image and pixelX and pixelY is the selected pixel coordinates.
Further I'm using these lat/long to get the world coordinates as:
double x = sphereRadius * Math.sin(latRadians) * Math.sin(longRadians);
double y = sphereRadius * Math.cos(latRadians);
double z = sphereRadius * Math.cos(longRadians) * Math.sin(latRadians);
sphereRadius is 18 which is equal to the radius of opengl sphere on which the image is finally drawn. The camera is at the origin of this sphere. Please can somebody check if my approach is correct and if the formula's used are correct for a right handed coordinate system.
Using the above formulae I get x=0,y=18,z=0 for latitude = 0 and longitude = 0 which is not expected result. Have I missed something?
EDIT: The formula that seems to be working for me is :
//flip Y axis latRadians = Math.PI/2 - latRadians;
double x = sphereRadius * Math.sin(latRadians) * Math.sin(longRadians);
double y = -sphereRadius * Math.cos(latRadians);
double z = -sphereRadius * Math.sin(latRadians) * Math.cos(longRadians);
But there's still some offset(around 850 pixels) and the deviation is minimum at equator and prime meridian, since it contains the true scale value. I think I need to calculate the offset through angles between up vector and right vector of camera. Can somebody correct me?
There's a flat equirectangular projection of which I take pixel xy position. Then this equirectangular is wrapped on the inside of sphere and my camera is at origin of this sphere. I need to calculate the world co-ordinates from pixel xy. Hope this clarifies some doubts.
sin(lat)
andcos(lat)
. – Dietrich Epp