8
$\begingroup$

Suppose I want to look at the region defined by the conditions

\begin{align}x\leq y && x<2\\\text{OR}\quad x\geq y&& x\geq2 \end{align}

I plot this using the command

RegionPlot[x <= y  && x < 2 || x >= y && x >= 2, {x, 0, 5}, {y, 0, 5}]

which gives the image below.

Why does this image look the way it does at x=2,y=2, and how can I fix it?

More specifically, I think the regions should only intersect at a point, and should form like a "tilted X". But where the lines cross there is some "width"?

Region plot with OR

$\endgroup$
  • 2
    $\begingroup$ use the options PlotPoints or MaxRecursion or both , e.g., PlotPoints -> 100], and/or MaxRecursion -> 7? $\endgroup$ – kglr May 21 '18 at 20:26
  • $\begingroup$ @kglr that indeed fixes it (plotpoints does. Didn't check max recursion). Thank you. $\endgroup$ – user106860 May 21 '18 at 20:30
6
$\begingroup$

See Specific initial sample points for 3D plots for some discussion of following form of PlotPoints. Basically throw a point into the offending area and increase MaxRecursion (default value is 2), if needed. If you follow the linked Q&A, you'll realize this approach has a good chance to succeed and a still significant chance that it will fail. It succeeds here if we raise MaxRecursion to 3:

RegionPlot[x <= y && x < 2 || x >= y && x >= 2, {x, 0, 5}, {y, 0, 5}, 
 MaxRecursion -> 3, PlotPoints -> {Automatic, {{2.001, 2.01}}}]

Mathematica graphics

$\endgroup$
  • 2
    $\begingroup$ (+1) I never knew of this extended syntax for PlotPoints! $\endgroup$ – Chip Hurst May 21 '18 at 23:24
7
$\begingroup$

It looks like the default discretization method gives the desired singular vertex:

reg = ImplicitRegion[x <= y && x < 2 || x >= y && x >= 2, {{x, 0, 5}, {y, 0, 5}}];
mesh = BoundaryDiscretizeRegion[reg, Frame -> True]

enter image description here

We can verify this by highlighting the vertices:

HighlightMesh[mesh, Style[0, Red]]

enter image description here

$\endgroup$
1
$\begingroup$

As pointed out in a comment, I can fix it by specifying

PlotPoints ->100

and/or

MaxRecursion-> 7

I guess I just didn't/don't understand how the command worked. I looked at the details of the command and I believe the follows two comments are helpful

  • RegionPlot initially evaluates pred at a grid of equally spaced sample points specified by PlotPoints. Then it uses an adaptive algorithm to subdivide at most MaxRecursion times, attempting to find the boundaries of all regions in which pred is True.
  • You should realize that since it uses only a finite number of sample points, it is possible for RegionPlot to miss regions in which pred is True. To check your results, you should try increasing the settings for PlotPoints and MaxRecursion.
$\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.