I'm trying to do a game with real time simulations of gears. There is a big Gear with inside a smaller gear.

I managed to draw gears with different diameters but equal size teeth, but if i try to move the smaller one inside the bigger one the movement is odd.

See the animated gif:

The biggest gear is in center C1 and the small in the center C2. I calculate C2 position in this way:

C2.x = C1.x + C1_RADIUS-C2_RADIUS) * cos(t);
C2.y = C1.y - C1_RADIUS-C2_RADIUS) * sin(t);

for t that goes from 0 to TWO_PI in n steps.

I apply as rotation the angle t, but maybe it is wrong and i have to calculate another rotation for get a perfect joint.


I am using radians for rotations and I think this is OK.

My main problem is that I want to achieve a perfect joint between teeth like this example. My teeth are overlapping in some odd way.


a working example can be found here: http://www.openprocessing.org/sketch/83665

  • \$\begingroup\$ I only see the small gear teeth rotating very slowly. But the inner green cross spinning at what looks like the correct speed. Is the main problem getting the drawing of the teeth rotating or finding the correct rotation speed? Common issue to check here is if you're using radians. \$\endgroup\$
    – House
    Dec 12, 2012 at 17:46
  • \$\begingroup\$ i have edited the question a little bit.. \$\endgroup\$
    – nkint
    Dec 12, 2012 at 18:36
  • \$\begingroup\$ It reminds a shader i wrote some time ago : glsl.heroku.com/e#3738.0. what you should take in account here is gear ratio. ratio = number of teeth gear A / number of teeth gear B. use that ratio to scale rotation speed of main gear vs second gear. \$\endgroup\$
    – tigrou
    Dec 12, 2012 at 20:33
  • \$\begingroup\$ Can you please make a new animated GIF when your problem is fixed? Looking at the “wrong” one is so frustrating :-) \$\endgroup\$ Dec 12, 2012 at 21:08
  • \$\begingroup\$ still some problem if the gear is outside. i have found some dirty number to add to try to resolve problem but nothing do to.. if you have some idea.. \$\endgroup\$
    – nkint
    Dec 17, 2012 at 16:16

1 Answer 1


The large gear has circumference 2πR1 and the small one has circumference 2πR2, so when the small gear has made a full circle, it has turned R1/R2 times around itself, minus one time because it turned inside the large gear (it would be plus one if the gear was outside).

So when the centre of the inner gear is rotated by angle t, the gear itself needs to be rotated by angle (R1/R2-1)t.

If the values you handle are tooth counts N1 and N2 you can replace R1/R2 with N1/N2.

There is also the issue of the initial rotation. Let a be the angle value atan2(C2.y - C1.y, C2.x - C1.x). Apply initial rotation a to gear 1. If gear 2 is inside, apply rotation a to it, too. If gear 2 is outside, apply a π+a+h rotation where h = π/(2*N2) is the half angle of a tooth.

  • \$\begingroup\$ thanks. this did the trick perfectly. can you give me more information on how to find this formula? \$\endgroup\$
    – nkint
    Dec 12, 2012 at 21:00
  • 2
    \$\begingroup\$ I must admit my knowledge of gear mathematics only comes from 30 years of playing with Legos. If I come across a meaningful resource I will add it to my answer. \$\endgroup\$ Dec 12, 2012 at 21:11
  • \$\begingroup\$ @nkint It is the number of teeth that counts. You can just replace the radius ratio R1/R2 with the tooth count ration N1/N2. \$\endgroup\$ Dec 13, 2012 at 13:21
  • \$\begingroup\$ ok perfect, thanks, now it is more clear. i have googled for "gear ratio" but i don't find anywhere the +1 or -1 for outside/inside \$\endgroup\$
    – nkint
    Dec 13, 2012 at 13:22
  • \$\begingroup\$ tue to the fact that there are still some problems i unchecked the correct answer.. and i have upload all the code, maybe someone one day will have a look to the last unresolved problem! \$\endgroup\$
    – nkint
    Dec 17, 2012 at 16:18

You must log in to answer this question.

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