-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobstacles.py
37 lines (29 loc) · 960 Bytes
/
obstacles.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
import matplotlib.pyplot as plt
import matplotlib.patches as pch
import numpy as np
import random
class Obstacles:
np.random.seed(42)
def __init__(self, D):
self.obstacles = []
self.D = D
self.num_obs = 25
def generate_obs(self, rad, axes):
coords = (random.randrange(self.D), random.randrange(self.D))
c = pch.Circle(coords, rad, color="black", zorder=2)
self.obstacles.append(c)
def plot_obs(self, axes):
for c in self.obstacles:
axes.add_artist(c)
def create_set(self, axes):
for _ in range(self.num_obs):
rad = random.randrange(15)
self.generate_obs(rad, axes)
def check_collision(self, point):
for o in self.obstacles:
tf = o.get_data_transform().transform(point)
if o.contains_point(tf):
return True
return False
def get_obs(self):
return self.obstacles