For a certain demo application, I want to create at random a rectilinear polygon with a given number of corners.
Selecting random $x$ and $y$ coordinates of each corner is not a good method, since most polygons selected in this way will not be rectilinear.
So, I thought of selecting $x$ and $y$ coordinates of each second corner. For example, if the random corners happen to be:
(0,0), (10,10), (20,20)
then I convert them to an L-shaped hexagon with corners:
(0,0), (10,0), (10,10), (20,10), (20,20), (0,20)
The problem is, this method sometimes yields non-polygons. For example, if the random corners are:
(0,30), (10,10), (20,20)
then the result is the following 8-shape, which is not a polygon at all:
(0,30), (10,30), (10,10), (20,10), (20,20), (0,20).
MY QUESTION: Is there a way to select $x$ and $y$ coordinates such that the result is always a polygon?
NOTE: The randomness is only for demonstration purposes. I.e, the polygons should be sufficiently random such that the user sees a different polygon each time, but it doesn't have to be uniformly random. So, if there is a way to select some numbers at random, and then modify them in some way so as to get a rectilinear polygon, this is fine.
I guess that instead of generating half the corners in sequence, I'd generate a bunch of overlapping rectangles (each defined by two of its four corners) and then define the resulting polygon to be the union of all these.
If the number of corners is a strong requirement, you might have to either loop or tune things towards the end to make sure it's actually met, since adding a rectangle can add up to four corners, but can even remove all but four corners, and anything in between.