How to hide the portion of a graphic that is outside of a circle

Sometimes one might want to display a graphic such that only the portion inside a circle with a certain radius is displayed. The plot of a Sin wave below will be used as an example where only the portion of the graphic inside a circle centered at the origin with radius 0.85 is displayed.

curve = Plot[Sin[75 t], {t, -1, 1}] ;

The graphic made by the next cell is used to demonstrate how one can hide the portion of the above plot outside the desired circle.

RowBox[{RowBox[{RowBox[{circ, =, RowBox[{ParametricPlot, [, RowBox[{RowBox[{{, RowBox[{RowBox[ ... , ,, RowBox[{{, RowBox[{RowBox[{-, 1.5}], ,, 1.5}], }}]}], }}]}], ,, AxesTrue}], ]}], ;}]

The next input displays the mask from above on-top of the Sin wave made earlier.

RowBox[{RowBox[{Show, [, RowBox[{curve, ,, mask, ,, AspectRatioAutomatic, ,, RowBox[{P ... ], ,, RowBox[{{, RowBox[{RowBox[{-, 1.5}], ,, 1.5}], }}]}], }}]}], ,, AxesTrue}], ]}], ;}]

The next cell makes a circle with lots of points, and ensures the mask covers the whole circle.

RowBox[{RowBox[{RowBox[{circ, =, RowBox[{ParametricPlot, [, RowBox[{RowBox[{{, RowBox[{RowBox[ ... ve, mask, AspectRatioAutomatic, PlotRange {{-1, 1}, {-1, 1}}, AxesTrue] ;

In the next cell the mask is invisible since it's the same color as the bacgkround.

mask = Graphics[{GrayLevel[1], Polygon[pnts]}] ;  Show[curve, mask, AspectRatioAutomatic, PlotRange {{-1, 1}, {-1, 1}}, AxesTrue] ;


Created by Mathematica  (May 16, 2004)

Back to Ted’s Tricks index page