1

I have a specific pattern to show in Graphics and I would like to choose the PlotRegion as a shape. In other words, I would like to show part of the pattern within a specific shape such as Hexagon or Polygon.

Assume that the pattern is Rectangle, see below, and I would like to make the PlotRegion to be a Hexagon. How can I do that?

Graphics[{Pink, Rectangle[]}]

enter image description here

Johu
  • 4,918
  • 16
  • 43
MMA13
  • 4,664
  • 3
  • 15
  • 21

1 Answers1

1

Use Transparent as a color and make a mask using it. Combine different Graphics with Show or combine the lists of graphics primitives.

Note, that this can also be done with continues Opacity and not only sharp cutoff. For example Transparent can be used in the ColorFunction of DensityPlot and then your mask can be described by a continues value function.

The mask can be constructed using RegionDifference

Show[{Graphics[{Pink, Rectangle[]}], 
  DiscretizeRegion[
   RegionDifference[Rectangle[], Disk[{0.5, 0.5}, 0.3]], 
   BaseStyle -> Directive[EdgeForm[None], FaceForm[White]]]}]

enter image description here

If the underlying graphics you mask is a Plot-like and not a general Graphcis, one can use MeshRegion and RegionFunction. See the related Q&A.

Johu
  • 4,918
  • 16
  • 43