4
$\begingroup$

I have a function which creates a hole of varying radius, depth and would like to tile it in x and y.

    Hole[x_, y_, radius_, holefraction_] := 
 Which[x^2 + y^2 <= radius, holefraction, x^2 + y^2 > radius, 1]

I have been playing around with the mod[] function, but can't seem to find the right way to rigidly offset the hole by an arbitrary pitch in x and y. If this were in a loop, i would just iterate as x=xrelative+i*pitch, but how would I do the reverse, where I just want to rigidly pattern in x and y?
Alternatively, is there a way to create a 2nd function using this one, and just set periodic boundary conditions in x and y? Thanks!

$\endgroup$
5
$\begingroup$
PeriodicHole[p : {x_, y_}, radius_, holefraction_, per : {xPer_, yPer_}] :=
                       If[Norm[p - Round[p, per]] < radius, holefraction, 1]

Plot3D[PeriodicHole[{x, y}, .2, .1, {.5, .4}], {x, 0, 1}, {y, 0, 1}, 
 PlotPoints -> 50, MeshFunctions -> {#3 &}, 
 PlotStyle -> Directive[Orange, Specularity[White, 20]]]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Round[ ] threads automatically over lists $\endgroup$ – Dr. belisarius Apr 10 '15 at 0:43
3
$\begingroup$

You can generate the conditions that should go inside Which on the fly.

holes[x_, y_, radius_, holefraction_] := Which @@ Flatten[{
     Table[
      {Norm[{xp - x, yp - y}] <= radius, holefraction},
      {xp, 0, 10},
      {yp, 0, 10}
      ],
     True, 1
     }];

Test:

DensityPlot[
 holes[x, y, 0.3, 0.5],
 {x, 0, 10}, {y, 0, 10},
 PlotPoints -> 100
 ]

Density plot

$\endgroup$
2
$\begingroup$
myBlock = ImplicitRegion[RegionMember[Cuboid[], {x, y, z}], {x, y, z}];

myHole[xcenter_, ycenter_, radius_, depth_] := 
ImplicitRegion[
RegionMember[
Cylinder[{{xcenter, ycenter, 1.05}, {xcenter, ycenter, 1 - depth}}, radius], 
{x, y, z}], {x, y, z}];

RegionPlot3D[
RegionDifference[myBlock,
   RegionUnion[
   Table[myHole[x, y, .06, .3], {x, .2, .8, .2}, {y, .2, .8, .2}]]],
PlotPoints -> 100]

enter image description here

If you want to have a single iteration variable, use Mod and Floor this way:

RegionPlot3D[
RegionDifference[myBlock,
  RegionUnion[
 Table[myHole[.25 (Mod[i, 3]+1), .25 (Mod[Floor[i/3], 3]+1), .06, .3], 
 {i, 0, 8}]]],
 PlotPoints -> 100,
 Boxed->False]
$\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.