-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_points_generator.py
100 lines (63 loc) · 2.32 KB
/
random_points_generator.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import random as rd
import math as mth
from geometry import Circle, Rectangle
class Random:
@staticmethod
def generate_uniform_points(n=100, min_x = -100, max_x = 100, min_y = -100, max_y = 100):
T = []
for i in range( n ):
T.append((rd.uniform(min_x, max_x), rd.uniform(min_y, max_y)))
return T
@staticmethod
def generate_circle_points(n=100, circle = Circle((0, 0), 100)):
T = []
for i in range(n):
f = rd.uniform(0, 2) * mth.pi
x = circle.r * mth.cos(f) - circle.S[0]
y = circle.r * mth.sin(f) - circle.S[1]
T.append((x,y))
return T
@staticmethod
def generate_rectangle_points(n=100, rectangle = Rectangle((-10, 10), (10, 10), (10, -10), (-10, -10))):
T = []
a = rectangle.vertices[0]
b = rectangle.vertices[1]
c = rectangle.vertices[2]
d = rectangle.vertices[3]
v1 = (a[0] - b[0], a[1] - b[1])
v2 = (b[0] - c[0], b[1] - c[1])
v3 = (c[0] - d[0], c[1] - d[1])
v4 = (d[0] - a[0], d[1] - a[1])
for i in range(n):
x = rd.randint(1, 4)
y = rd.random()
if x ==1:
T.append( (b[0] + v1[0] * y, b[1] + v1[1] * y) )
elif x == 2:
T.append( (c[0] + v2[0] * y, c[1] + v2[1] * y) )
elif x == 3:
T.append( (d[0] + v3[0] * y, d[1] + v3[1] * y) )
else:
T.append( (a[0] + v4[0] * y, a[1] + v4[1] * y) )
return T
"""
def generate_square_points(a=(0, 0), b=(10, 0), c=(10, 10), d=(0, 10), axis_n=25, diag_n=20):
T = []
v1 = (a[0] - b[0], a[1] - b[1])
v2 = (d[0] - a[0], d[1] - a[1])
for i in range(axis_n):
y = rd.random()
T.append( (b[0] + v1[0] * y, b[1] + v1[1] * y) )
for i in range(axis_n):
y = rd.random()
T.append( (a[0] + v2[0] * y, a[1] + v2[1] * y) )
d1 = (b[0] - d[0], b[1] - d[1])
d2 = (a[0] - c[0], a[1] - c[1])
for i in range(diag_n):
y = rd.random()
T.append( (d[0] + d1[0] * y, d[1] + d1[1] * y) )
for i in range(diag_n):
y = rd.random()
T.append( (c[0] + d2[0] * y, c[1] + d2[1] * y) )
return T
"""