5
$\begingroup$

I am trying to plot a region defined by an inequality which contains both a 2D square and a 1D segment. My issue is that RegionPlot only shows the square and ignores the line.

I noticed that if I use Reduce on the inequality, the solution is complete and contains the 1D region, and then I can use ImplicitRegion and DiscretizeRegion to visualize it correctly, but my goal is to represent the region in the xy plane with some interactive features.

This is the function I use in the inequality:

 dv[{p1_, p2_}, {x_, y_}] := Piecewise[{
   {Abs[p2 - y], p1 == x},
   {Abs[p2] + Abs[x - p1] + Abs[y], p1 != x}
   }]

This is the interactive RegionPlot which doesn't show the 1D line:

Manipulate[
 DynamicModule[{center = {0, 0}}, 
  LocatorPane[Dynamic[center], Dynamic@RegionPlot[
     dv[center, {x, y}] <= \[Epsilon],
     {x, -10, 10}, {y, -10, 10},
     Sequence[
     Axes -> True, AxesStyle -> Thick, GridLines -> Automatic, 
      BoundaryStyle -> Directive[
Thickness[Medium], Dashed], MaxRecursion -> 3, 
      PerformanceGoal -> "Quality"]
     , ImageSize -> Large]]],
 {\[Epsilon], 0, 10}
 ]

And this is the correct solution given by Reduce, along with its dicretized representation:

sol = Reduce[dv[{1, 3}, {x, y}] < 6, Reals]

(-2 < x < 1 && -2 - x < y < 2 + x) || (x == 1 && -3 < y < 9) || (1 < 
    x < 4 && -4 + x < y < 4 - x)

region = ImplicitRegion[sol, {x, y}];
DiscretizeRegion[region]

enter image description here

I am not an expert in using Mathematica so probably there is an obvious way to fix this. Thanks in advance.

$\endgroup$
4
$\begingroup$
Clear["Global`*"]

dv[{p1_, p2_}, {x_, y_}] := 
 Piecewise[{{Abs[p2 - y], p1 == x}, {Abs[p2] + Abs[x - p1] + Abs[y], 
    p1 != x}}]

Manipulate[
 Module[{sol, region},
  center = Rationalize@center;
  sol = Reduce[dv[center, {x, y}] < Rationalize[\[Epsilon]], Reals];
  region = ImplicitRegion[sol, {x, y}];
  DiscretizeRegion[region,
   PlotRange -> 15,
   Axes -> False,
   Frame -> True,
   GridLines -> Automatic,
   GridLinesStyle -> Red,
   PerformanceGoal -> "Quality",
   ImageSize -> Medium]],
 {{\[Epsilon], 5}, 0, 10, 0.1, Appearance -> "Labeled"},
 {{center, {2, 2}}, Locator}]

enter image description here

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