# How can you calculate the angle required to line up the teeth of cogs if you know all their attributes

Cog $A$ is at position: $Ax$, $Ay$, rotation: $Ar$ and number of teeth: $At$

Cog $B$ is at position: $Bx$, $By$ and number of teeth $Bt$. What is Cog $B$'s rotation such that teeth between Cog $A$ and Cog $B$ line up. There will be the same number of answers as there are teeth, but a 'base angle' is desired.

-
Image here: i.imgur.com/ICrhs.jpg – sq2 Jul 15 '12 at 3:50

You can calculate the angle $\alpha$ of the line from $A$ to $B$ as $\alpha=\arctan\frac{By-Ay}{Bx-Ax}$. You want the phases to be opposite at this angle, so $(\alpha-Ar)At=(\alpha+\pi-Br)Bt+\pi+ 2\pi n$, with $n$ an integer; you can solve this for $Br$ to determine $Br$ up to integer multiples of $2\pi/Bt$.

-
@sq2: Then it would be great if you'd write it up as an answer; then your question wouldn't remain unanswered, and we could compare our solutions. – joriki Jul 17 '12 at 11:41

The solution I have found, which may be @joriki's solution expressed in a different format:

Angle α is of course required, see @joriki's solution.

Br = At / Bt * -Ar + α * (At + Bt) / Bt

and if Bt is even, add π / Bt to Br

-
Here's proof: esquemedia.com/experiments/gears – sq2 Jul 17 '12 at 12:21