4
$\begingroup$

The Manipulate below produces a path traversing the upper unit semicircle, going from {1,0} at time 0 to {-1,0} at time 1/2, then traversing the same upper semicircle, but in the reverse direction, going back from {-1,0} at time 1/2 to {1,0} at time 1.

However, one cannot "see" the reverse half of the path, since it lies on top of the same semicircle, but traversed in the reverse direction, of the forward half.

Is it possible to use a PlotStyle, or other directive, to change the style of the curve at time 1/2 so that, for example, the plot from then onward is thicker and a different color?

f[t_ /; 0 <= t <= 1/2] := ReIm[Exp[2 \[Pi] I t]]
f[t_ /; 1/2 < t <= 1] := ReIm[Exp[2 \[Pi] I (1 - t)]]

Manipulate[
 ParametricPlot[f[t], {t, 0, v}, 
  PlotRange -> {{-1, 1}, {-1, 1}}], {{v, 0.01}, 0.01, 1}]

(I do realize that there's a way to fake the result I want, namely, by changing the function f on the half-interval {1/2, 1} so as to have a slightly greater radius than 1. But I would much prefer to leave the radius unchanged and "merely" change the style of the curve's thickness and/or color on that half-interval.)

$\endgroup$
1
  • $\begingroup$ The easy solution would be to rename the second definition g and then plot {f[t], g[t]}. $\endgroup$ – C. E. Sep 12 '20 at 17:45
3
$\begingroup$
Clear["Global`*"]

f[t_ /; 0 <= t <= 1/2] := ReIm[Exp[2 \[Pi] I t]]
f[t_ /; 1/2 < t <= 1] := ReIm[Exp[2 \[Pi] I (1 - t)]]

You could use ColorFunction

EDIT:

Manipulate[
 ParametricPlot[f[t], {t, 0, v},
  PlotRange -> {{-1, 1}, {-1, 1}},
  ColorFunction -> (If[#3 < 1/2, Blue, Red] &),
  ColorFunctionScaling -> False],
 {{v, 0.01}, 0.01, 1, 0.01, Appearance -> "Labeled"}]
$\endgroup$
3
  • $\begingroup$ I want constant styling for 0 <= t <= 1/2 and then different constant styling for 1/2 < t <= 1, but in each case, only for the arc currently being traversed. The points in your Manipulate become blue well before t reaches 1/2, so that one cannot see the retracing backwards until around t = 0.6. $\endgroup$ – murray Sep 12 '20 at 19:41
  • $\begingroup$ Exactly what I was after. Thank you! $\endgroup$ – murray Sep 12 '20 at 21:23
  • $\begingroup$ This method, and those in other answers, can be enhanced by including something like: Epilog -> {PointSize[Large], Point[f[v]]} so as to show the moving point tracing out the path. $\endgroup$ – murray Sep 13 '20 at 16:05
3
$\begingroup$

The plot of a single function without singularities will result in a single Line object, which can only a single thickness. To get two thicknesses, you would need to draw two lines. This may or may not be acceptable, since it doesn't look like a single function.

Either

Manipulate[
 ParametricPlot[{
   Style[ConditionalExpression[f[t], t <= 1/2], AbsoluteThickness[1], Blue],
   Style[ConditionalExpression[f[t], t >= 1/2], AbsoluteThickness[3], Red]},
  {t, 0, v},
  PlotRange -> {{-1, 1}, {-1, 1}},
  PlotRangePadding -> Scaled[0.01]],
 {{v, 0.01}, 0.01, 1, 0.01, Appearance -> "Labeled"}]

or

Manipulate[
 ParametricPlot[{
   ConditionalExpression[f[t], t <= 1/2],
   ConditionalExpression[f[t], t >= 1/2]},
  {t, 0, v},
  PlotRange -> {{-1, 1}, {-1, 1}},
  PlotStyle -> {
    Directive[AbsoluteThickness[1], Blue],
    Directive[AbsoluteThickness[3], Red]},
  PlotRangePadding -> Scaled[0.01]],
 {{v, 0.01}, 0.01, 1, 0.01, Appearance -> "Labeled"}]
$\endgroup$
3
  • $\begingroup$ An equally good solution to Bob Hanlon's (mathematica.stackexchange.com/a/230025/148), having only the slight "defect" that it uses the two ConditionalExpression clauses (which is clever, though!). $\endgroup$ – murray Sep 12 '20 at 21:29
  • $\begingroup$ @murray I agree about the two expressions, but I think it's the cleanest way, if not the only way, to get two thicknesses. $\endgroup$ – Michael E2 Sep 12 '20 at 21:40
  • $\begingroup$ @murray Here's another way but I think it's too tricky: Module[{i = 1}, ParametricPlot[ f[t], {t, 0, v}, Exclusions -> t == 1/2, ExclusionsStyle -> Red, PerformanceGoal -> "Quality", PlotRange -> {{-1, 1}, {-1, 1}}, PlotRangePadding -> Scaled[0.01]] /. l_Line :> {{Directive[AbsoluteThickness[1], Blue], Directive[AbsoluteThickness[3], Red], Directive[AbsoluteThickness[3], Red]}[[i++]], l} ] $\endgroup$ – Michael E2 Sep 12 '20 at 21:49
1
$\begingroup$

You can also use MeshFunctions, Mesh and MeshShading options as follows:

Manipulate[ParametricPlot[f[t], {t, 0, v}, 
   MeshFunctions -> {#3 &}, 
   Mesh -> {{1/2}}, 
   MeshStyle -> None, 
   MeshShading -> {Directive[CapForm["Butt"], AbsoluteThickness[7], Blue], 
      Directive[CapForm["Butt"], AbsoluteThickness[4], 
         Dashing[{Large, Medium}], Red]}, 
   PlotRange -> {{-1, 1}, {-1, 1}} 1.1],
 {{v, 0.01}, 0.01, 1}]

enter image description here

Use

MeshShading -> {Directive[AbsoluteThickness[1], Blue], 
     Directive[AbsoluteThickness[7], Dashing[{Large, Medium}], Opacity[.5, Red]]}

to get

enter image description here

$\endgroup$
0
$\begingroup$
f[t_ /; 0 <= t <= 1/2] := ReIm[Exp[2 π I t]]
f[t_ /; 1/2 < t <= 1] := ReIm[Exp[2 π I (1 - t)]]

Manipulate[
 ParametricPlot[f[t], {t, 0, v}, PlotRange -> {{-1, 1}, {-1, 1}}, 
  ColorFunction -> Function[{t}, If[t > 1/4, Blue, Black]], 
  ColorFunctionScaling -> False], {{v, 0.01}, 0.01, 1}]

ParametricPlot with Colorfunction

Manipulate[
 ParametricPlot[f[t], {t, 0, v}, PlotRange -> {{-1, 1}, {-1, 1}}, 
  PlotStyle -> If[v > 1/4, {Blue, Bold}, {Black, Dashed}]], {{v, 
   0.01}, 0.01, 1}]

ParametricPlot with PlotStyle

$\endgroup$
1
  • $\begingroup$ That does not do what I need: at time 1/4 (which should be 1/2, not 1/4), it suddenly changes the entire semicircular arc already traced to the new style! After time 1/2, I only want to see the new style applied to the portion of the arc traced from time 1/2 up to time v. $\endgroup$ – murray Sep 12 '20 at 19:07

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.