37
$\begingroup$

If you type

?Region`*

you'll get:

Mathematica graphics

which seems a bunch of interesting and not documented symbols.

Any idea (or experience) on how to use them?

Edit

By using our "collective spelunking" I was able to work out this answer - Great! :)

And Silvia used it to write another one!

$\endgroup$
20
  • 3
    $\begingroup$ Region`RegionMeasure[Circle[]] -> 2 Pi :) $\endgroup$
    – cormullion
    Dec 20, 2013 at 18:34
  • 2
    $\begingroup$ Christmas has arrived in your region? :) $\endgroup$
    – cormullion
    Dec 20, 2013 at 18:47
  • 4
    $\begingroup$ Check this: Region`RegionProperty[Polygon[{{1, 0}, {0, 1}, {2, 3}}], {x, y}, "FastDescription"] $\endgroup$ Dec 20, 2013 at 22:10
  • 2
    $\begingroup$ Great find by the way. I wish we could get documentation for some of the useful stuff in these hidden-away packages. $\endgroup$ Dec 20, 2013 at 22:24
  • 3
    $\begingroup$ In Simon's footsteps, trying to find valid arguments for RegionProperty I ran Union@Cases[ ToExpression[#, InputForm, DownValues] & /@ Names["Region`*"], HoldPattern[Region`RegionProperty[__, s_String]] :> s, Infinity] to find {"Distance", "FastDescription", "ImplicitDescription", "Nearest", "SpaceDimension"}. SpecialRegionProperty can take {"Assumptions", "BoundingBox", "Centroid", "ConvexQ", "Distance", "ImplicitDescription", "InjectiveParametricDescription", "Instance", "Measure", "Nearest", "ParametricDescription", "RegionDimension", "SignedDistance", "SpaceDimension"} $\endgroup$
    – Szabolcs
    Dec 21, 2013 at 0:12

5 Answers 5

16
$\begingroup$

For a more clear view, here is a table of some of the Region functions.

AppendTo[$ContextPath, "Region`"]

Clear[testfunc]
testfunc[reg_] := {ToString /@ #, Through[#[reg]]} &[{
                    ConvexRegionQ,
                    BoundedRegionQ,
                    RegionDimension,
                    Module[{dim = RegionEmbeddingDimension[#]},
                           var = Symbol["x" <> ToString[#]] & /@ Range[dim];
                           dim] &,
                    RegionMeasure,
                    RegionCentroid,
                    RegionProperty[#, var, "FastDescription"] &,
                    RegionProperty[#, var, "ImplicitDescription"] &,
                    RegionElement,
                    LevelFunction[RegionProperty[#, var, "FastDescription"][[1, 2]]] &
                  }] // 
          Grid[Insert[#, {ConvexRegionQ, BoundedRegionQ, RegionDimension, 
               RegionEmbeddingDimension, RegionMeasure, RegionCentroid, 
               FastDescription, ImplicitDescription, RegionElement, 
               LevelFunction}, 2]\[Transpose], Dividers -> All, 
            FrameStyle -> GrayLevel[.8], Alignment -> Left] & // Quiet

In addition of BoxRegion, other *Regions also seems to be used to declare regions:

Names["Region`*Region"]

{"BallRegion", "BooleanRegion", "BoxRegion", "EllipsoidRegion", "EmptyRegion", "FullRegion", "InverseTransformedRegion", "ParametricRegion", "SimplexRegion", "TransformedRegion"}

For example, a 2D triangle embeded in 7D space:

tri3d = RandomInteger[{-10, 10}, {3, 3}];
tri7d = ArrayFlatten[{{tri3d, ConstantArray[0, {3, 4}]}}];
(* a random rotate in 7D space: *)
rt7d = RotationTransform[{{0, 0, 1, 0, 0, 0, 0}, RandomInteger[{-1, 1}, 7]},
                         ConstantArray[0, 7]];
tri7d = rt7d /@ tri7d;
testfunc@SimplexRegion[tri7d]

test for 7D triangle

Maybe some of them (LevelFunction) work only on "full-rank" regions?

simplex = Function[dim, SimplexRegion[RandomInteger[{-10, 10}, {dim + 1, dim}]]] @ 4
testfunc @ simplex

test for simplex

Some regions look like special cases:

RegionDimension@EmptyRegion[2]

$-\infty$

RegionMeasure@FullRegion[3]

$\infty$

Edit:

SimplePolygonPartition can be used to divide self-intersecting Polygon to simple pieces. The usage is like

SimplePolygonPartition[Polygon[...]]
SimplePolygonPartition[Polygon[...],Graphics`Region`RegionDump`FillingMethod->"OddEvenRule"]

An example can be found here.

$\endgroup$
9
  • 1
    $\begingroup$ Great! In a few days we'll be able to write a manual! :) $\endgroup$ Dec 21, 2013 at 3:31
  • 5
    $\begingroup$ @belisarius The Uncomplete Unofficial Documentation for Undocumented Functions :P $\endgroup$
    – Silvia
    Dec 21, 2013 at 4:02
  • 1
    $\begingroup$ take a look! mathematica.stackexchange.com/a/39206/193 $\endgroup$ Dec 21, 2013 at 6:49
  • $\begingroup$ @belisarius Thanks for you and Simon's enlightenment, I found a similar solution :) $\endgroup$
    – Silvia
    Dec 22, 2013 at 0:25
  • $\begingroup$ @belisarius Found a new one SimplePolygonPartition :) $\endgroup$
    – Silvia
    Jan 28, 2014 at 6:30
13
$\begingroup$

This is quite a find. I've only had time to play with it a little, but are some interesting results:

Region`ConvexRegionQ[Disk[{1., 0.}]]
True
Region`RegionCentroid[Disk[{1., 0.}]]
{1., 0.}
Region`RegionMeasure[Disk[{1., 0.}]]
π
Region`RegionIntersection[Disk[{0, 0}], Disk[{1, 0}]]

seems to do nothing, but

Region`RegionMeasure @ Region`RegionIntersection[Disk[{0, 0}], Disk[{1, 0}]]
-(Sqrt[3]/2) + (2 π)/3

It appears one can create regions and operate on them:

box = Region`BoxRegion[{0, 0}, {2, 3}];
Region`RegionMeasure @ box
6
Region`RegionCentroid @ box

{1, 3/2}

$\endgroup$
1
  • $\begingroup$ +1 And it seems most of them also work for 3D cases. $\endgroup$
    – Silvia
    Dec 21, 2013 at 0:11
9
$\begingroup$

Its interesting to note that the Region context is loaded when you evaluate Graphics`Region`RegionInit[]. Old favourite Graphics`Mesh gets loaded too. There is some interesting looking stuff in Graphics`Region, clearly incomplete, for example one of the definitions is this...

BoundingRegion[___] := "Implement me..."

I've not done much spelunking yet, but did find this:

Graphics`Region`RegionInit[];

RegionConvert[Disk[]]
(* MeshRegion[{2, 2}, {951, 2289, 1339}, <>] *)

Graphics[Line @ MeshCoordinates[%, 1]]

enter image description here

$\endgroup$
1
7
$\begingroup$

Four more:

RegionNearest[] returns the nearest point inside a region to a given point:

AppendTo[$ContextPath, "Region`"]

RegionNearest[Disk[], {3, 4}]
(*
 {3/5, 4/5}
*)

RegionDifference[] seems to return unevaluated ... but no:

RegionMeasure@RegionDifference[Rectangle[], Disk[]]
(*
 1 - π/4
*)

TransformedRegion[] also seems to return unevaluated ... but again:

RegionMeasure@TransformedRegion[Rectangle[], ScalingTransform[{3, 2}]]
(*
 6
*)

ParametricRegion[]:

RegionMeasure@ParametricRegion[{{x, y}, 0 < x < 1 && 0 < y < 2}]
(*
 2
*)
$\endgroup$
3
  • $\begingroup$ @Silvia RegionMeasure@ParametricRegion[{{x, y}, 0 < x < 1 && 0 < y < 2}] $\endgroup$ Dec 21, 2013 at 5:58
  • $\begingroup$ Sorry I missed that.. But ParametricRegion will be my most interested one :) $\endgroup$
    – Silvia
    Dec 21, 2013 at 5:58
  • $\begingroup$ Wow! Brilliant! $\endgroup$
    – Silvia
    Dec 21, 2013 at 5:58
0
$\begingroup$

So far as I know, the region properties can be:

In[1]:= Union[
 Join[Region`SpecialBoundaryProperty[]; 
  Cases[GeneralUtilities`Definitions[
    "SpecialBoundariesDump`SRBdryRule"], _String, -1], 
  Region`SpecialRegionProperty[]; 
  Cases[GeneralUtilities`Definitions[
    "SpecialRegionsDump`SRPropRule"], _String, \[Infinity]]]]

Out[1]= {"Assumptions", "Boundary", "BoundingBox", "Centroid", \
"ConvexQ", "Distance", "ImplicitDescription", \
"InjectiveParametricDescription", "Instance", "LinearGraphics", \
"Measure", "Nearest", "ParametricDescription", "Primitive", "Region", \
"RegionDimension", "SignedDistance", "SimpleBoundary", \
"SimplicialDecomposition", "SpaceDimension", "Type"}

Unfortunately, this list is incomplete. According to

In[2]:= Region`RegionProperty[Pyramid[],{x,y,z},"FastDescription"]
Out[2]= {{{x,y,z},-4 (-2-2 y+2 z)>=0&&-4 (-2+2 x+2 z)>=0&&-4 (-2+2 y+2 z)>=0&&4 (2+2 x-2 z)>=0&&16 z>=0}}
In[3]:= Region`RegionProperty[Pyramid[],{x,y,z},"FastImplicitDescription"]
Out[3]= -4 (-2-2 y+2 z)>=0&&-4 (-2+2 x+2 z)>=0&&-4 (-2+2 y+2 z)>=0&&4 (2+2 x-2 z)>=0&&16 z>=0
In[4]:= Region`RegionProperty[Pyramid[],{x,y,z},True,"ImplicitDescription"]
Out[4]= {(x==-1&&((y==-1&&z==0)||(-1<y<0&&z==0)||(y==0&&z==0)||(0<y<1&&z==0)||(y==1&&z==0)))||(-1<x<0&&((y==-1&&z==0)||(-1<y<x&&0<=z<=1+y)||(y==x&&0<=z<=1+y)||(x<y<0&&0<=z<=1+x)||(y==0&&0<=z<=1+x)||(0<y<-x&&0<=z<=1+x)||(y==-x&&0<=z<=1+x)||(-x<y<1&&0<=z<=1-y)||(y==1&&z==0)))||(x==0&&((y==-1&&z==0)||(-1<y<0&&0<=z<=1+y)||(y==0&&0<=z<=1-y)||(0<y<1&&0<=z<=1-y)||(y==1&&z==0)))||(0<x<1&&((y==-1&&z==0)||(-1<y<-x&&0<=z<=1+y)||(y==-x&&0<=z<=1+y)||(-x<y<0&&0<=z<=1-x)||(y==0&&0<=z<=1-x)||(0<y<x&&0<=z<=1-x)||(y==x&&0<=z<=1-y)||(x<y<1&&0<=z<=1-y)||(y==1&&z==0)))||(x==1&&((y==-1&&z==0)||(-1<y<0&&z==0)||(y==0&&z==0)||(0<y<1&&z==0)||(y==1&&z==0))),True}

"FastImplicitDescription" is also a valid region property.
So, is there a complete list?

$\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.