5
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – Keith Feb 9 '15 at 18:34
6
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – Keith Feb 9 '15 at 21:24
  • 1
    $\begingroup$ @Keith like Rotate[First@gear[], theta]? $\endgroup$ – Kuba Feb 9 '15 at 21:28
3
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.