A school warm-up exercise to occupy your time - page 4

 
I take it that no one has solved the area of the polygon?
 
Maxim Kuznetsov:

Not directly related to trading, but interesting. Warm-up for the brain and keyboard at the weekend :-) It came up when I was doing maths with my kids and trying to teach them programming.

As you know, the area of a triangle can be calculated by the lengths of its three sides. For a polygon, alas, it is not so, but if the lengths of the sides are given, you can find the __maximal area__ of the figure with those sides.

Note a question: how it (maximal area of a polygon and angles adjacent to its sides) can be computed analytically and is the MT optimizer capable of such tricks ?

although this is rather just a curious problem for software solution, but may help with optimization: figure out what parameters to fix and within what limits to consider.

---

just compare the area found by the optimizer's brute force (and it will depend on the algorithm and what/how it is brute force) and the analytical solution, which is the only one.

Couldn't get past it :))
It seems to be not a very hard problem. Especially if solved by approximation method.
Sure it can be calculated simply by formula, but I don't want to bother with integrals and derivatives.
Besides the calculation speed (method of half division) of a hexagon takes 4 microseconds (light travels 1.2 km in this time) with accuracy of calculation of radius of the circle in which this polygon is inscribed, up to tenth decimal place. This is very excessive precision.


#include <Canvas\iCanvas.mqh> //https://www.mql5.com/ru/code/22164
#define  EPS 0.0000000001  // необходимая точность нахождения R

ulong t1;

void OnStart()
{
   double arr[]= {1,2,3,4,5,6};
   t1=GetMicrosecondCount();
   int size = ArraySize(arr);
   double max=arr[ArrayMaximum(arr)];
   double sum=0;
   for(int i=0; i<size; i++) sum+=arr[i];
   if (max>sum/2) {
      Print("Не существует многоугольника с таким набором сторон");
      return;
   }
   double R_max=sum/4;
   double R_min=max/2;
   double R=0;
   double delta=1;
   while(fabs(delta)>EPS) {
      double a=0;
      R=(R_max+R_min)/2;
      for(int i=0; i<size; i++) a+=2*asin(arr[i]/(2*R));
      delta = a-2*M_PI;
      if (delta>0) R_min=R;
      else R_max=R;
   }
   t1=GetMicrosecondCount()-t1;
   DrawFigure(arr,R);
   Sleep(20000);
}
//+------------------------------------------------------------------+
void DrawFigure(double &arr[],double r)
{
   Canvas.Erase();
   int size = ArraySize(arr);
   int x0=_Width/2;
   int y0=_Height/2;
   double k=(y0-10.0)/r;
   Canvas.Circle(x0,y0,Round(r*k),0xFF0000FF);
   double a=0;
   double S=0;
   for(int i=0; i<size; i++) {
      double b=2*asin(arr[i]/(2*r));
      Canvas.FillTriangle(x0,y0,Round(x0+cos(a)*r*k),Round(y0+sin(a)*r*k),Round(x0+cos(a+b)*r*k),Round(y0+sin(a+b)*r*k),Canvas.Grad(double(i)/(size-1)));
      S+=r*r*sin(b)/2;
      a+=b;
   }
   Canvas.CurentFont("Arial",40,50);
   _CommXY(100,100,"Время расчета = "+string(t1)+" микросекунд");
   _Comment("Радиус окружности = " + DoubleToString(r));
   _Comment("Макс площадь фигуры = " + DoubleToString(S,5));
   Canvas.Update();
}
//+------------------------------------------------------------------+
Files:
Zadacha.mq5  5 kb
iCanvas.mqh  47 kb
 
double arr[]= {1, 2, 3, 4, 5, 6, 4.1, 8.5, 4.1, 3.4, 7, 4.7, 3.2};

13 Angle.

 
Nikolai Semko:

Couldn't get past it :))
It doesn't seem to be a very difficult problem. Especially if you solve it by approximation.
I'm sure it can be calculated simply by formula, but I don't want to bother with integrals and derivatives.
Besides the calculation speed (method of half division) of a hexagon takes 4 microseconds (light travels 1.2 km in this time) with accuracy of calculation of radius of the circle in which this polygon is inscribed, up to tenth decimal place. This is very excessive precision.


1) The difficulty in proving the fact that the vertices of the maximal area mn must lie on the same circle (Cramer's theorem). I don't know how to prove it or where to read the proof.

2) I don't really believe in the existence of analytical formula for maximal area or radius of a circle.

3) The sum of array elements can be calculated by MathSum()

 
Programmatically, even a schoolboy can solve it. The sporting interest is in deriving the formula.
 
Aleksey Nikolayev:

...

2) I don't really believe in the existence of an analytical formula for the maximum area or for the radius of a circle.

...

Trying... (I can't get a stone flower yet))

 
Nikolai Semko:

13-corner.

you can also use Heron's formula.

void DrawFigure(double &arr[],double r) {
  Canvas.Erase();
  int size = ArraySize(arr);
  int x0=_Width/2;
  int y0=_Height/2;
  double k=(y0-10.0)/r;
  Canvas.Circle(x0,y0,Round(r*k),0xFF0000FF);
  double a=0;
  double S=0;
  for(int i=0; i<size; i++) {
    //double b=2*asin(arr[i]/(2*r));   
    //Canvas.FillTriangle(x0,y0,Round(x0+cos(a)*r*k),Round(y0+sin(a)*r*k),Round(x0+cos(a+b)*r*k),Round(y0+sin(a+b)*r*k),Canvas.Grad(double(i)/(size-1)));
    //S+=r*r*sin(b)/2;
    //a+=b;
    
    double p = (2*r + arr[i])/2;//полупериметр треугольника   
    S += MathSqrt(p*MathPow(p-r,2)*(p-arr[i])); //формула Герона  
    
  }
  Canvas.CurentFont("Arial",40,50);
  _CommXY(100,100,"Время расчета = "+string(t1)+" микросекунд");
  _Comment("Радиус окружности = " + DoubleToString(r));
  _Comment("Макс площадь фигуры = " + DoubleToString(S,5));
  Canvas.Update();
}

you need

Canvas.Grad
 
Площадь многоугольника
Площадь многоугольника
  • matematikalegko.ru
Площадь многоугольника Площадь многоугольника. Друзья! К вашему вниманию пару задачек с многоугольником и вписанной в него окружностью. Существует формула, которой связывается радиус указанной окружности и периметр с площадью такого многоугольника. Вот она: Как выводится эта формула? Просто! Имеем многоугольник и вписанную окружность...
 
Площадь
  • algolist.ru
Утверждение: площадь многоугольника - замкнутой ломаной без самопересечений, заданной своими вершинами в порядке обхода, вычисляется по формуле: Пусть требуется определить площадь полигона A 1 , A 2 , A 3 , A 4 , A 5 с координатами вершин x 1 ,y 1 ; x 2 ,y 2 ; x 3 ,y 3 ; x 4 ,y 4 ; x 5 ,y 5 . Площадь полигона S можно представить трапециями, у...
 
Iurii Tokman:

need

Canvas.Grad

Oops, sorry. Updated the QB.

Files:
iCanvas.mqh  47 kb