2
$\begingroup$

I have this 2D graphics

a1 = {-1, Sqrt[3]};
a2 = {1, Sqrt[3]};
unitCell[x_, y_] := {Black, Disk[{x, y}, 0.1], Black, 
  Disk[({x, y} + a1/2), 0.1], Black, Disk[({x, y} + a2/2), 0.1], Blue,
   Thickness[0.001], Line[{{x, y}, {x, y} + a1/2}], 
  Line[{{x, y}, {x, y} + a2/2}], 
  Line[{{x, y} + a2/2, {x, y} + a2/2 - (a2 - a1)/2}], 
  Line[{{x, y} + a2/2, {x, y} + a2}], 
  Line[{{x, y} + a1/2, {x, y} + a1}], 
  Line[{{x, y} + a1/2, {x, y} + a1/2 - (a2 - a1)/2}]};
ff2=Graphics[{Table[
   unitCell @@ (a1 j + a2 k), {j, -5, 5}, {k, -5, 5}]}, 
 ImageSize -> 300, PlotRange -> {{-6, 6}, {-6, 6}}]

I would like to exclude points outside a disk of radius r (i.e. show only points inside the red or green circle as below.

enter image description here

This is how I did it be not working

r=2    
desirdReg= RegionDifference[ff2, Disk[{0, 0}, r]];
    Region[desirdReg]

it gives:

RegionDifference::reg:  is not a correctly specified region.

I would like to get something like this

enter image description here

$\endgroup$
2
  • $\begingroup$ What are the definitions of unitVectA and unitVectB? $\endgroup$
    – demm
    Commented Jan 3, 2022 at 11:32
  • $\begingroup$ @demm they are a1 and a2, code modified. $\endgroup$
    – MMA13
    Commented Jan 3, 2022 at 11:35

2 Answers 2

3
$\begingroup$

I suggest using patterns and deleting the unwanted Disk and Line objects.

reg = Disk[{3/4, 0}, 2];

ff2 = {Table[unitCell @@ (a1 j + a2 k), {j, -5, 5}, {k, -5, 5}]};

Graphics[DeleteCases[
  ff2, (Disk[{x_, y_}, r_] /; {x, y} \[NotElement] reg) | 
       (Line[{{x1_, y1_}, {x2_, y2_}}] /; ({x1, y1} \[NotElement] reg || 
       {x2, y2} \[NotElement] reg)), All]]

Mathematica graphics

$\endgroup$
3
$\begingroup$
dsk = Disk[{0, Sqrt[3]}, Sqrt[3]];

reg = RegionIntersection[DiscretizeRegion@dsk, DiscretizeGraphics[ff2]];

cropped = MeshPrimitives[reg, All];

Graphics[{AbsoluteThickness[1], AbsolutePointSize[10], cropped}]

enter image description here

Graphics[{First@ff2, AbsoluteThickness[3], AbsolutePointSize[7], 
  MapThread[{##} &, {{ Blue, Red}, Reverse@cropped}], Opacity[.5], 
  Green, Circle @@ dsk}, PlotRange -> 4]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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