views:

746

answers:

1

I have a set of latitude and longitude co-ordinates which are to be rendered in a GL program I'm working on. I have information such as the number of units per latitude and longitude degree (I have the co-ordinates in decimal degrees, eg, 27.1234) - for example, 15 units per longitude, and 10 units per latitude. However, I've had problems with rendering.

This calculation gives me locations I can use for rendering, but it's not perfect. I initially tested only with co-ordinates such as S026.33.01.806 E148.46.27.009, and when I switched to co-ordinates such as N039.52.19.030 W075.14.28.107 the rendering ended up upside-down and horizontally flipped.

It may be a fundamental lack of understanding of OpenGL and how it interprets co-ordinates, or perhaps I'm approaching the problem the wrong way. I'm using Python and PyOpenGL, but I presume this algorithm is something that can be done without a specific language requirement.

EDIT: I have uploaded the code that seems to be most relevant to http://slexy.org/view/s21LKiD9tj.

+2  A: 

Erm, the number of units for longitude is not constant? What strange kind of conversion function are you using?

Assuming the earth to be spherical with radius r, centered in the root of the coordinate system, with z-axis pointing north, x-axis pointing towards longitude 0, and y-axis pointing towards longitude 90, you can get cartesian coordinates as follows:

x = r * cos(latitude) * cos(longitude);
y = r * cos(latitude) * sin(longitude);
z = r * sin(latitude);

Note: If your language's trigonometric functions expect the arguments to be specified in radians rather than degrees, be sure to convert them first.

meriton