title: How to draw a polygon in C++ such that the lines do not intersect?
body: <p>I need to draw a polygon in C++.  I set random points in vector and then connect them via lines. But sometimes those lines intersect and i get something like this.</p>
  
  <p><img src="https://i.stack.imgur.com/D5CA9.jpg" alt="enter image description here"></p>
  
  <p>Is there any formula or something like that, so that the lines wouldn't cross?</p>
  
  <p>Here is part of the code: </p>
  
  <pre><code>void draw_picture(Canvas &amp; canvas) {
    PairXY a,b,c,d,e;
    int k;
    vector &lt;PairXY&gt; vertex;
    vertex.push_back(PairXY(drandom(k),drandom(k)));
    vertex.push_back(PairXY(drandom(k),drandom(k)));
    vertex.push_back(PairXY(drandom(k),drandom(k)));
    vertex.push_back(PairXY(drandom(k),drandom(k)));
    vertex.push_back(PairXY(drandom(k),drandom(k)));
  
    vector &lt;PairXY&gt;::const_iterator iter;
  
    iter = vertex.begin();
    a=*iter;
    iter = vertex.begin()+1;
    b=*iter;
    iter = vertex.begin()+2;
    c=*iter;
    iter = vertex.begin()+3;
    d=*iter;
    iter = vertex.begin()+4;
    e=*iter;
  
    Line l1(a,b);
    draw_line(l1,canvas);
    Line l2(b,c);
    draw_line(l2,canvas);
    Line l3(c,d);
    draw_line(l3,canvas);
    Line l4(d,e);
    draw_line(l4,canvas);
    Line l5(e,a);
    draw_line(l5,canvas);
  }
  </code></pre>