I would like a series of objects to behave in similar manner to a series of connected gears.

This means that each black object in the diagram below will rotate at a speed based on the ratio of their radius compared to their parent's radius.

Circles act like gears

The problem is how can I determine a sensible parent child hierarchy algorithmically?

Is there a tried and tested mathematical procedure for such a task?

  • 4
    \$\begingroup\$ There are no parents or children - only neighbors. One real challenge here is that you might be able to map what's touching what, but the issue is deciding if it's actually a feasible configuration. You might find that a gear has two neighbors, both of which are moving. The two neighbors have to apply a matching action onto the shared gear - ie, both making it spin at the same speed, and in the same direction. \$\endgroup\$
    – Tim Holt
    Commented Aug 1, 2014 at 21:25

3 Answers 3


Let's consider three gears: \$G_1\$, \$G_2\$ and \$G_3\$.

Now each gear has a given radius \$r_1\$, \$r_2\$ and \$r_3\$. The problem is to find the angular velocity for each gear (denoted \$\omega_1\$, \$\omega_2\$ and \$\omega_3\$). From a physics course we know that the tangent velocity v is proportional to the radius: \$v_1 = \omega_1 r_1\$.

Now, if a given gear, say \$G_1\$, is connected to a second gear \$G_2\$, then the tangent velocities match: \$v_1=v_2=v\$, where \$v\$ is the overall velocity of the system, a global parameter for a system of connected gears.

Now it follows that \$\omega_1r_1 = v\$ so \$\omega_1 = \frac{v}{r_1}\$ for each gear. That way you can find out the angular velocity of all gears in a system.

The next step is finding the rotation direction. For this, simply choose a gear (say G_1), fix the rotation direction (say to \$+\omega_1\$), look which gears are connected to it. If \$G_2\$ is connected to it, its angular velocity is \$-\omega_2\$.

There is still the problem of the clinch situation:

For small-scale problems I would advise to simply do this gear-wise for all gears: Then, if for any gear you want to set a different direction than already set - set all angular velocity values (or the system velocity) to 0 - the system is "jammed"!

You simply do this for each set of connected gears.

Its not a very sophisticated method to do this but I think it should work. :-)

One more comment: you can easily save the gear structure in the so-called "adjacency matrix". It is a matrix that is 1, if gear i is connected to gear j and 0 otherwise. As an example, take the 3x3 matrix consisting of only ones - where each of three gears is connected to the other - it represents a jammed system! In your scripts, use the adjacency matrix to write the script that determines the rotation directions!


You might be using a net-like structure, where each gear knows about all gears it is in contact with.

When you need to apply a rotation, you pick a master gear that you start with and recursively rotate all its neighbors.

If you want an algorithm to find a master gear - there's really none. You just pick gears that has only one neighbor and choose one of them (e.g. by it's size or net distance from other gears).

Note, that you need to deal with clinch situations, when you have three gears interlocking each other.

  • 1
    \$\begingroup\$ If you want an algorithm to find a master gear - there's really none. This is what I was having issues with to begin with. Now that I have abandoned the idea that one can be found, it makes the solution much easier to attain. \$\endgroup\$ Commented Sep 2, 2014 at 18:54

This seems like a standard engineering problem. It is definitely possible to determine the rotations of all gears, even with multiple drivers. Read up on Gear Trains. If this is a big part of your work, it might be worth picking up a book on engineering dynamics. Good luck!

  • \$\begingroup\$ This does not seem to answer the question. It would be better to prove that it is possible to solve the system, rather than simply declaring it to be so. Also, the information from your link that you believe to be relevant should be included in your answer with citation, see gamedev.stackexchange.com/help/referencing. \$\endgroup\$ Commented Nov 3, 2014 at 6:17

You must log in to answer this question.

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