How to generate random vertices to form a convex polygon in c++?

后端 未结 4 2080
天命终不由人
天命终不由人 2021-01-05 02:46

I need to generate a set of vertices for a simple convex polygon to do a minimum weight triangluation for that polygon using dynamic programming , I thought about taking a c

4条回答
  •  清酒与你
    2021-01-05 03:25

    Generate your 20 random numbers between 0 and 2*pi, and sort them.

    Now use a little basic trigonometry to convert to X,Y coordinates.

    for (int i = 0; i < 20; i++)
    {
        x = x0 + r*cos(angle[i]);
        y = y0 + r*sin(angle[i]);
        // ...
    }
    

提交回复
热议问题