summaryrefslogtreecommitdiff log msg author committer range
diff options
 context: 12345678910152025303540 space: includeignore mode: unifiedssdiffstat only
author committer Nicolas Schodet 2011-10-15 21:11:28 +0200 Nicolas Schodet 2011-10-15 21:11:28 +0200 46e9274161ff1f964ffa70970c4f43947b7bc951 (patch) 3cf4a4021415493f2f0aba1bff079e7fd693e9fb 677dbdcc67d976cbf2040dad32b5a4600f233eaf (diff)
host/simu/model: use vector class in round obstacle
-rw-r--r--host/simu/model/round_obstacle.py17
1 files changed, 10 insertions, 7 deletions
 diff --git a/host/simu/model/round_obstacle.py b/host/simu/model/round_obstacle.pyindex 6658ed19..e749440b 100644--- a/host/simu/model/round_obstacle.py+++ b/host/simu/model/round_obstacle.py@@ -24,6 +24,7 @@ """Obstacle with a round shape.""" from math import pi, cos, sin, sqrt from utils.observable import Observable+from simu.utils.vector import vector class RoundObstacle (Observable): @@ -38,17 +39,19 @@ class RoundObstacle (Observable): to intersection point, else, return None.""" if self.pos is None: return None- ab = sqrt ((b - a) ** 2 + (b - a) ** 2) # distance AB.- n = ((b - a) / ab, (b - a) / ab) # vector of length 1.- o = self.pos # obstacle center.+ a, b = vector (a), vector (b)+ vab = b - a+ ab = abs (vab) # distance AB.+ n = vab.unit () # vector of length 1.+ o = vector (self.pos) # obstacle center. # To check if the line (AB) intersects the circle, compute distance # from circle center to line using a dot product.- vao = (o - a, o - a) # vector AO.- # dot product, (-n, n) is perpendicular to n.- doc = abs (vao * -n + vao * n)+ vao = o - a # vector AO.+ # abs of dot product.+ doc = abs (vao * n.normal ()) if doc < self.radius: # Line intersects, check if segment intersects.- m = vao * n + vao * n+ m = vao * n f = sqrt (self.radius ** 2 - doc ** 2) if m - f > 0 and m - f < ab: return m - f