Jump to content

  • Log In with Google      Sign In   
  • Create Account

Spherical to Cartesian conversion


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Madd   Members   -  Reputation: 169

Like
0Likes
Like

Posted 05 January 2013 - 03:18 PM

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.



Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 13368

Like
1Likes
Like

Posted 05 January 2013 - 03:33 PM

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, 05 January 2013 - 03:33 PM.


#3 Madd   Members   -  Reputation: 169

Like
0Likes
Like

Posted 05 January 2013 - 04:03 PM

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!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS