class documentation

class Point(NamedTuple('_Point', [('x', float), ('y', float)])): (source)

View In Hierarchy

Class representing a point on the 2D plane.

Class Method FromPolar Constructs a point from polar coordinates.
Method __add__ Adds the coordinates of a point to another one
Method __div__ Divides the coordinates by a scalar
Method __mul__ Multiplies the coordinates by a scalar
Method __sub__ Subtracts the coordinates of a point to another one
Method as_polar Returns the polar coordinate representation of the point.
Method distance Returns the distance of the point from another one.
Method interpolate Linearly interpolates between the coordinates of this point and another one.
Method length Returns the length of the vector pointing from the origin to this point.
Method normalized Normalizes the coordinates of the point s.t. its length will be 1 after normalization. Returns the normalized point.
Method sq_length Returns the squared length of the vector pointing from the origin to this point.
Method towards Returns the point that is at a given distance from this point towards another one.
@classmethod
def FromPolar(cls, radius, angle): (source)

Constructs a point from polar coordinates.

radius is the distance of the point from the origin; angle is the angle between the X axis and the vector pointing to the point from the origin.

def __add__(self, other): (source)

Adds the coordinates of a point to another one

def __div__(self, scalar): (source)

Divides the coordinates by a scalar

def __mul__(self, scalar): (source)

Multiplies the coordinates by a scalar

def __sub__(self, other): (source)

Subtracts the coordinates of a point to another one

def as_polar(self): (source)

Returns the polar coordinate representation of the point.

Returns
the radius and the angle in a tuple.
def distance(self, other): (source)

Returns the distance of the point from another one.

Example:

>>> p1 = Point(5, 7)
>>> p2 = Point(8, 3)
>>> p1.distance(p2)
5.0
def interpolate(self, other, ratio=0.5): (source)

Linearly interpolates between the coordinates of this point and another one.

Parameters
otherthe other point
ratiothe interpolation ratio between 0 and 1. Zero will return this point, 1 will return the other point.
def length(self): (source)

Returns the length of the vector pointing from the origin to this point.

def normalized(self): (source)

Normalizes the coordinates of the point s.t. its length will be 1 after normalization. Returns the normalized point.

def sq_length(self): (source)

Returns the squared length of the vector pointing from the origin to this point.

def towards(self, other, distance=0): (source)

Returns the point that is at a given distance from this point towards another one.