2

I want to generate figures of regions bounded by pairs of parallel lines. I'm using RegionPlot to do this, but my figures are showing these truncated corners that do not correspond to the regions I'm trying to define. Here is a very basic example:

RegionPlot[-1 < x + y < 1 && -1.5 < x - y < 1.5, {x, -3, 3}, {y, -3, 3}]

Obviously the region defined by these inequalities is a rectangle. But my output is this:

truncated corners?

As you can see, it has these slightly truncated corners. They are sometimes more drastic in other examples of regions that should be parallelograms (are bounded by two pairs of parallel lines).

Is there something wrong with my syntax? Is this a glitch? How do I fix it?

j0equ1nn
  • 278
  • 1
  • 8
  • 2
    Try PlotPoints->100. You need to look at the options associated with the commands. In this case, the more points you plot, the closer you get to an exact solution. – bill s Sep 25 '17 at 01:51
  • @bills Thanks, yes of course I've been looking at the options associated with the commands but it's not always obvious which is the appropriate one, hence seeking help on this forum! – j0equ1nn Sep 25 '17 at 01:57
  • 1
    RegionPlot[-1 < x + y < 1 && -3/2 < x - y < 3/2, {x, -3, 3}, {y, -3, 3}, MaxRecursion -> 5] – Bob Hanlon Sep 25 '17 at 02:08
  • @BobHanlon Thanks, that also helps! I get other weird glitches as I do things more complicated than my example indicates but this gives me hints at when to mess around with. One thing I don't get though is why these answers are posted as comments. Maybe the question is too basic to be worth of an official answer? Should I delete it? – j0equ1nn Sep 25 '17 at 02:27
  • 3
    Information that is easily found in the documentation isn't likely to be of much use to future visitors, so we just reply in the comments. Your question is likely to be closed - please don't be offended, but do try to explore the documentation in future before posting. – bill s Sep 25 '17 at 02:58
  • Okay I understand, but I guess I slightly resent the assumption that I haven't looked at the documentation. It's not like the documentation is searchable by issues such as this, and reading through all the options comprehensively is much more painstaking than checking with experienced users. Maybe it would be good to have a "beginner" tag, so as not to irritate people using the forum for more advanced purposes? – j0equ1nn Sep 25 '17 at 03:26
  • After all I'm likely to ask a lot more dumb questions in the next couple weeks because I just want to generate the figures I need for an article that's almost ready to submit! I do intend to educate myself more fully in the future so as not to be a nuisance. And thanks @bills for your patience with these questions that must be painfully obvious to you. – j0equ1nn Sep 25 '17 at 03:28
  • 2
    Interestingly, I get a nice rectangle when I reduce the plot range, as RegionPlot[-1 < x + y < 1 && -1.5 < x - y < 1.5, {x, -1.5, 1.5}, {y, -1.5, 1.5}]. Szabolcs' answer in other words is that Mathematica doesn't analytically determine that your region is a rectangle. It just samples points on a grid and then draws a bounding box. When your plot range is large compared to your region, it doesn't capture the small features such as sharp corners. I don't have a catch-all solution in general. Sometimes trying an alternative method gives results as good as increasing... – LLlAMnYP Sep 25 '17 at 09:01
  • ...PlotPoints or MaxRecursion, but is better performance wise. However I'm not sure I can name something off the top of my head. – LLlAMnYP Sep 25 '17 at 09:02
  • @j0equ1nn Closing or deleting the question doesn't imply that we were not willing to help you. Many people did. It only implies that should net receive further answers or comments ans maybe is a question that should not be archived long term. Your question will be put on-hold. Don't be discouraged by that cleaning-up policy. Your future good questions are welcome. Learn about common pitfalls here. – rhermans Sep 25 '17 at 15:01
  • @rhermans ok no problem – j0equ1nn Sep 25 '17 at 20:51

1 Answers1

4

RegionPlot samples the plot region on a regular grid, then refines that grid where necessary to improve precision. You can see the grid using the Mesh -> All option.

This method is not good at accurately mapping sharp corners, but you can always increase PlotPoints or MaxRecursion to get a better result.

If you define the region in terms of ImplicitRegion, you can use DiscretizeRegion instead, which has better methods for sharp corners.

reg = ImplicitRegion[-1 < x + y < 1 && -1.5 < x - y < 1.5, {x, y}];

BoundaryDiscretizeRegion[
   reg,
   Method -> #
   ] & /@ {"RegionPlot", "Continuation"}

Mathematica graphics

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263