View Full Version : Vertex to Spherical

08-31-2004, 11:18 AM
I was working on a cute little project in OpenGL:ES and came accross something I didn't knwo how to do. :(

How can you convert a vertex to spherical coordinates? (ie. longtitude, latitude)

I'm looking for a simple way as the target platform only has limited RAM :(

Does someone know anything about this sort of stuff?
Is it even possible?

Later! ;)

08-31-2004, 11:28 AM
Do a search for geotrans or read about elliptical integrals, trans mercator, wgs84, lambert etc. My guess is that you want to do some kind of transformation between a "flat" cartesian coordinate system and a spherical coordinate system like wgs84 etc.

08-31-2004, 01:35 PM
Thanks for the reply! :)

What you suggested is way over my head. :(
Too much math involved :p

I have some code that should do what I want, but it's a bit bulky and I'm sure there are easier ways.
Here it is;

longitude = atan2(-x, z);
latitude = atan(y / sqrt(x*x + z*z));

longitude = 1.0 - longitude / (2*PI);
latitude = fabs(0.5 - latitude / PI);You could use the longitude and latitude as U and V texture coordinates.

But the above code weighs a lot! :(
5 K of code is added, and it's not that fast so it may need to be inlined. And I'm aiming for cellphone platforms with OpenGL:ES.

I know my way is the naive way of doing it, and there must be a better way, that only uses acos() and cos() which is ok because I allready use them in the code and they are fast.

Anything other way of doing it would be better than mine :)