How to apply $\overline{r}(x,y)$ to shapes with straight lines or absolute values?

I am studying the maxima of function $\overline{r}(x,y)$ of closed shapes.

Suppose the curve is star-shaped with respect to this center point $\mathbf p=(u,v)$, so that any ray emanating from $\mathbf p$ meets the curve exactly once, at say point $\mathbf q$. Then $r = \|\mathbf q - \mathbf p\|$, $\theta$ is the angle between $\mathbf q-\mathbf p$ and the $x$-axis, $\overline{r}(x,y)$ is the average radius $$\overline{r}(x,y)=\frac1{2\pi}\oint_{\mathbf q\in\mathcal C}\|\mathbf q-\mathbf p\|\,\mathrm d\theta.$$

and $\mathbf{p}$ is the point maximizing $\overline{r}$.

(Conveniently, this integral can also be computed for non-star-shaped curves; for a ray that meets the curve multiple times, it amounts to taking the total length of all segments that lie in the interior of the curve.)

In a previous answer, using Mesh Coordinates, Discretization, and Euler's Distance, I could calculate the maxima $\mathbf{p}$ of $\overline{r}(x,y)$.

curve = DiscretizeRegion[
ImplicitRegion[
S1[x, y] == 1, {{x, -3, 3}, {y, -4, 4}}], {{-3, 3}, {-4, 4}},
AccuracyGoal -> 8]
q = MeshCoordinates[curve];
edges = First /@ MeshCells[curve, 1];
signedAngle[a_, b_] := Arg[(Complex @@ a)/(Complex @@ b)]
1/(2 \[Pi]) Abs[Sum[Module[{q1, q2, r, d\[Theta]}, q1 = q[[First@e]];
q2 = q[[Last@e]];
r = EuclideanDistance[p, (q1 + q2)/2];(*midpoint approximation*)
d\[Theta] = signedAngle[q1 - p, q2 - p];
r d\[Theta]], {e, edges}]]
s = FindMaximum[avgRadius[{x, y}], {{x, 0}, {y, 0}}]

However, I wanted to apply a similar definition to closed shapes that contain straight lines.

Shapes With Straight Lines: Polygons

For example, for a triangle with vertices $(-1,0)$, $(0,1)$ and $(1,0)$, if I apply DescritizeRegion

curve = DiscretizeRegion[
Line[{{-1, 0}, {0, 1}, {1, 0}, {-1, 0}}]], {{-1, 1}, {-1,
1}}, AccuracyGoal -> 8]

instead of showing the discretized region it gives the following.

DiscretizeRegion::regp: A correctly specified region expected at position 1 of DiscretizeRegion[,{{-1,1},{-1,1}},AccuracyGoal->8].

Assuming the positions should be labelled, I used BoundaryMeshRegion

curve = DiscretizeRegion[
BoundaryMeshRegion[{{-1, 0}, {0, 1}, {1, 0}},
Line[{1, 2, 3, 1}]], {{-1, 1}, {0, 1}}, AccuracyGoal -> 8]

but instead of descritizing the boundary, its descritizes the area.

How do I apply $\overline{r}(x,y)$ to the triangle? Similarily how would apply this to a dumbell shaped curve?

• Note that Graphics is not a region. You can discretize the 1-dimensional line by removing the Graphics[...] and just using DiscretizeRegion[ Line[{{-1, 0}, {0, 1}, {1, 0}, {-1, 0}}], AccuracyGoal -> 8]. Jan 2, 2018 at 5:16
• @eyorble I tried that but I get DiscretizeRegion::regp: A correctly specified region expected at position 1 of DiscretizeRegion[Line[{-1,0},{0,1},{1,0},{-1,0}],{{-2,2},{-2,2}},AccuracyGoal->4]. Jan 2, 2018 at 14:03
• As far a I know, there is no dedicated method in Mathematica to discretize a non-fulldimensional MeshRegion. However, even being not the most efficient way and having requirement that the curve has to be closed, you can use curve = BoundaryMesh@ DiscretizeRegion[ BoundaryMeshRegion[{{-1, 0}, {0, 1}, {1, 0}}, Line[{1, 2, 3, 1}]], {{-1, 1}, {0, 1}}] Jan 2, 2018 at 16:10
• That's not an issue of the discretization but of division by zero. That happens because the initial guess for FindMinimum is {0,0} which happens to lie on the curve. Try s = FindMaximum[avgRadius[{x, y}], {{x, 0.1}, {y, 0.1}}] instead. Jan 2, 2018 at 17:31
• @Arbuja I am not sure that increaing AccuracyGoal in DiscretizeRegion is the right way to achieve higher accuracy here; the error of your method is proportional to the maximal edge length of curve. You can control the maximal edge length with MaxCellMeasure->{1->len} (1 stands for 1-dimensional cells, len for the maximal length you allow). Anyway, using DiscretizeRegion and applying BoundaryMesh on the result is a very expensive way to get a finely smapled curve. See my aanswer below for a more performant approach. Jan 2, 2018 at 20:44

Here is another way to specify a one-dimensional region:

γ = t \[Function] {Cos[t], Sin[t]} (1. + 0.25 Sin[5 t]);
n = 1000;
pts = Table[γ[t], {t, 0, 2 Pi, 2 Pi/n}];
curve = MeshRegion[pts, Line[Transpose[{Range[1, n], Range[2, n + 1]}]]];

It circumvents the need for DiscretizeRegion. You can adapt that also for triangles: Simply parameterize and sample the boundary pieces and use Join to create a single list of points. Your procedure for finding the point of maximal avarage ray length will work quite likely on regions defined this way.

• @HendrickSchumacer You can’t use any parametrization. For example, consider a ellipse with parametric curve $(2\cos{(t)},3\sin({t}))$ gives a different average distance then $(\frac{6\cos{(t)}}{\sqrt{4\cos^{2}(t)+9\sin^{2}(t)}},\frac{6\sin{(t)}}{\sqrt{4\cos^{2}(t)+9\sin^{2}(t)}})$ Jan 3, 2018 at 13:01
• @Arbuja Why on earth should the average distance (or average ray length) depend on the parameterization parameter t? Really, could you please think about the problem a bit more thoroughly before asking the next time? Jan 3, 2018 at 17:07
• @HenrikSchmacer I never said the average distance must depend on t. What I'm saying is if you parameterize the curve, the distance formula of some parametrizations give the incorrect average radius. Jan 3, 2018 at 18:45
• @HenrikSchumacer How come you graphed $r=1+0.25\sin{(5\theta)}$. Can your code work for non-polar equations. Jan 3, 2018 at 18:48
• @Arbuja This may work for any other sufficiently smooth and regular curve. I chose to use a curve in polar coordinates just for convenience. Jan 3, 2018 at 20:44