1
\$\begingroup\$

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?

\$\endgroup\$
2

1 Answer 1

2
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ How can I generate a random rotation matrix? Thanks \$\endgroup\$
    – lacas
    Commented Mar 11, 2014 at 18:22
  • \$\begingroup\$ 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. \$\endgroup\$
    – ggambetta
    Commented Mar 13, 2014 at 15:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .