How to generate a random convex polygon?

前端 未结 6 1232
南旧
南旧 2021-02-05 11:19

I\'m trying to devise a method for generating random 2D convex polygons. It has to have the following properties:

  • coordinates should be integers;
  • the poly
6条回答
  •  無奈伤痛
    2021-02-05 11:49

    A simple algorithm would be:

    1. Start with random line (a two vertices and two edges polygon)
    2. Take random edge E of the polygon
    3. Make new random point P on this edge
    4. Take a line L perpendicular to E going through point P. By calculating intersection between line T and lines defined by the two edges adjacent to E, calculate the maximum offset of P when the convexity is not broken.
    5. Offset the point P randomly in that range.
    6. If not enough points, repeat from 2.

提交回复
热议问题