# Centroid of an implicitly defined plane region

An implicit curve could be something such as:

$$(x/exp(y))^2+y^2=1,$$

Code:

(x/Exp[y])^2 + y^2 == 1

which is the boundary of a plane region. How can its centroid be found?

plot = ContourPlot[(x/Exp[y])^2 + y^2 == 1, {x, -2, 2}, {y, -2, 2}];
solid = BoundaryDiscretizeGraphics[plot];
solidcenter = RegionCentroid[solid]
solidgraph =
Graphics[{FaceForm[Directive[Green, Opacity[.2]]],
EdgeForm[Directive[Brown, AbsoluteThickness[5]]], solid, Red,
Point[solidcenter]}]

{-0.0000145217, 0.24011}

hollow = DiscretizeGraphics[plot];
hollowcenter = RegionCentroid[hollow]
hollowgraph =
Graphics[{{PointSize[0], hollow}, Red, Point[hollowcenter]}]

{2.05425*10^-6, 0.246728}

• many thanks but there seems to be some typos could you fix them Commented Mar 12, 2023 at 8:28
• many thanks for the correction and may I confirm that by using == in ContourPlot, this centroid is that of the solid region or of the hollow region? Commented Mar 12, 2023 at 10:00
• @feynman If we using BoundaryDiscretizeGraphics，the region is solid. If we replace BoundaryDiscretizeGraphics with DiscretizeGraphics,the region is the hollow region. Commented Mar 12, 2023 at 10:08
• thanks a million! you seem to have a redundant part of 'reg, AbsolutePointSize[10], Point[center]' (having it twice)? Commented Mar 12, 2023 at 10:52
\$Version

"12.2.0 for Microsoft Windows (64-bit) (December 12, 2020)"

reg = ImplicitRegion[(x/Exp[y])^2 + y^2 == 1, {x, y}];
ctr = RegionCentroid[reg];
ContourPlot[(x/Exp[y])^2 + y^2 == 1, {x, -2, 2}, {y, -2, 2}
, Epilog -> {
Red, AbsolutePointSize[6]
, Point@ctr
}
]

• You should indicate which version you used. On my Mac, this works with v13.0.1 but not v13.1, v13.2, or v13.2.1 Commented Mar 12, 2023 at 6:54
• many thanks and may I confirm that by using == in ImplicitRegion, this centroid is that of the solid region or of the hollow region? Commented Mar 12, 2023 at 8:40
• Define: reg2 = ImplicitRegion[(x/Exp[y])^2 + y^2 <= 1, {x, y}] and plot: RegionPlot[reg2 , PlotRange -> {{-2, 2}, {-2, 2}} , Epilog -> {Red, AbsolutePointSize[6], Point@RegionCentroid[reg2]} ] to see the difference.
– Syed
Commented Mar 12, 2023 at 8:46