Why RegionDifference cannot work normally?

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.

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


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]


Normal case

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


Test on version V10.3

Bug fixed in V10.4

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

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}}]


which you can convert to a MeshRegion via

DiscretizeGraphics@%


• @ShutaoTANG - it works for me, after your edit (sorry about the mistake) Mar 31, 2016 at 8:40
• However, I cannot run the code that I have edited, which ran for long time and given this errot
– xyz
Mar 31, 2016 at 8:46
• 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 Mar 31, 2016 at 8:50
• My Mathematica version $10.3.0$, bug...:)
– xyz
Mar 31, 2016 at 8:53
• Yeah, is there any way for you to download the 10.3.1 upgrade? It's just a bugfix so it should be free Mar 31, 2016 at 8:57