2
$\begingroup$

I have a program that needs to be done like this:

ParametricPlot[
  equation,
  If[x < 1, {x, 0, t}, {x, t, 2}]]

But Mathematica didn't seem to recognize the values of xmin and xmax in the range of the independent variable x, nor the variable x itself.

The simplest solution, in my opinion, would be to insert If expressions into the range itself, something like this:

ParametricPlot[
  equation,
  {x, If[x < 1, 0, t], If[x >= 1, t, 2]}]

EDIT:

This is why I needed to do this. I needed to paint the curve when $0<t\leq T$, but "delete" it when $T<t\leq2T$

Spirograph

$\endgroup$
9
  • 3
    $\begingroup$ Why don´t you describe what you want to do rather than prescribe something that most likely will not work syntactically? $\endgroup$ – Yves Klett Jan 7 '14 at 12:00
  • $\begingroup$ @YvesKlett The short answer would be why you can't put a variable/function in the plots range position? ParametricPlot[equation,myrangefunction[a,b]]. Being myrangefunction[a_,b_]:={x,a,b} I don't know why that doesn't work. $\endgroup$ – Arcotick Jan 7 '14 at 12:29
  • 1
    $\begingroup$ it will help to post a self contained small complete example than fragments. This way, one can see better what you are trying to do. $\endgroup$ – Nasser Jan 7 '14 at 12:32
  • 1
    $\begingroup$ Didn't recognize or it threw an error? I think it should throw an error because ParametricPlot has the HoldAll attribute that you can read about in the docs, which means it won't evaluate arguments. However, doing it like in your first example and changing it to Evaluate@If[... should work as long as t is defined. $\endgroup$ – C. E. Jan 7 '14 at 12:37
  • 1
    $\begingroup$ The iterator {x,y,z} cannot be changed retroactively as a function of x itself within ParametricPlot. $\endgroup$ – Yves Klett Jan 7 '14 at 13:28
4
$\begingroup$

Some preliminary definitions:

With[{r1 = 2, r2 = 1, 
      c1 = {Cos[#], Sin[#]} &, c2 = {Cos[4 #], Sin[4 #]} &, c3 = {Cos[2 #], -Sin[2 #]} &},
 f1[t_] = (r1 + 2 r2) c1[t] - 0.85 r2 c2[t];
 f2[t_] = r1 c1[t] + 0.85 r2 c3[t];
 ]

A Dynamic solution. The offset 0.0001 is to keep ParametricPlot from complaining and not evaluating. (It does not work if the end points of the domain are the same.) Clip is a convenient way to keep the end points of the domain at the end points of a period.

Column[{
  Manipulator[Dynamic[t0], {0, 4 Pi}],
  Dynamic@
    ParametricPlot[{f1[t], f2[t]},
     {t, Clip[t0 - 2 Pi, {0, 2 Pi - 0.0001}], 
         Clip[t0,        {0.0001, 2 Pi}]},
     PlotStyle -> Lighter@Blue, PlotRange -> 5]
  }]

Mathematica graphics

An animation. First the frames:

movie = Table[
   ParametricPlot[{f1[t], f2[t]},
     {t, Clip[t0 - 2 Pi, {0, 2 Pi - 0.0001}], 
         Clip[t0,        {0.0001, 2 Pi}]},
     PlotStyle -> Lighter@Blue, PlotRange -> 5],
   {t0, 0, 4 Pi, 2 Pi / 50}];

Then ListAnimate[movie] or Export["foo.gif", movie]:

Export["foo", movie]

$\endgroup$
3
  • $\begingroup$ +1, I know it's tangent to the problem in the OP but since I went at it for a while with a set of equations that produced a very similar result as this, but not quite, could you hint as to how you found those equations? Ty. $\endgroup$ – C. E. Jan 8 '14 at 16:25
  • $\begingroup$ @Anon They are an epicycloid and a hypocycloid, with the traced point on the rolling wheel set slightly inside the rim (0.85 r2). $\endgroup$ – Michael E2 Jan 8 '14 at 16:51
  • $\begingroup$ @MichaelE2 Actually it's .8 but that's good enough ;) $\endgroup$ – Arcotick Jan 8 '14 at 21:00
3
$\begingroup$

I am guessing, but perhaps the OP is looking for something like this.

With[{t = .9},
  Module[{range},
    range = If[t < 1., {x, 0., t}, {x, t, 2.}];
    ParametricPlot[{x, .5 x}, Evaluate@range, 
      PlotRange -> {{0, 2}, {0, 1}}]]]

left-plot.png

With[{t = 1.1},
  Module[{range},
    range = If[t < 1., {x, 0., t}, {x, t, 2.}];
    ParametricPlot[{x, .5 x}, Evaluate@range, 
      PlotRange -> {{0, 2}, {0, 1}}]]]

right-plot.png

Update

Now that I hae a better understanding of what you want, I suggest you get the effect by controlling the coloring of the curve, rather than by adjusting its range. Here is an example.

Manipulate[
  ParametricPlot[{Cos[t], Sin[t]}, {t, 0, tt},
    PlotRange -> {{-1, 1}, {-1, 1}},
    PlotStyle -> {Thick},
    ColorFunction -> (If[#3 > 2 π, White, Black] &),
    ColorFunctionScaling -> False],
    {tt, .1, 4 π, .1, Appearance -> "Labeled"}]

circle.png

$\endgroup$
1
  • $\begingroup$ Some black points can be seen on the white part. I knew I could make it with colors, and also putting a white function in top of the blue one, but I don't see this as a good resolution, what if some other plots are under this curve? $\endgroup$ – Arcotick Jan 8 '14 at 23:28

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.