# Problems with region-related functions

For a demonstration project, I am calculating certain geometric properties of a region (an isosceles triangle in this example), as follows:

baseshape = SASTriangle[2, Pi/6, 2];
cbs0 = RegionCentroid[baseshape];
baseshape = TransformedRegion[baseshape, TranslationTransform[-cbs0]];


This calculates the centroid, and moves the region so its centroid is at the origin. Now I am going to rotate the region, move it down by depth, and define the part of the region that lies below y=0 as a new region, as follows:

rrs[\[Theta]_?NumericQ, depth_?NumericQ] :=
RegionIntersection[
TransformedRegion[
TransformedRegion[baseshape, RotationTransform[\[Theta]]],
TranslationTransform[{0, -depth}]],
ImplicitRegion[y <= 0, {x, y}]];


However, I get an error message when I try to plot this:

Plot[Area[rrs[0, depth]], {depth, -0.7, 1.4}]

Area::reg: rrs(0,d,{0,0}) is not a correctly specified region.


The plot looks fine, but I don't understand the reason for the error message. What am I missing?

• Evaluating Area[rrs[0,depth]] gives a pure function with several variables, may be the reason behind the error message. – Vahagn Tumanyan Sep 8 '16 at 6:11
• The standard trick is to define area[depth_?NumericQ] := Area[rrs[0, depth]] and plot area[depth]. – Chip Hurst Sep 8 '16 at 19:43

The error comes from the evaluation of Area[rrs[0, depth]] with the non-evaluated symbol depth:

Plot[Area[rrs[0, Echo@depth]], {depth, -0.6, -0.5},
PlotPoints -> 2, MaxRecursion -> 1]

>> -0.6
>> -0.5999
>> depth
Area::reg: rrs[0,depth] is not a correctly specified region.
>> -0.6
>> -0.5
>> -0.55

(* plot displayed *)


This symbolic evaluation happens as part of the detection of exclusions. You can avoid it by setting the option Exclusions to None:

Plot[Area[rrs[0, Echo@depth]], {depth, -0.6, -0.5},
PlotPoints -> 2, MaxRecursion -> 1, Exclusions -> None]

>> -0.6
>> -0.5999
>> -0.6
>> -0.5
>> -0.55

(* plot displayed *)


Note that Plot has the default value Exclusions -> Automatic, which is effectively equivalent to Exclusions -> All when the option PerformanceGoal is Quality (see Exclusions ref page),

Options[Plot, "PerformanceGoal"]
(* {PerformanceGoal :> $PerformanceGoal} *)$PerformanceGoal
(* "Quality" *)


so another way to get rid of the message is to set PerformanceGoal to another value:

Plot[Area[rrs[0, Echo@depth]], {depth, -0.6, -0.5},
PlotPoints -> 2, MaxRecursion -> 1, PerformanceGoal -> "Speed"]

>> -0.6
>> -0.5999
>> -0.6
>> -0.5
>> -0.55

(* plot displayed *)


This last approach may be more interesting if you want to process excluded regions with ExclusionsStyle (in this case the value of Exclusions should not be Automatic, and needs to be set to another value --- for instance True or All).

• Great answer, thanks! Now I understand why Plot attempts to evaluate expressions with non-numeric values. – Pirx Sep 8 '16 at 16:05