Back to index

python3.2  3.2.2
Public Member Functions
turtle.Vec2D Class Reference

List of all members.

Public Member Functions

def __new__
def __add__
def __mul__
def __rmul__
def __sub__
def __neg__
def __abs__
def rotate
def __getnewargs__
def __repr__

Detailed Description

A 2 dimensional vector class, used as a helper class
for implementing turtle graphics.
May be useful for turtle graphics programs also.
Derived from tuple, so a vector is a tuple!

Provides (for a, b vectors, k number):
   a+b vector addition
   a-b vector subtraction
   a*b inner product
   k*a and a*k multiplication with scalar
   |a| absolute value of a
   a.rotate(angle) rotation

Definition at line 236 of file turtle.py.


Member Function Documentation

def turtle.Vec2D.__abs__ (   self)

Definition at line 265 of file turtle.py.

00265 
00266     def __abs__(self):
        return (self[0]**2 + self[1]**2)**0.5
def turtle.Vec2D.__add__ (   self,
  other 
)

Definition at line 252 of file turtle.py.

00252 
00253     def __add__(self, other):
        return Vec2D(self[0]+other[0], self[1]+other[1])

Definition at line 274 of file turtle.py.

00274 
00275     def __getnewargs__(self):
        return (self[0], self[1])
def turtle.Vec2D.__mul__ (   self,
  other 
)

Definition at line 254 of file turtle.py.

00254 
00255     def __mul__(self, other):
00256         if isinstance(other, Vec2D):
00257             return self[0]*other[0]+self[1]*other[1]
        return Vec2D(self[0]*other, self[1]*other)
def turtle.Vec2D.__neg__ (   self)

Definition at line 263 of file turtle.py.

00263 
00264     def __neg__(self):
        return Vec2D(-self[0], -self[1])
def turtle.Vec2D.__new__ (   cls,
  x,
  y 
)

Definition at line 250 of file turtle.py.

00250 
00251     def __new__(cls, x, y):
        return tuple.__new__(cls, (x, y))
def turtle.Vec2D.__repr__ (   self)

Definition at line 276 of file turtle.py.

00276 
00277     def __repr__(self):
00278         return "(%.2f,%.2f)" % self
00279 

def turtle.Vec2D.__rmul__ (   self,
  other 
)

Definition at line 258 of file turtle.py.

00258 
00259     def __rmul__(self, other):
00260         if isinstance(other, int) or isinstance(other, float):
            return Vec2D(self[0]*other, self[1]*other)
def turtle.Vec2D.__sub__ (   self,
  other 
)

Definition at line 261 of file turtle.py.

00261 
00262     def __sub__(self, other):
        return Vec2D(self[0]-other[0], self[1]-other[1])
def turtle.Vec2D.rotate (   self,
  angle 
)
rotate self counterclockwise by angle

Definition at line 267 of file turtle.py.

00267 
00268     def rotate(self, angle):
00269         """rotate self counterclockwise by angle
00270         """
00271         perp = Vec2D(-self[1], self[0])
00272         angle = angle * math.pi / 180.0
00273         c, s = math.cos(angle), math.sin(angle)
        return Vec2D(self[0]*c+perp[0]*s, self[1]*c+perp[1]*s)

The documentation for this class was generated from the following file: