This may be out of focus for GD.se but i will try to birefly explain this.
There are several kinds of gear functions. The most common being the involute of a circle and the cycloid. In principle you could generate a corresponding gear shape pair for nearly any shape but in practice involute has superior properties for misalignment. This is because the pair of a circle involute is a circle involute.
The most common gear shape.
Involute gears are by far most common. The involute shape is simply the sum of 2 vectors. Vector one is rotating along the base circle that the curve is the involute of. Vector 2 is perpendicular to this vector and is the length of how far has been traveled on the base circle.
Image 1: Formation of the involute shape.
This in mathematical parametric terms forms a function for x and y as for example as follows, you get the following parametric function:
x = r * sin(t) - r * t * cos(t)
y = r * cos(t) + r * t * sin(t)
Where t is the angle in radians and r is the radius
(If you graph 0 to - Pi/2 you get the same image). Okay but this sin itself is not enough. As you need to calculate the shift and size for the mirror of this curve to get the teeth aligned. But this was a very short version of my introductory lecture on the subject. In any case pick a book on mechanical engineering for the really gritty details.
As it is now i think this over exceeds the purpose of this exchange. But before i part ways ill leave a hint on how to plot the curve in with adobe tools in form of a plotting routine for Photoshop (could be easily changed for illustrator). See this post:
Trace equation of line in Photoshop