# Finding the centroid of a given curve

How to find Centroid of the following curve?

curve =
Plot[Cos[x]/(x + Log[x]), {x, 1, 8}, Ticks -> None, PlotStyle -> {Blue, Thick}] I tried:

Graphics[{curve, Red, Point[RegionCentroid[curve]]}]


but it doesn't work

• Have you tried with ParametricRegion[]? RegionCentroid[] works on regions (as the function name implies) and not on Graphics[] objects. Dec 19, 2016 at 11:28
• Though it does work on graphics primitives (second example in the RegionCentroid documentation) Dec 19, 2016 at 11:42

For those, who wonder what we would do without RegionCentroid, there is the simple way of calculating the centre by normal integration. When we consider your function $f$ as parametric curve the situation is clear.

$$x(t)=t\\y(t)=\frac{\cos(t)}{t+\log(t)}$$

Furthermore, we need the arc length $L(f)$ of the curve which can be calculated with

$$ds=\sqrt{x'(t)^2+y'(t)^2}\;dt$$

Then your centre $(x_m, y_m)$ is given by

$$x_m\cdot L(f)=\int x\;ds\qquad y_m\cdot L(f)=\int y\;ds$$

For your particular case this means the x-coordinate of your centroid is given by

$$x_m = \left(\int_1^8 t\; ds\right)/(\int_1^8ds)$$

In Mathematica code

x[t_] := t;
y[t_] := Cos[t]/(t + Log[t]);

ds = Sqrt[x'[t]^2 + y'[t]^2];

NIntegrate[{x[t], y[t]} ds, {t, 1, 8}]/NIntegrate[ds, {t, 1, 8}]

(* {4.38467, -0.00815125} *)

• It should be:NIntegrate[{x*Sqrt[1 + dydx^2], y[x]*Sqrt[1 + dydx^2]}, {x, 1, 8}]/ NIntegrate[Sqrt[1 + dydx^2], {x, 1, 8}] ,{4.38467, -0.00815125} Dec 19, 2016 at 12:38
• @MariuszIwaniuk I'm sorry. I didn't look it up. I'm fixing the post. Thanks for being attentive. Dec 19, 2016 at 12:59

To expand on J.M.'s comment, you will need to use the correct predicates to build the region (I used ImplicitRegion because I find it most flexible):

region = ImplicitRegion[y == (Cos[x]/(x + Log[x])) && x > 1 && x < 8, {x, y}];


Then you can use RegionCentroid on it:

centroid = RegionCentroid[DiscretizeRegion@region];
Show[RegionPlot[region], ListPlot[centroid], PlotLabel -> centroid] Simplest is the numerical approach for Graphics objects, which is to use DiscretizeGraphics:

curve = Plot[Cos[x]/(x + Log[x]), {x, 1, 8}, Ticks -> None, PlotStyle -> {Blue, Thick}];
RegionCentroid[DiscretizeGraphics[curve]]

{4.3846982827317245, -0.008143914969936251}


Note, while you can get lucky with analytical results too sometimes:

RegionCentroid[ParametricRegion[{x, x^2}, {{x, 1, 8}}]]


$$\left\{\frac{257 \sqrt{257}-5 \sqrt{5}}{3 \left(-2 \sqrt{5}+16 \sqrt{257}-\sinh ^{-1}(2)+\sinh ^{-1}(16)\right)},\frac{-18 \sqrt{5}+8208 \sqrt{257}+\sinh ^{-1}(2)-\sinh ^{-1}(16)}{16 \left(-2 \sqrt{5}+16 \sqrt{257}-\sinh ^{-1}(2)+\sinh ^{-1}(16)\right)}\right\}$$

Generally it is not the case: 