# RegionCentroid issue

This example shows an unexpected result from RegionCentroid:

object =
Polygon[
{{20000, 200000}, {20000.1, 200000.2}, {20000.3, 200000.2}, {20000., 200000.}}];
point = Point[RegionCentroid[object]];
Show[Graphics[{object, Red, PointSize[.2], point}]]


The RegionCentroid result should be inside the convex region.

When the object is translated to the origin the result is correct. Any idea for a general solution or workaround for arbitrary regions?

Your issue is basically a numerics problem. If you were to do the computations exactly, there would be no problem.

obj =
Polygon[
{{20000, 200000}, {20000 + 1/10, 200000 + 2/10},
{20000 + 3/10, 200000 + 2/10}, {20000, 200000}}];

pt = Point[RegionCentroid[obj]]

Point[{300002/15, 3000002/15}]

Graphics[{obj, Red, AbsolutePointSize[8], pt}, Frame -> True]


• yes, looks like an accuracy issue inside RegionCentroid. The translated object Polygon[{{0, 0}, {0.1, 0.2}, {0.3, 0.2}, {0, 0}}] works fine. – Ali Nov 4 '18 at 20:45
• @Ali As another alternative to symbolic numbers you can also use arbitrary precision numbers via 20000.150 (will give 50 digits of precision) or via SetPrecision[20000.1,50]. Just using machine precision numbers implicitly (by just writing 20000.1) is considered intended behaviour and not an issue or bug. It's essentially a tradeoff between precision and computation time. See here for more info on this. – Thies Heidecke Nov 4 '18 at 22:44
• @Thies: Thanks, using Polygon[SetPrecision[{...},20]]` indeed solves the issue in a general way. – Ali Nov 5 '18 at 21:16