Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a region of "thick" grid-lines, like so

GRID = ImplicitRegion[((0 <= x <= 1 || 2 <= x <= 3 || 4 <= x <= 5 || 6 <= x <= 7 || 
   8 <= x <= 9) || (0 <= y <= 1 || 2 <= y <= 3 || 4 <= y <= 5 || 
   6 <= y <= 7 || 8 <= y <= 9)), {{x, 0, 9}, {y, 0, 9}}];

which with RegionPlot[GRID] produces

enter image description here

However, I would like to be able to make my grid an arbitrary size, and arbitrary thickness. So far I have tried using

GRID2 = ImplicitRegion[Mod[x, 5] <= 1 || Mod[y, 5] <= 1, {{x, -10, 10}, {y, -10, 10}}]

but when I try to plot this Mathematica tells me it's an invalid region to plot. I've also tried Floor-ing the x and y prior to Mod-ing, but it makes no difference. Are there any suggestions on a better way of doing this?

EDIT: It's probably worth pointing out that I plan on using this region as the domain specification of a ParametricPlot3D.

share|improve this question
up vote 12 down vote accepted
r = N @ ImplicitRegion[
   Sin[x Pi] > 0 || Sin[y Pi] > 0, 
   {{x, 0, 9}, {y, 0, 9}}
]

RegionPlot @ r

enter image description here

r3 = N @ ImplicitRegion[
   Sin[x Pi] > 0 || Sin[y Pi] > 0 || Sin[z Pi] > 0, 
   {{x, 0, 9}, {y, 0, 9}, {z, 0, 9}}
]

RegionPlot3D[r3, PlotStyle -> Opacity@.5]

enter image description here

So you can play with translation and scaling with:

Sin[2 x Pi] > 0 || Sin[.5 (y + 1) Pi] > 0

enter image description here

share|improve this answer
1  
Also works with SquareWave[x/2] > 0 || SquareWave[y/2] > 0, but the timings are horrible - 24s vs 0.4s for the Sin version. – shrx Jan 24 at 8:26
    
The meshes are different too: i.stack.imgur.com/0WeFJ.png – shrx Jan 24 at 8:33
    
@shrx Can't make that work on 10.3.1: ImplicitRegion[ SquareWave[x/2] > 0 || SquareWave[y/2] > 0, {{x, 0, 9}, {y, 0, 9}}] and the dense mesh you see for SquareWave is there for Sin appraoch. – Kuba Jan 24 at 8:37
    
interesting, seems like a regression. I have 10.2.0 on OS X. – shrx Jan 24 at 9:08

Here is an idea based on graphics primitives instead of mathematical inequalities.

columnWidth = 1;
regionSize = 10;
holes = Table[
   Rectangle[{x, y}, {x + columnWidth, y + columnWidth}],
   {x, columnWidth, regionSize, 2 columnWidth},
   {y, columnWidth, regionSize, 2 columnWidth}
   ];
holes // Graphics

Mathematica graphics

Now we subtract these squares from a larger square that covers all of the area:

RegionDifference[
  Rectangle[{0, 0}, {regionSize + columnWidth, regionSize + columnWidth}],
  RegionUnion[holes]
  ] // RegionPlot

Mathematica graphics

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.