Spherical and Cartesian Coordinates
I've been having some trouble converting from spherical to Cartesian coordinates. The program I am working on is a simulation of stars orbitting the center of a galaxy. Now, I'd like the center of the screen to represent the center of the galaxy and for the stars to orbit around that. However, I've had to do weird things to make my orbits look good and I think it's because I don't fully comprehend how 3D space is represented in Processing.
Normally, to get to Cartesian, I'd do something like:
- x = cos(theta)*sin(phi)*r;
- y = sin(theta)*sin(phi)*r;
- z = cos(phi)*r;
But I want to make it relative to the center of the screen and since the axis are positioned different with positive x right, positive y down, and negative z into the screen, I'm confused exactly how to do it.
What sort of offset do I want? How do I make sure that it orbits something in the center of the screen? Are my equations correct?
Any thoughts would be great.