Skip to content

Commit 95ea4dc

Browse files
committed
fin part2/ex1 also added things
1 parent c6704d5 commit 95ea4dc

File tree

1 file changed

+29
-0
lines changed
  • Programming_Assignments/part2/src/ex1

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import random
2+
from scipy.spatial import Voronoi, voronoi_plot_2d
3+
import numpy as np
4+
import matplotlib.pyplot as plt
5+
6+
7+
RANGE_XY = 100000
8+
def gen_points():
9+
num_points = int(input("Give number of Points to generate Voronoi Diagram: "))
10+
return np.array([[np.random.randint(0, RANGE_XY),np.random.randint(0, RANGE_XY)] for i in range(num_points)])
11+
12+
def compute_plot_voronoi(points):
13+
vor_diag = Voronoi(points)
14+
voronoi_plot_2d(vor_diag)
15+
plt.show()
16+
17+
def main():
18+
#generate random points
19+
try :
20+
points = gen_points()
21+
except:
22+
print("ERROR on generating random points")
23+
return
24+
25+
#compute/plot voronoi
26+
compute_plot_voronoi(points)
27+
28+
if __name__ == "__main__":
29+
main()

0 commit comments

Comments
 (0)