Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How can I move an object on a random orbital path around a sphere?

I've created some objects at an initial position that is essentially a random point on the sphere offset by some distance (say, 10.0).

Now I want to choose a random direction and have the object orbit the sphere in that direction. How can I accomplish that?

share|improve this question
2  
Are you able to move the object in a non-random direction around the sphere? As in, is the problem selecting a random direction or having the object orbit a sphere? –  Byte56 Feb 26 at 17:47
    

1 Answer 1

up vote 2 down vote accepted

First generate a random 3D rotation matrix. Then for each frame compute a simple, boring rotation vector around the center (e.g x = r*cos(k*t), y = r*sin(k*t), z = 0), multiply it by the rotation matrix, add it to the center of the sphere, and you have a random orbit.

share|improve this answer
    
How can I generate a random rotation matrix? Thanks –  lacas Mar 11 at 18:22
    
Create two different, normal, random 3D vectors A and B. Compute C = AxB; C should be perpendicular to the plane defined by A and B. Now compute B' = AxC. A, B' and C should be orthonormal, so you can use them as the columns of a matrix and it will be a rotation matrix. –  ggambett Mar 13 at 15:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.