SharedPolygon sampling.sagewsOpen in CoCalc
Code for generating random polygons
from numpy import random, cumsum # Import the cumulative sum and random functions from numpy

n = 12 # Set the number of edges

M = matrix(random.normal(0,1,(2,n))) # 2xn matrix with standard Gaussian entries

G, mu = M.gram_schmidt() # G is the result of applying Gram-Schmidt to the rows of M

w = G[0] + I*G[1] # Convert G to a list of complex numbers

e = [z^2 for z in w] # Square each complex number in the list; this gives the edges of the polygon

v = vector(cumsum(e)) # The vertices of the polygon are the cumulative sums of the edge vectors

rv = [[z.real(), z.imag()] for z in v] # Convert vertices from complex numbers to points in R^2 for display purposes

polygon2d(rv, color='black', fill=False) # Display polygon