summaryrefslogtreecommitdiff
path: root/host/simu/model/round_obstacle.py
diff options
context:
space:
mode:
authorNicolas Schodet2009-04-30 23:59:34 +0200
committerNicolas Schodet2009-04-30 23:59:34 +0200
commit5039808c1c648f3aedf81e9e5fc2762d38c4d171 (patch)
treee97c208423af0d0293c042560d1408e364cb2566 /host/simu/model/round_obstacle.py
parent44d514491bcfaf34d207dc5e172349bea0f4d7b7 (diff)
* digital/io/tools, host/simu:
- added distance sensors and obstacles.
Diffstat (limited to 'host/simu/model/round_obstacle.py')
-rw-r--r--host/simu/model/round_obstacle.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/host/simu/model/round_obstacle.py b/host/simu/model/round_obstacle.py
index fc0cfc6a..6658ed19 100644
--- a/host/simu/model/round_obstacle.py
+++ b/host/simu/model/round_obstacle.py
@@ -23,10 +23,12 @@
# }}}
"""Obstacle with a round shape."""
from math import pi, cos, sin, sqrt
+from utils.observable import Observable
-class RoundObstacle:
+class RoundObstacle (Observable):
def __init__ (self, radius, level = 0):
+ Observable.__init__ (self)
self.pos = None
self.radius = radius
self.level = level
@@ -34,6 +36,8 @@ class RoundObstacle:
def intersect (self, a, b):
"""If the segment [AB] intersects the obstacle, return distance from a
to intersection point, else, return None."""
+ if self.pos is None:
+ return None
ab = sqrt ((b[0] - a[0]) ** 2 + (b[1] - a[1]) ** 2) # distance AB.
n = ((b[0] - a[0]) / ab, (b[1] - a[1]) / ab) # vector of length 1.
o = self.pos # obstacle center.