# Is there a Bug in Mathematica 11.1 with RegionCentroid?

Bug introduced in 11.1 and fixed in 11.2.0

I solved for the centroid of $x^2+y^2+\sin(4x)+\sin(4y)=4$

J = RegionCentroid[
DiscretizeRegion[
ImplicitRegion[
x^2 + y^2 + Sin[4*x] + Sin[4*y] == 4, {{x, -3, 3}, {y, -3, 3}}],
AccuracyGoal -> 8]]


But end up with

{-1.90037, 0.230247}

With a lower accuracy

J = RegionCentroid[
DiscretizeRegion[
ImplicitRegion[
x^2 + y^2 + Sin[4*x] + Sin[4*y] == 4, {{x, -3, 3}, {y, -3, 3}}],
AccuracyGoal -> 4]]


I still get

{-1.90035, 0.230246}


Which makes no sense.

Edit

DescretizeRegion doesn't work without adding bounds {{-3,3},{-3,3}}

DiscretizeRegion[
ImplicitRegion[
x^2+y^2+Sin[4x]+Sin[4y]==4, {{x, -3, 3}, {y, -3, 3}}], {{-3,
3}, {-3, 3}}, AccuracyGoal -> 8]


This was presented in a previous question

However, with RegionCentroid I still get

{-1.90037, 0.230247}

• Please only tag things [bugs] if they've been confirmed by WRI. It's a community standard, but makes our lives better. Jan 14 '18 at 0:30
• Your AccuracyGoal is throwing things off. The curve is over-discretized. Drop it and it'll work for you. Jan 14 '18 at 0:36
• I tried that but it didn't work. I get {-1.90035, 0.230246} Jan 14 '18 at 0:38
• Bug as heck - all proposed solutions, and the OP's code, work fine on v10.4; v11.1 messes things up. Adding the tag. Jan 14 '18 at 6:58
• I reproduce the issue with version 11.1.1 on Windows 7 x64. Version 10.4.1 and 11.2.0 produce the expected result: {-0.108616, -0.108616}. So the bug was introduced in version 11.1 and fixed in 11.2.0. Added the bug header. Jan 15 '18 at 0:53

## 2 Answers

DescretizeRegion works fine

I cannot reproduce this. To me, it seems that the bug lies clearly with the DiscretizeRegion function:

\$Version
DiscretizeRegion[
ImplicitRegion[
x^2 + y^2 + Sin[4*x] + Sin[4*y] == 4, {{x, -3, 3}, {y, -3, 3}}]]
(* "11.1.1 for Mac OS X x86 (64-bit) (May 30, 2017)" *)


Given the above region, RegionCentroid is behaving properly,

Show[%, Graphics @ Point @ RegionCentroid@%]


On MacOS, this bug is fixed in version 11.2

• Actually, with DescretizeRegion I added the bounds {{-3,3},{-3,3}] to DiscretizeRegion[ ImplicitRegion[ S16[x, y] == 0.4, {{x, -2.5, 1}, {y, -2.5, 2.5}}], {{-2.5, 1}, {-2.5, 2.5}}, AccuracyGoal -> 8]  but with RegionCentroid this does not work. Jan 14 '18 at 21:42
• This was mentioned in my previous question Jan 14 '18 at 21:44
• Never mind, in my first comment, RegionCentroid does work but still gives the incorrect output. Jan 14 '18 at 21:56
• I get the correct output from your DescretizeRegion code with versions 10.0.1, 10.4.1, 11.1.1 and 11.2.0 on Windows 7 x64. The behavior seems to be platform-dependent. Jan 15 '18 at 0:46

Try <=4

    r = ImplicitRegion[x^2 + y^2 + Sin[4*x] + Sin[4*y] <= 4, {x, y}];
center = RegionCentroid[DiscretizeRegion[r]];
Show[RegionPlot[r, PlotRange -> {{-3, 3}, {-3, 3}}], Graphics[Point@center]]

center={-0.0848068, -0.084911}


• Can you even reproduce the original issue? I can't. Jan 14 '18 at 0:44
• Can you get the coordinates? Jan 14 '18 at 0:46
• coordinates is RegionCentroid[DiscretizeRegion[r]] Jan 14 '18 at 0:47
• RegionCentroid[ DiscretizeRegion[ ImplicitRegion[ x^2 + y^2 + Sin[4*x] + Sin[4*y] == 4, {{x, -3, 3}, {y, -3, 3}}]]] produces {-1.89998, 0.230282} on my machine with MMA 11.1 Jan 14 '18 at 0:48
• @OkkesDulgerci I get the same with version 11.1.1 on Windows 7 x64. Version 11.2.0 produces {-0.108357, -0.108372}. Jan 15 '18 at 0:56