5
$\begingroup$

Bug introduced in 10.0 and fixed in 10.4


Given that two polygons regions as below:

ellipsePoints[mat_, {x_, y_}] := 
  mat.{Sin[#], Cos[#], 1} & /@ Range[x, y, 0.02 Pi]
ellipsePoints[mat_, {{a_, b_}, {c_, d_}}] := 
  mat.{Sin[#], Cos[#], 1} & /@ 
   Join[Range[a, b, 0.02 Pi], Range[c, d, 0.02 Pi]]

mat1 = 
  {{{0., -5., 0}, {-5.2203, 0., 1.7945}}, 
   {{-0.8583, -4.9384, 0.6792}, {-5.4189, 0.7822, 1.8663}}, 
   {{-1.8203, -4.7553, 1.0855}, {-5.6022, 1.5451, 1.9672}}, 
   {{-2.3568, -4.6194, 1.1959}, {-5.6897, 1.9134, 2.047}}, 
   {{-2.9427, -4.455, 1.2502}, {-5.7755, 2.27, 2.1556}}, 
   {{-4.3197, -4.0451, 1.2087}, {-5.9456, 2.9389, 2.4846}}, 
   {{-6.1237, -3.5355, 1.}, {-6.1237, 3.5355, 3.}}};

domain1 = 
  {{{5.0026, 2 Pi}, {0, 1.4113}}, {1.2264, 5.2684},
   {0.6788, 5.5682}, {{0.2931, 2.3402}, {2.9578, 5.7662}}, 
   {{3.2396, 2 Pi}, {0, 2.1486}}, {{3.4794, 2 Pi}, {0, 2.0429}}, 
   {{3.5801, 2 Pi}, {0, 2.0223}}};

pts1 = Flatten[
        MapThread[ellipsePoints, {mat1[[1 ;; 3]], domain1[[1 ;; 3]]}], 1];
pts2 = Flatten[
         MapThread[ellipsePoints, {mat1[[1 ;; 5]], domain1[[1 ;; 5]]}], 1];

Show[ConvexHullMesh[pts2], ConvexHullMesh[pts1]]

Obviously, mesh1 and mesh2 own difference of area.

enter image description here

RegionDifference[ConvexHullMesh[pts2], ConvexHullMesh[pts1]]

enter image description here

However, the above code cannot return the difference of area normally.

An alternative method is using RegionIntersection[],

intersec = 
 RegionIntersection[ConvexHullMesh[pts3], ConvexHullMesh[pts2]]

then using the bigest area minus insters. This time it also failed.

RegionDifference[ConvexHullMesh[pts2], intersec]

enter image description here


Normal case

pts3 = Flatten[MapThread[ellipsePoints, {mat1, domain1}], 1];
RegionDifference[ConvexHullMesh[pts3], ConvexHullMesh[pts1]]

enter image description here


Test on version V10.3

enter image description here

Bug fixed in V10.4

enter image description here

$\endgroup$
6
  • $\begingroup$ I get the correct answer in version 10.4 $\endgroup$
    – RunnyKine
    Mar 31, 2016 at 8:38
  • $\begingroup$ @RunnyKine my version is V10.3 $\endgroup$
    – xyz
    Mar 31, 2016 at 8:39
  • 1
    $\begingroup$ Well, I guess it was fixed in 10.4 then. (!Mathematica graphics) $\endgroup$
    – RunnyKine
    Mar 31, 2016 at 8:40
  • $\begingroup$ @RunnyKine THX, I have added the bug tag. $\endgroup$
    – xyz
    Mar 31, 2016 at 9:05
  • $\begingroup$ @RunnyKine Could you help me this confusion. Thanks:) $\endgroup$
    – xyz
    Apr 6, 2016 at 3:37

1 Answer 1

6
$\begingroup$

This is not an answer to "Why doesn't RegionDifference work with these regions?" - there the only answer I have is that the computational geometry functions are still a work in progress.

This is a workaround for giving the region you are looking for, by building an ImplicitRegion first,

{em1, em2} = {ConvexHullMesh[pts2], ConvexHullMesh[pts1]}; 
RegionPlot[
 ImplicitRegion[Xor[{x, y} ∈ em1, {x, y} ∈ em2], {x, y}], 
 PlotRange -> {{-6, 7}, {-5, 9}}]

enter image description here

which you can convert to a MeshRegion via

DiscretizeGraphics@%

enter image description here

$\endgroup$
6
  • $\begingroup$ @ShutaoTANG - it works for me, after your edit (sorry about the mistake) $\endgroup$
    – Jason B.
    Mar 31, 2016 at 8:40
  • $\begingroup$ However, I cannot run the code that I have edited, which ran for long time and given this errot $\endgroup$
    – xyz
    Mar 31, 2016 at 8:46
  • $\begingroup$ hmmmm, version 10.3.0 or 10.3.1? I'm using 10.3.1 and it works for me. It runs in 10.0 but doesn't capture both parts of the region, only the upper part. But in version 10.2 it gives the same error as you get $\endgroup$
    – Jason B.
    Mar 31, 2016 at 8:50
  • $\begingroup$ My Mathematica version $10.3.0$, bug...:) $\endgroup$
    – xyz
    Mar 31, 2016 at 8:53
  • $\begingroup$ Yeah, is there any way for you to download the 10.3.1 upgrade? It's just a bugfix so it should be free $\endgroup$
    – Jason B.
    Mar 31, 2016 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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