Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.5K Views
|
7 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Why does RegionDifference fail with crescent polygon (V10)?

Posted 6 years ago
POSTED BY: Gary Palmer
7 Replies
Posted 6 years ago

This link is relevant:

Wolfram DiscretizeGraphics

POSTED BY: Gary Palmer
Posted 6 years ago

That did the trick for me, too. I wonder exactly what DiscretizeRegion is doing to the RegionPlot object. To sum up, I'm guessing that native objects like Disk and Rectangle and simple Polygons have DiscretizeRegion somehow built in, but a Polygon construction with more complex data needs to be discretized. I include the revised figure.

enter image description here

POSTED BY: Gary Palmer

On my system your maskCrescent is not really a mask with the crescent as a hole. It is a superposition of polygons that covers the whole of the square. I don't know what happens in version 10. I suspect that something goes wrong when we convert a Region with a hole into graphics primitives with RegionPlot. I get quite different pictures from the following inputs:

RegionDifference[Polygon@rectanglePts, Polygon@crescentPts]
RegionPlot@%

On my system the whole problem somehow goes away if I insert DiscretizeRegion before RegionPlot:

regionDiffCrescent = 
  First@RegionPlot@
    DiscretizeRegion@
     RegionDifference[Polygon@rectanglePts, Polygon@crescentPts];
POSTED BY: Gianluca Gorni
Posted 6 years ago

The requested piece of code is the code for g2 which produced figure [b]. Does my code produce in your system a figure [b] with a white crescent with a diagonal line through it as in the triangle in figure [c]? If so, then I would conclude that the problem is the MMA 10 rather than with the code. I have isolated the code for figure [b].

sz = 1.5; (* rect corner dimension *)

c = 0.551915024494; (* Bezier constant for circle *)

bz = {{0, 1}, {c, 1}, {1, c}, {1, 0}};(* Bezier control points *)

bzF = BezierFunction@bz;

bzFPts = Table[bzF[t], {t, 0, 1, .1}];

crescentPts = AppendTo[bzFPts, bzFPts[[1]]];

figure = Line[{{-1, -1}, {1, 1}}];

rectanglePts = {{-sz, -sz}, {-sz, sz}, {sz, 
    sz}, {sz, -sz}, {-sz, -sz}};

(* error message generated here *)

regionDiffCrescent = First@RegionPlot@RegionDifference[
     Polygon@rectanglePts,
     Polygon@crescentPts
     ] ;

(* remove the default directives from new region *)

maskCrescent = DeleteCases[regionDiffCrescent, _Directive, -1]; 

g2 = Graphics[{figure, FaceForm@LightGray, maskCrescent, 
   Text["[b]", {-.75, .75}]}, ImageSize -> {100, 100}] 
POSTED BY: Gary Palmer

Your code gives no error on my system. Can you give a piece of code that does not work?

POSTED BY: Gianluca Gorni
Posted 6 years ago

The new feature is good to know about, but I'm still using version 10. Can one conclude that DifferenceRegion also fails with these Bezier data in version 12?

POSTED BY: Gary Palmer

If you have version 12 you can try out the new "polygon with holes" feature:

Graphics[Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}} -> 
   crescentPolygon[[3, 1]]]]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard