Vertex to Spherical

I was working on a cute little project in OpenGL:ES and came accross something I didn’t knwo how to do. :frowning:

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 :frowning:

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

Later! :wink:

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.

Thanks for the reply! :slight_smile:

What you suggested is way over my head. :frowning:
Too much math involved :stuck_out_tongue:

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! :frowning:
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 :slight_smile: