From 5039808c1c648f3aedf81e9e5fc2762d38c4d171 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Thu, 30 Apr 2009 23:59:34 +0200 Subject: * digital/io/tools, host/simu: - added distance sensors and obstacles. --- host/simu/model/round_obstacle.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'host/simu/model/round_obstacle.py') 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. -- cgit v1.2.3