summaryrefslogtreecommitdiffhomepage
path: root/host/simu/utils/vector.py
diff options
context:
space:
mode:
Diffstat (limited to 'host/simu/utils/vector.py')
-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).