-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgo#2.py
43 lines (34 loc) · 1.16 KB
/
algo#2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import math, random
from shapely.geometry import Point
from shapely.geometry.polygon import Polygon
import pandas as pd
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt
def genPolygon( X, Y, radius, irregular, spike, n) :
irregular = irregular* 2*math.pi / n
spike = spike * radius
# generate n angle between the random limits
angles = []
low = (2*math.pi / n) - irregular
high = (2*math.pi / n) + irregular
for i in range(n) :
temp = random.uniform(low, high)
angles.append( temp )
#adding first vertice to end of list to make a closed polygon.
angles.append(angles[0])
#generating points
points = []
angle = random.uniform(0, 2 * math.pi)
for i in range(n) :
r_i = random.gauss(radius, spike)
x = X + r_i*math.cos(angle)
y = Y + r_i*math.sin(angle)
points.append((x,y))
angle = angle + angles[i]
return points
verts = genPolygon( X=50, Y=100, radius=400, irregular=0.2, spike=0.03, n=100 )
pa = Polygon(verts)
print(pa.wkt)