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

后端 未结 4 2082
天命终不由人
天命终不由人 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:31

    Here is a flexible and efficient way to generate convex polygon : -

    1. Generate random points on the circle at center point (xc,yc)
    2. tweak any point (xi,yi) in sequence of consecutive points
    3. check if (x(i-1),y(i-1)) , (xi,yi) , (x(i+1),y(i+1)) form a left turn else reject the tweak.

    if points are arranged in anti clockwise manner then left turn at point (x2,y2) :-

    int crosspro = (x3-x2)*(y2-y1) - (y3-y2)*(x2-x1) 
    
    if(crosspro>0) return(left_turn);
    
    else return(right_turn);
    

提交回复
热议问题