How to determine if a polygon is concave or convex?
<p>The user inputs nth points. I need to check if a polygon exists and then to determine the type - concave or convex polygon. I know that a polygon is convex if every of it's angles is under 180 degrees. So the problem comes down to finding every inside corner of the polygon. I've been searching for the formula or algorithm but with no success.</p>

<p><strong>Example:</strong></p>

<p>Input: n = 4;</p>

<p>Point1: (5;6)</p>

<p>Point2: (4;-5)</p>

<p>Point3: (-5;4)</p>

<p>Point4: (-5;5) </p>

<p>Expected output: Polygon is convex</p>

<p><a href="https://i.stack.imgur.com/WaqGz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WaqGz.jpg" alt="Example"></a></p>

<p>This is the code so far: Right now it only finds the max and minimum distance between the points in the plane.</p>

<pre><code>#include "stdafx.h"
#include &lt;iostream&gt;
using namespace std;

int main()
{
    double a[15][2];
    int n;
    cin &gt;&gt; n;
    if (n &lt;= 0 &amp;&amp; n &gt; 15)
        return 1;

    for (int i = 0; i &lt; n; i++)
    {
        cout &lt;&lt; "x" &lt;&lt; i &lt;&lt; " = , y" &lt;&lt; i &lt;&lt; " = ";
        cin &gt;&gt; a[i][0] &gt;&gt; a[i][1];
    }

    double maxDistance = 0.0;
    double minDistance = 0.0;
    double maxpoint1[2];
    double maxpoint2[2];
    double minpoint1[2];
    double minpoint2[2];

    for (int i = 0; i &lt; n; i++)
    {
        for (int j = 0; j &lt; n; j++)
        {
            if (j != i)
            {
                double x1 = a[i][0];
                double x2 = a[j][0];
                double y1 = a[i][1];
                double y2 = a[j][1];
                double currentDistance = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));

                if (currentDistance &gt; maxDistance)
                {
                    maxDistance = currentDistance;
                    maxpoint1[0] = x1;
                    maxpoint1[1] = y1;
                    maxpoint2[0] = x2;
                    maxpoint2[1] = y2;

                }

                if (minDistance &gt; currentDistance)
                {
                    currentDistance = minDistance;
                    minpoint1[0] = x1;
                    minpoint1[1] = y1;
                    minpoint2[0] = x2;
                    minpoint2[1] = y2;
                }

                cout &lt;&lt; "x1 = " &lt;&lt; x1 &lt;&lt; " y1 = " &lt;&lt; y1 &lt;&lt; " x2 = " &lt;&lt; x2 &lt;&lt; " y2 = " &lt;&lt; y2;
                cout &lt;&lt; endl &lt;&lt; "Distance is " &lt;&lt; currentDistance;
                cout &lt;&lt; endl;
            }
        }
    }

    cout &lt;&lt; "The max distance is: " &lt;&lt; maxDistance &lt;&lt; " between x1 = " &lt;&lt; maxpoint1[0] &lt;&lt; " y1 = " &lt;&lt; maxpoint1[1] &lt;&lt; " and x2 = " &lt;&lt; maxpoint2[0] &lt;&lt; " y2 = " &lt;&lt; maxpoint2[1];
    cout &lt;&lt; "The min distance is: " &lt;&lt; minDistance &lt;&lt; " between x1 = " &lt;&lt; minpoint1[0] &lt;&lt; " y1 = " &lt;&lt; minpoint1[1] &lt;&lt; " and x2 = " &lt;&lt; minpoint2[0] &lt;&lt; " y2 = " &lt;&lt; minpoint2[1];


    return 0;
}
</code></pre>