# Conditional range in a parametric plot

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$

• Why don´t you describe what you want to do rather than prescribe something that most likely will not work syntactically? – Yves Klett Jan 7 '14 at 12:00
• @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. – Arcotick Jan 7 '14 at 12:29
• 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. – Nasser Jan 7 '14 at 12:32
• 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. – C. E. Jan 7 '14 at 12:37
• The iterator {x,y,z} cannot be changed retroactively as a function of x itself within ParametricPlot. – Yves Klett Jan 7 '14 at 13:28

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]
}]


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]:

• +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. – C. E. Jan 8 '14 at 16:25
• @Anon They are an epicycloid and a hypocycloid, with the traced point on the rolling wheel set slightly inside the rim (0.85 r2). – Michael E2 Jan 8 '14 at 16:51
• @MichaelE2 Actually it's .8 but that's good enough ;) – Arcotick Jan 8 '14 at 21:00

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}}]]]


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}}]]]


### 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"}]


• 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? – Arcotick Jan 8 '14 at 23:28