3
$\begingroup$

I have a curve that have some unwanted parts. How can I remove them ? Or how to constraint the curve to a specific region ?

Here's a MWE that shows the problem :

t[tau_, v_, g_] := (Sinh[g tau + ArcTanh[v]] - Sinh[ArcTanh[v]])/g
x[tau_, v_, g_] := (Cosh[g tau + ArcTanh[v]] - Cosh[ArcTanh[v]])/g

Chi[t_, x_] := ArcTan[t + x] - ArcTan[t - x]
Eta[t_, x_] := ArcTan[t + x] + ArcTan[t - x]

curve[v_, g_] := ParametricPlot[
    {Chi[t[tau, v, g], x[tau, v, g]], Eta[t[tau, v, g], x[tau, v, g]]},
    {tau, -50, 50},
    PlotRange -> All
    ]

Show[curve[0.5, 2],
    PlotRange -> {{-Pi, Pi}, {-Pi, Pi}}, 
    Frame -> True]

Preview :

curve

The interesting part of that curve is inside the region delimited by a simple square losange, with corners at {-Pi, 0}, {0, -Pi}, {Pi, 0}and {0, Pi}.

So how can we draw the parts contained in that region only ?

$\endgroup$
  • $\begingroup$ Maybe do instead {tau, -3, 3}. $\endgroup$ – march Apr 22 '16 at 15:54
  • $\begingroup$ Use in your curve function {tau, -10, 9.5} instead of {tau, -50, 50}. $\endgroup$ – demm Apr 22 '16 at 15:56
  • $\begingroup$ Well, this would be specific to the values used for v and g, wouldn't ? I need something more general, for all values of those parameters. $\endgroup$ – Cham Apr 22 '16 at 16:01
3
$\begingroup$
curve[v_, g_] := ParametricPlot[{Chi[t[tau, v, g], x[tau, v, g]], 
   Eta[t[tau, v, g], x[tau, v, g]]}, {tau, -50, 50}, PlotRange -> All,
  RegionFunction -> Function[{x, y, u}, Norm[{x, y}, 1] < .99999 Pi]]

Show[RegionPlot[Norm[{x, y}, 1] <= Pi, {x, -Pi, Pi}, {y, -Pi, Pi}], 
 curve[0.5, 2], PlotRange -> {{-Pi, Pi}, {-Pi, Pi}}, Frame -> True]

Mathematica graphics

Show[RegionPlot[Norm[{x, y}, 1] <= Pi, {x, -Pi, Pi}, {y, -Pi, Pi}], 
 curve[.5, -4], PlotRange -> {{-Pi, Pi}, {-Pi, Pi}}, Frame -> True]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Wow ! That solution works very well. Please, could you explain what the Function[{x, y, u}, Norm[{x, y}, 1] < .99999 Pi] is doing ? $\endgroup$ – Cham Apr 22 '16 at 23:03
  • $\begingroup$ @Cham, Your diamond is the region where 1-norm is equal to Pi, i.e., the region where Norm[{x,y},1] ==Pi. So, the specified RegionFunction is restricting the plotting region to {x,y} values with 1-norm less than Pi. $\endgroup$ – kglr Apr 22 '16 at 23:12
  • $\begingroup$ I'm not sure to understand. What is a 1-norm ? Norm[{x, y}] = Sqrt[x^2 + y^2], isn't ? Then what is Norm[{x, y}, 1] ? $\endgroup$ – Cham Apr 22 '16 at 23:14
  • $\begingroup$ Also, what is the u variable, in your {x, y, u} ? $\endgroup$ – Cham Apr 22 '16 at 23:18
  • 1
    $\begingroup$ @Cham, Sqrt[x^2 + y^2] is the 2-Norm. 1-Norm is Norm[{x, y}, 1] =Abs[x] + Abs[y] (see Norm>>Neat Examples.) The u the RegionFunction arguments corresponds to the u in ParametricPlot[{fx, fy}, {u, umin, umax}] , that is, it corresponds to tau in your curve function. $\endgroup$ – kglr Apr 22 '16 at 23:33
6
$\begingroup$

Using your definitions, let's derive a RegionMemberFunction that indicates whether a point lies on the boundary of the diamond-shaped region that you want to exclude from plotting:

rmf = RegionMember@DiscretizeRegion@Line[{{-Pi, 0}, {0, -Pi}, {Pi, 0}, {0, Pi}, {-Pi, 0}}];

Notice that the first point must be repeated to obtain a closed line.

Using that region membership function, we can define a new parametric plot including a RegionFunction directive that tests points to plot, and only plots them if they are not on part of that boundary:

Clear[curveLimited]
curveLimited[v_, g_] := 
 ParametricPlot[{Chi[t[tau, v, g], x[tau, v, g]], 
   Eta[t[tau, v, g], x[tau, v, g]]}, {tau, -50, 50}, PlotRange -> All,
   RegionFunction -> (Not[rmf[{#1, #2}]] &)
 ]

Show[
 curveLimited[.5, 2],
 PlotRange -> {{-Pi, Pi}, {-Pi, Pi}}, Frame -> True
]

Mathematica graphics

This works automatically for any value of the plotting parameters:

Show[
 curveLimited[.999, -3],
 PlotRange -> {{-Pi, Pi}, {-Pi, Pi}}, Frame -> True
]

Mathematica graphics

$\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.