3
$\begingroup$

This works as expected:

BoundaryDiscretizeRegion[RegionUnion[Triangle[], Rectangle[{0.5, 0}, {1, 1}]]]

Union of triangle and rectangle

Now, suppose I want to change the fill color to green and the edge color to red. How would I do that?

(I tried using RegionPlot, but that didn't work)

$\endgroup$
7
  • $\begingroup$ This is on 11.0, by the way. $\endgroup$
    – Shane
    Commented Jul 19, 2017 at 15:38
  • 1
    $\begingroup$ It's interesting that you say that RegionPlot[RegionUnion[..]] works as expected, since as far as I can tell, nowhere in the documentation does it say that such a thing is supported. $\endgroup$
    – Carl Woll
    Commented Jul 19, 2017 at 21:30
  • $\begingroup$ @CarlWoll If there were documentation on that usage, that is how I would expect it to function. I read about using RegionPlot[] that way in a Q here (can't remember which question, unfortunately). In any case, you bring up an interesting point. When I try RegionPlot[BoundaryDiscretizeRegion[RegionUnion[Triangle[], Rectangle[{0.9, 0}, {1, 1}]]], {x, 0, 1}, {y, 0, 1}], I get all sorts of errors. Does this mean that BoundaryDiscretizeRegion[] doesn't give me a legitimate region to plot with RegionPlot? $\endgroup$
    – Shane
    Commented Jul 19, 2017 at 21:44
  • $\begingroup$ Why do you want to use RegionPlot in this way? Is it just so that there are ticks? Is it because you need a Graphics object? $\endgroup$
    – Carl Woll
    Commented Jul 19, 2017 at 21:47
  • 1
    $\begingroup$ Something like BoundaryDiscretizeRegion[ RegionUnion[Triangle[], Rectangle[{0.5, 0}, {1, 1}]], BaseStyle -> {FrontFaceColor -> Green, EdgeColor -> Red}] ? $\endgroup$
    – Carl Woll
    Commented Jul 19, 2017 at 22:41

2 Answers 2

3
$\begingroup$

BoundaryDiscretizeRegion takes most of the options available to Graphics:

Complement[
    Options[Graphics][[All, 1]],
    Options[BoundaryDiscretizeRegion][[All, 1]]
]

{ColorOutput, ContentSelectable, CoordinatesToolOptions, FormatType, \ ImageSizeRaw, PreserveImageOptions}

This means, that you should be able to use Graphics options to control the appearance of the discretization. Rather than just giving you the options to use, I will show you how to find out what options are available for this purpose. The box form of Graphics is GraphicsBox, and the options for GraphicsBox are:

Options[GraphicsBox]

{AlignmentPoint -> Center, AspectRatio -> Automatic, Axes -> False, AxesLabel -> None, AxesOrigin -> {Automatic, Automatic}, AxesStyle -> {}, Background -> None, BaseStyle -> {}, BaselinePosition -> Automatic, ColorOutput -> Automatic, ContentSelectable -> Automatic, CoordinatesToolOptions :> Automatic, DefaultAxesStyle -> "GraphicsAxes", DefaultBaseStyle -> "Graphics", DefaultFrameStyle -> "GraphicsFrame", DefaultFrameTicksStyle -> "GraphicsFrameTicks", DefaultGridLinesStyle -> "GraphicsGridLines", DefaultLabelStyle -> "GraphicsLabel", DefaultTicksStyle -> "GraphicsTicks", Epilog -> {}, FormatType -> TraditionalForm, Frame -> False, FrameLabel -> None, FrameStyle -> {}, FrameTicks -> Automatic, FrameTicksStyle -> {}, GridLines -> None, GridLinesStyle -> {}, ImageMargins -> 0., ImageMarkers -> None, ImagePadding -> All, ImageSize -> Automatic, ImageSizeRaw -> Automatic, ImageSizeRules -> Automatic, LabelStyle -> {}, Method -> {}, PlotLabel -> None, PlotRange -> All, PlotRangeClipping -> False, PlotRangePadding -> Automatic, PlotRegion -> {{0., 1.}, {0., 1.}}, PreserveImageOptions -> Automatic, Prolog -> {}, RotateLabel -> True, Ticks -> Automatic, TicksStyle -> {}}

In particular, note the DefaultBaseStyle option:

Options[GraphicsBox, DefaultBaseStyle]

{DefaultBaseStyle -> "Graphics"}

The DefaultBaseStyle points to the style "Graphics". This style has the following settings:

CurrentValue[{StyleDefinitions, "Graphics"}]

{CellMargins -> {{4, Inherited}, {Inherited, Inherited}}, CellGroupingRules -> "GraphicsGrouping", StripStyleOnPaste -> False, PageBreakWithin -> False, GeneratedCell -> True, CellAutoOverwrite -> True, ShowCellLabel -> False, DefaultFormatType -> DefaultOutputFormatType, ContextMenu -> {MenuItem["Cu&t Graphics Selection", "Cut"], MenuItem["&Copy Graphics Selection", "Copy"], MenuItem["&Paste into Graphic", FrontEnd`Paste[After]], Delimiter, MenuItem["&Drawing Tools", FrontEndExecute[{FrontEnd`NotebookOpen[ FrontEnd`FindFileOnPath["DrawingTools.nb", "PrivatePathsSystemResources"]]}]], MenuItem["&Get Coordinates", FrontEndExecute[FrontEnd`Select2DTool["GetCoordinates"]]], Delimiter, MenuItem["G&roup", "Group"], MenuItem["&Ungroup", "Ungroup"], Delimiter, MenuItem["Move to &Front", "MoveToFront"], MenuItem["Move to &Back", "MoveToBack"], MenuItem["Move For&ward", "MoveForward"], MenuItem["Move Bac&kward", "MoveBackward"]}, "AutoStyleOptionsHighlightMisspelledWords" -> False, LanguageCategory -> "NaturalLanguage", FormatType -> StandardForm, ShowStringCharacters -> False, NumberMarks -> False, CounterIncrements -> "Graphics", ImageMargins -> {{43, Inherited}, {Inherited, 0}}, Arrowheads -> 0.04, Dashing -> None, CapForm -> "Square", JoinForm -> {"Miter", 3.25}, LineColor -> GrayLevel[0], LineOpacity -> 1, EdgeColor -> GrayLevel[0], EdgeOpacity -> 1, EdgeThickness -> Medium, EdgeDashing -> None, EdgeCapForm -> "Square", EdgeJoinForm -> {"Miter", 3.25}, FrontFaceColor -> GrayLevel[0], BackFaceColor -> GrayLevel[0], FrontFaceOpacity -> 1, BackFaceOpacity -> 1, GraphicsColor -> GrayLevel[0], PointSize -> Absolute[3], Thickness -> Medium, Opacity -> 1, DrawEdges -> False, StyleMenuListing -> None, FontFamily -> "Arial", FontSize -> 10, FontWeight -> "Plain", FontColor -> GrayLevel[0], FontOpacity -> 1}

You see options controlling LineColor, EdgeColor, etc., and you can play with changing these settings to see what their effects are. To change the fill color and the edge color of your discretization, you could use:

BaseStyle -> {FrontFaceColor -> Green, EdgeColor -> Red, EdgeThickness -> .02}

Using this BaseStyle in your discretization produces:

BoundaryDiscretizeRegion[
    RegionUnion[Triangle[], Rectangle[{0.5, 0}, {1, 1}]],
    BaseStyle -> {FrontFaceColor -> Green, EdgeColor -> Red, EdgeThickness -> .02}
]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ "I will show you how to find out what options are available for this purpose." Invaluable to me. Thanks! $\endgroup$
    – Shane
    Commented Jul 20, 2017 at 18:46
3
$\begingroup$

You could use the option MeshCellStyle.

BoundaryDiscretizeRegion[
  RegionUnion[Triangle[], Rectangle[{0.5, 0}, {1, 1}]], 
  MeshCellStyle -> {1 -> Directive[Thick, Red], 2 -> Green}
]

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.