diff options
| author | Raymond Hogenson <rayhogenson@openmailbox.org> | 2016-10-09 23:27:02 -0400 |
|---|---|---|
| committer | Raymond Hogenson <rayhogenson@openmailbox.org> | 2016-10-09 23:27:02 -0400 |
| commit | 2dd0795104b14fbb7aeee95f9f6bcf349f119960 (patch) | |
| tree | 4df0ebbb5172ecdf327e7afb28e8b1126a3600c4 /color.py | |
| parent | Merge (diff) | |
| parent | Realistic small fish movement (diff) | |
| download | bridge-2dd0795104b14fbb7aeee95f9f6bcf349f119960.tar.zst | |
Merge branch 'master' of github.com:rayhogenson/bridge
Diffstat (limited to 'color.py')
| -rw-r--r-- | color.py | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -7,7 +7,7 @@ class Vector(object): __slots__ = ('x', 'y', 'z') """3-dimensional vector class.""" - def __init__(self, x, y, z): + def __init__(self, x=0, y=0, z=0): """Create a vector from its components.""" self.x = x self.y = y @@ -40,6 +40,17 @@ class Vector(object): def __eq__(self, other): return self.x == other.x and self.y == other.y and self.z == other.z + def unit(self): + return self / abs(self) + + def rot2d(self, theta): + costheta = math.cos(theta) + sintheta = math.sin(theta) + new_x = self.x * costheta - self.y * sintheta + new_y = self.x * sintheta + self.y * costheta + return self.__class__(new_x, new_y) + + @property def components(self): return (self.x, self.y, self.z) |
