A general theory of the kinematics and geometry of gears in three