1
$\begingroup$

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?

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

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).

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.