17

I'm plotting gear curves, and I observe that for some parameter values ParametricPlot[] does not plot all the teeth:

gearCurve[a_, b_, n_] := ParametricPlot[
  {
    (a + 1/b Tanh[b Sin[n t]]) Cos[t], 
    (a + 1/b Tanh[b Sin[n t]]) Sin[t]
  }, 
  {t, 0, 2 Pi}, 
  Axes -> False];
  gearCurve[10, 5, 38]

produces the following image:

problematic gear

What is going on?

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
Victor K.
  • 5,146
  • 3
  • 21
  • 34

3 Answers3

25

Yaroslav Bulatov posted a great answer addressing this problem on StackOverflow.

Among several good illustrations the answer includes this undocumented option:

Method -> {Refinement -> {ControlValue -> (*radians*) }}

Alexey Popkov also gave an excellent analysis of the Plot algorithm.

His answer includes the apparently equivalent but cleaner (in degrees rather than radians as above):

Method-> {MaxBend -> (*degrees*) }

Example:

gearCurve[a_, b_, n_] :=
  ParametricPlot[
    {(a + 1/b Tanh[b Sin[n t]]) Cos[t],
     (a + 1/b Tanh[b Sin[n t]]) Sin[t]},
    {t, 0, 2 Pi},
    Axes -> False,
    Method-> {MaxBend -> 1}
  ];

gearCurve[10, 5, 38]

Mathematica graphics

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
16

Sorry, the engineer inside couldn't resist

enter image description here

Edit

Here is the code:

gearCurve[a_, b_, n_, c_, h_] := 
  ParametricPlot[{c + (a + 1/b Tanh[b Sin[n t + h]]) Cos[t + h], 
                      (a + 1/b Tanh[b Sin[n t + h]]) Sin[t + h]}, {t, 0, 2 Pi}, 
   Axes -> False, 
   Method -> {Refinement -> {ControlValue -> 1 Degree}}];

Animate[Show[gearCurve[10, 5, 38, 0, h], gearCurve[10, 5, 38, 20, -h],
             PlotRange -> {{-10, 30}, {-10, 10}}], {h, 0, 2 Pi, .01}, 
             DisplayAllSteps -> True]
Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
15

Just need to bump up PlotPoints...

gearCurve[a_, b_, n_] := 
  ParametricPlot[{(a + 1/b Tanh[b Sin[n t]]) Cos[
  t], (a + 1/b Tanh[b Sin[n t]]) Sin[t]}, {t, 0, 2 Pi}, 
  Axes -> False, PlotPoints -> 100];
gearCurve[10, 5, 38]

enter image description here

JohnD
  • 3,301
  • 3
  • 22
  • 42
  • 1
    If you want to be able to adjust the PlotPoints or other options at will: gearCurve[a_, b_, n_, opts___] := ParametricPlot[{(a + 1/b Tanh[b Sin[n t]]) Cos[t], (a + 1/b Tanh[b Sin[n t]]) Sin[t]}, {t, 0, 2 Pi}, opts, Axes -> False, PlotPoints -> 100]. Better yet, the code is easily compacted: gearCurve[a_, b_, n_, opts___] := PolarPlot[a + 1/b Tanh[b Sin[n t]], {t, 0, 2 Pi}, opts, Axes -> False, PlotPoints -> 100] – J. M.'s missing motivation Jul 19 '12 at 06:08