# Generating periodic structure using RegionPlot3D

I am trying to create a periodic structure from a unit cell figure which I created using RegionPlot3D:

RegionPlot3D[x^2 + y^2 + z^2 < 0.6, {x, -0.5, 0.5}, {y, -0.5, 0.5}, {z, -0.5, 0.5}]


While I can create multiple instances of the unit figure using something like

RegionPlot3D[
x^2+y^2+z^2 ||
(x-1)^2+y^2+z^2 ||
x^2+(y-1)^2+z^2 <0.6, {x,-0.5,0.5}, {y,-0.5,0.5}, {z,-0.5,0.5}
]


I would prefer to have something like a parameter which I can vary to get the multiple instances. Just as an example, I want something like

Graphics3D[
Table[
Sphere[{x,y,z},0.6], {x,0,2,1}, {y,0,2,1}, {z,0,2,1}
]
]


but with my unit figure. Is it possible to achieve it using RegionPlot3D? I am perfectly happy with any other solution - even one which might generate the unit cell with something else. Thanks.

• The region you define is a sphere, but with your plot ranges you have a cutoff sphere, is that what you are going for? – Jason B. Apr 1 '16 at 10:51
• Exactly. My unit cell is a cut-off sphere, and I want to create a periodic structure using multiple instances of that unit cell. – g1joeT Apr 1 '16 at 10:52

## 2 Answers

One useful function for generating periodic structures is Mod[]. Consider the following:

RegionPlot3D[Mod[x, 2, -1]^2 + Mod[y, 2, -1]^2 + Mod[z, 2, -1]^2 < 1,
{x, -2, 2}, {y, -2, 2}, {z, -2, 2},
PlotPoints -> 95, PlotStyle -> Opacity[3/4]] One can fiddle a bit with the scaling so that the spheres intersect instead of just touching. Consider the following:

RegionPlot3D[Mod[2 x, 2, -1]^2 + Mod[2 y, 2, -1]^2 + Mod[2 z, 2, -1]^2 < 12/5,
{x, -2 Sqrt[3/5], 2 Sqrt[3/5]}, {y, -2 Sqrt[3/5], 2 Sqrt[3/5]},
{z, -2 Sqrt[3/5], 2 Sqrt[3/5]}, PlotPoints -> 75,
PlotStyle -> Opacity[3/4]] To get the interstices, just negate the region function:

RegionPlot3D[! (Mod[2 x, 2, -1]^2 + Mod[2 y, 2, -1]^2 + Mod[2 z, 2, -1]^2 < 12/5),
{x, -2 Sqrt[3/5], 2 Sqrt[3/5]}, {y, -2 Sqrt[3/5], 2 Sqrt[3/5]},
{z, -2 Sqrt[3/5], 2 Sqrt[3/5]}, PlotPoints -> 95] • Thanks for pointing out the Mod[] function. I took your code and tried to fiddle around with it. But I couldn't get it to generate the cut-off spheres I want. – g1joeT Apr 1 '16 at 11:12
• Thanks for the revision. I will try to understand the Mod function. – g1joeT Apr 1 '16 at 14:41

What I'd try to do would be to create a region object and use TransformRegion[region,TranslationTransform[...]] to create a displaced copy of it.

OP's original unit cell looks like Now I could create a region using DiscretizeGraphics out of this,

region = DiscretizeGraphics@
Normal@RegionPlot3D[
x^2 + y^2 + z^2 < 0.6, {x, -0.5, 0.5}, {y, -0.5, 0.5}, {z, -0.5,
0.5}]


This gives an error message, but it works I create a table of these regions,

regions = Table[
TransformedRegion[region, TranslationTransform[{x, y, z}]], {x,
2}, {y, 2}, {z, 2}];


and combine them into one RegionPlot3D

RegionPlot3D[regions, Mesh -> 10] And simply by changing the < in the original code to a >, you can get the interstitial regions, ## Edit

Here is a method that I like better, since it doesn't give the error above, but it is a bit slower. The unit cells and interstitial regions can be plotted via

region = DiscretizeRegion@
RegionIntersection[Cuboid[{-.5, -.5, -.5}, {.5, .5, .5}],
Ball[{0, 0, 0}, Sqrt[.6]]];
regions =
Table[TransformedRegion[region,
TranslationTransform[{x, y, z}]], {x, 2}, {y, 2}, {z, 2}];
RegionPlot3D[Flatten@regions, Mesh -> 10]


and

region = DiscretizeRegion@
RegionDifference[Cuboid[{-.5, -.5, -.5}, {.5, .5, .5}],
Ball[{0, 0, 0}, Sqrt[.6]]];
regions =
Table[TransformedRegion[region,
TranslationTransform[{x, y, z}]], {x, 2}, {y, 2}, {z, 2}];
RegionPlot3D[Flatten@regions, Mesh -> 10]


respectively. I wish that DiscretizeRegion was not necessary, as that is what slows it down, but without it RegionPlot3D gives awful results.

• Just tried it out. I think this is exactly what I wanted. Thanks! – g1joeT Apr 1 '16 at 11:24
• Glad to help, welcome to the site, don't forget to take the tour. – Jason B. Apr 1 '16 at 11:25
• Additionally, is there any way to extract the complement of this structure? Meaning ... the periodic structure made up of the interstitial regions? – g1joeT Apr 1 '16 at 11:26
• Yes, but it will take me a second, going to lunch now :-) – Jason B. Apr 1 '16 at 11:26
• Who knows, maybe they'll even skip an integer and go to 12, just like Microsoft did with Windows :) – RunnyKine Apr 1 '16 at 20:37