• Advertisement
Sign in to follow this  

Spherical to Cartesian conversion

This topic is 1842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

 

I am writing a 3D first person game, and i came to a problem with converting spherical coordinates to Cartesian coordinates. The problem is with how I use my axis (which i don't want to change because i got used to them). I know that even Wikipedia gives an example of the conversion, however, I have a slight problem with it.

 

The example on Wikipedia has two angles:

*phi = on the XY plane

*theta = on the ZY plane.

 

Also, the Wikipedia example assumes the X axis is positive backwards, Y axis is positive to the right, and the Z axis is positive up.

 

Reference: http://en.wikipedia.org/wiki/Spherical_coordinates

 

My problem is that my coordinates are as follows:

 

+X = left

+Y = up

+Z = forward

 

And I have two angles:

 

*phi = on the XZ plane

*theta = on the YZ plane.

 

I know it should be simple to figure out how that conversion goes based on the Wikipedia example, but I simply can't visualize it :(

 

Does anyone know how to convert that into Cartesian coordinates?

 

All help is appreciated.

Share this post


Link to post
Share on other sites
Advertisement

I think of the angles as longitude and latitude. The height of a point (its Y coordinate) can be computed from the latitude alone, and it's something like sin(latitude). The other two coordinates will be cos(latitude)*cos(longitude) and cos(latitude)*sin(longitude). Figure out which is which, and perhaps you need to flip a sign, depending on your convention. It should be easy to figure out with those hints.

Edited by Álvaro

Share this post


Link to post
Share on other sites
I think of the angles as longitude and latitude. The height of a point (its Y coordinate) can be computed from the latitude alone, and it's something like sin(latitude). The other two coordinates will be cos(latitude)*cos(longitude) and cos(latitude)*sin(longitude). Figure out which is which, and perhaps you need to flip a sign, depending on your convention. It should be easy to figure out with those hints.

I did this:

X = -cos(theta)*cos(phi)

Y = sin(theta)

Z = cos(theta)*sin(phi)

 

...and it worked! (I had some graphics problems, but that's solved now). Thank you very much!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement