2
$\begingroup$

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?

$\endgroup$

2 Answers 2

6
$\begingroup$
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}

enter image description here

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

{2.05425*10^-6, 0.246728}

enter image description here

$\endgroup$
4
  • $\begingroup$ many thanks but there seems to be some typos could you fix them $\endgroup$
    – feynman
    Mar 12 at 8:28
  • $\begingroup$ 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? $\endgroup$
    – feynman
    Mar 12 at 10:00
  • 1
    $\begingroup$ @feynman If we using BoundaryDiscretizeGraphics,the region is solid. If we replace BoundaryDiscretizeGraphics with DiscretizeGraphics,the region is the hollow region. $\endgroup$
    – cvgmt
    Mar 12 at 10:08
  • $\begingroup$ thanks a million! you seem to have a redundant part of 'reg, AbsolutePointSize[10], Point[center]' (having it twice)? $\endgroup$
    – feynman
    Mar 12 at 10:52
5
$\begingroup$
$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
   }
 ]

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ 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 $\endgroup$
    – Bob Hanlon
    Mar 12 at 6:54
  • $\begingroup$ many thanks and may I confirm that by using == in ImplicitRegion, this centroid is that of the solid region or of the hollow region? $\endgroup$
    – feynman
    Mar 12 at 8:40
  • 1
    $\begingroup$ 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. $\endgroup$
    – Syed
    Mar 12 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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