-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorld.py
More file actions
34 lines (28 loc) · 1009 Bytes
/
Copy pathWorld.py
File metadata and controls
34 lines (28 loc) · 1009 Bytes
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
import numpy as np
class World:
def __init__(self, n_landmarks=20, size=10.0, seed=None, layout='random'):
if seed is not None:
np.random.seed(seed)
self.size = size
self.layout = layout
self.landmarks = self.generate_landmarks(n_landmarks)
def generate_landmarks(self, n):
if self.layout == 'circle':
center_x = self.size / 2.0
center_y = self.size / 2.0
radius = self.size * 0.4
landmarks = []
for i in range(n):
theta = 2.0 * np.pi * i / n
x = center_x + radius * np.cos(theta)
y = center_y + radius * np.sin(theta)
landmarks.append([x, y])
return np.array(landmarks)
else:
return np.random.uniform(
low=0.0,
high=self.size,
size=(n, 2)
)
def get_landmarks(self):
return self.landmarks