5

I grabbed the code to render a gear from a Mathematica Demo, but I'm having difficulty reproducing the way it's to be used:

gear[{x_, y_}, n_] := ParametricPlot[{
    {x + (1 + 2 n) Cos[1.5708/n + theta] - Cos[1.5708/n + theta + 2 n theta], 
     y + (1 + 2 n) Sin[1.5708/n + theta] - Sin[1.5708/n + theta + 2 n theta]},   
    {x + (-1 + 2 n) Sin[1.5708 - 4.7124/n - theta] 
                  - Sin[4.7124 - 4.7124/n - theta + 2 n theta], 
     y + (-1 + 2 n) Cos[1.5708 - 4.7124/n - theta]
                  - Cos[4.7124 - 4.7124/n - theta + 2 n theta]}}, 
    {theta, 0, 2 Pi}, 
    PlotPoints -> 101, RegionFunction -> (SquareWave[n #3/6.2832] > 1*^-6 &), 
    Axes -> False]

Then

Graphics[gear[{0, 0}, 20]]

works as expected, but

Graphics[{Thick, gear[{0, 0}, 20]}]

generates the Graphics is not a Graphics primitive or directive error. Is there a way to make this work?

Keith
  • 248
  • 1
  • 7
  • I would now like to be able to rotate my gears, e.g. Rotate[gear[...],theta]. Unfortunately now First simply removes the Rotate. Any suggestions for what will work in this case? – Keith Feb 09 '15 at 18:34

2 Answers2

6

gear produces Graphics so there is not need to add another.

If you want to modify the content you have to take it out:

Graphics[{Thick, First@gear[{0, 0}, 20]}]

Your first example works because it seems Graphics by default flatten Graphics[Graphics[:

Nest[Graphics, Disk[], 5]

to only one.

But your second example is something different, Graphics[{ ..., Graphics and this is not correct syntax.

Kuba
  • 136,707
  • 13
  • 279
  • 740
  • I would now like to be able to rotate my gears, e.g. Rotate[gear[...],theta]. Unfortunately now First only removes the Rotate. Any suggestions for what will work in this case? – Keith Feb 09 '15 at 21:24
  • 1
    @Keith like Rotate[First@gear[], theta]? – Kuba Feb 09 '15 at 21:28
3

Resetting AbsoluteThickness directly also works:

t=4;    
gear[{0, 0}, 20] /. AbsoluteThickness[z_] -> AbsoluteThickness[t]

enter image description here

Choose whatever t you wish, although too large a choice causes the two colors to overlap excessively.

bbgodfrey
  • 61,439
  • 17
  • 89
  • 156