Function Repository Resource:

RegionInputField

Source Notebook

User interface for drawing 2D mesh regions

Contributed by: Jon McLoone

ResourceFunction["RegionInputField"][Dynamic[var]]

creates a user interface for drawing a MeshRegion which updates var.

Details and Options

ResourceFunction["RegionInputField"] supports all options for RegionPlot.
"BackgroundImage" can be used to place a Graphics or Image in the background. It has no effect on the output.
Clicking the Undo button in the interface undoes the most recent edit to the region.

Examples

Basic Examples (4) 

Draw the outline of the desired region:

In[1]:=
ResourceFunction["RegionInputField"][Dynamic[x]]
Out[1]=

Draw additional areas which will be included in the same region:

Out[1]=

Set the SetterBar to "Remove" to subtract drawn areas from the region:

Out[1]=

The Dynamic variable is updated with the drawn region:

In[2]:=
x
Out[2]=

Options (3) 

RegionInputField supports the options of RegionPlot. These affect the appearance of interface but not the output Region:

In[3]:=
ResourceFunction["RegionInputField"][Dynamic[x], PlotStyle -> Red]
Out[3]=

The default PlotRange is {{0,1},{0,1}} which limits the coordinates that you can draw over. To create regions with larger coordinates, set the PlotRange for the RegionInputField:

In[4]:=
ResourceFunction["RegionInputField"][Dynamic[x], Frame -> True, PlotRange -> {{-100, 100}, {-100, 100}}]
Out[4]=

A Graphics object can be provided as a background image, in which case default options such as PlotRange and ImageSize are inherited from the provided image:

In[5]:=
ResourceFunction["RegionInputField"][Dynamic[x], Frame -> True, "BackgroundImage" -> Graphics[{LightGray, Circle[]}, PlotRange -> {{-2, 2}, {-2, 2}}, ImageSize -> 500]]
Out[5]=

"BackgroundImage" can also be an Image:

In[6]:=
ResourceFunction["RegionInputField"][Dynamic[x], "BackgroundImage" -> Image[GeoGraphics["Africa", GeoBackground -> "Coastlines"]], ImageSize -> 500]
Out[6]=

Applications

In[7]:=
DynamicModule[{x}, Column[{ResourceFunction["RegionInputField"][Dynamic[x], ImageSize -> {300, 300}],
   TextGrid[{{"Area: ", Dynamic[Area[x]]}, {"Perimeter: ", Dynamic[Perimeter[x]]}}]}]]
Out[7]=

Publisher

Jon McLoone

Version History

  • 1.1.0 – 20 May 2022
  • 1.0.0 – 16 October 2019

License Information