Followers 0

# Spherical to Cartesian conversion

## 2 posts in this topic

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.

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.

0

##### 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.

Edited by Álvaro
1

##### 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!

0

## Create an account

Register a new account