Some time ago, I was trying to move a camera (in 3D space) around the player, which ultimately is about moving an object around a sphere.

Now, the equation for the position around a circle is pretty easy and is:

1 2 |
x = circleCenter.x + cos(angle) * circleRadius; y = circleCenter.y + sin(angle) * circleRadius; |

However, I needed equations to find the position over a sphere.

After some research with Google, I came with this solution:

1 2 3 |
x = sphereCenter.x + cos(angleInY) * sphereRadius * cos(angleInX); y = sphereCenter.y + sin(angleInX) * sphereRadius; z = sphereCenter.z + sin(angleInY) * sphereRadius * cos(angleInX); |

While writting this post, I payed a quick visit to this article in Wikipedia and, according to them, these are the formulas:

1 2 3 |
x = sphereCenter.x + sin(angleInX) * sphereRadius * cos(angleInY); y = sphereCenter.y + cos(angleInX) * sphereRadius; z = sphereCenter.z + sin(angleInX) * sphereRadius * sin(angleInY); |

#### Observations:

*angleInX*is the angle around the X axis.*angleInY*is the angle around the Y axis.*sphereCenter*that has at least 3 elements and defines the position of the object we will be moving around. And so, theVector.x is the x attribute of the vector theVector, for example.

I needed to change the formulas from Wikipedia, as they work with the Z-axis as the “upward” axis, while I use the Y-axis instead.

I hope this will be handy to anyone trying to figure out how to move over a sphere.