1
$\begingroup$

I have a 3D object and I would like to remove everywhere except a part with a circle shape. Here is the 3D object

ax := 0; az := 2; ay := 0; rs = 0.1; rl = 0.01;
unitCell3D[x_, y_, z_] := {Black, Sphere[{x + ax, y + ay, az}, rs], 
   Black, Sphere[{x + ax, y + ay + 2/3 Sin[120 Degree], az}, rs], 
   Black, Cylinder[{{x + ax, y + ay, az}, {x + ax, 
      y + ay + 2/3 Sin[120 Degree], az}}, rl], Black, 
   Cylinder[{{x + ax, y + ay, az}, {x + ax + Cos[30 Degree]/2, 
      y + ay - Sin[30 Degree]/2, az}}, rl], Black, 
   Cylinder[{{x + ax, y + ay, az}, {x + ax - Cos[30 Degree]/2, 
      y + ay - Sin[30 Degree]/2, az}}, rl]};
xUns[j_] = j Sin[\[Pi]/3] + 0.1;
f2 = Graphics3D[
  Block[{unitVectA = {Cos[120 Degree], Sin[120 Degree], 0}, 
    unitVectB = {1, 0, 0}}, 
   Table[unitCell3D @@ (unitVectA j + unitVectB k), {k, -10, 
     10}, {j, -10, 10}]], Boxed -> False, Axes -> False, 
  Method -> {"EdgeDepthOffset" -> False}, ImageSize -> 300, 
  PlotRange -> {{-5.6, 5.6}, {xUns[-6] - Sin[\[Pi]/6], 
     xUns[6]}, {-0.3, 2.3}}]   

and here is how I remove the desired part

hole = Cylinder[{{0, 0, -3}, {0, 0, 2}}, Sqrt[10]];
dhole = DiscretizeRegion@hole; g2 =
 f2 /. Sphere -> Ball /. 
  r_?(RegionQ@# && ! RegionWithin[hole, #] &) :> 
   If[RegionDisjoint[hole, r], Nothing, {EdgeForm@None,
     BoundaryMesh[RegionDifference[DiscretizeRegion@r, dhole]]}];

Show[g2, Graphics3D[hole], Boxed -> False, ViewPoint -> Top, 
 ImageSize -> 450]    

but some dangling lines and dots exist in the removed region, see below. How can I make it perfectly removed outside the circle?

enter image description here

$\endgroup$
  • $\begingroup$ What for you build this region? $\endgroup$ – Alex Trounev Jul 8 at 14:28
  • $\begingroup$ I would like to remove everywhere except the defined circle $\endgroup$ – HD2006 Jul 8 at 14:36
  • $\begingroup$ How do you use it - just for plotting or in some problems with FEM? $\endgroup$ – Alex Trounev Jul 8 at 14:44
  • $\begingroup$ @AlexTrounev for plotting $\endgroup$ – HD2006 Jul 8 at 14:47
  • 1
    $\begingroup$ You need to change RegionDifference to RegionIntersection - after all, you want to include the part of the structure that is intersecting the cylinder here instead of cutting away the cylinder. The other change required is that you should make the upper limit of hole larger, e.g. 3 (otherwise you're cutting your structure in half, which will take way longer, and is probably not what you want) $\endgroup$ – Lukas Lang Jul 9 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.