summaryrefslogtreecommitdiffhomepage
path: root/host
diff options
context:
space:
mode:
authorNicolas Schodet2013-05-08 17:12:29 +0200
committerNicolas Schodet2013-05-08 17:12:29 +0200
commit83cae036d0f23c1c8ef54ef8ded67a130a235f72 (patch)
tree4b8c9c640f4b3fda4879e40320edb6520f9f4348 /host
parentd8166cc985d91855b71307d56e99eb2c3a6fb234 (diff)
host/simu/utils/vector: add vector rotate
Diffstat (limited to 'host')
-rw-r--r--host/simu/utils/vector.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/host/simu/utils/vector.py b/host/simu/utils/vector.py
index e5a8bd05..f865c576 100644
--- a/host/simu/utils/vector.py
+++ b/host/simu/utils/vector.py
@@ -223,6 +223,16 @@ class vector (object):
"""
return vector (-self.y, self.x)
+ def rotate (self, angle):
+ """Return the vector, rotated by given angle.
+
+ >>> vector (1, 2).rotate (math.pi / 2) # doctest: +ELLIPSIS
+ vector(-2.0, 1.0...)
+ """
+ c = math.cos (angle)
+ s = math.sin (angle)
+ return vector (c * self.x - s * self.y, s * self.x + c * self.y)
+
def angle (self):
"""Return angle from (1, 0).