Vectors

class wasabi.geom.vector.Vector

Two-dimensional float vector implementation.

angle

The angle the vector makes to the positive x axis in the range (-180, 180].

angle_to(other)

Compute the angle made to another vector in the range [0, 180].

Parameters:
other : Vector

The vector with which to compute the angle.

cross(other)

Compute the cross product with another vector.

Parameters:
other : Vector

The vector with which to compute the cross product.

distance_to(other)

Compute the distance to another point vector.

Parameters:
other : Vector

The point vector to which to compute the distance.

dot(other)

Compute the dot product with another vector.

Parameters:
other : Vector

The vector with which to compute the dot product.

is_zero

Flag indicating whether this is the zero vector.

length

The length of the vector.

length2

The square of the length of the vector.

normalised()

Compute the vector scaled to unit length.

normalized()

Compute the vector scaled to unit length.

perpendicular()

Compute the perpendicular.

project(other)

Compute the projection of another vector onto this one.

Parameters:
other : Vector

The vector of which to compute the projection.

rotated(angle)

Compute the vector rotated by an angle.

Parameters:
angle : float

The angle (in degrees) by which to rotate.

safe_normalised()

Compute the vector scaled to unit length, or some unit vector if it was the zero vector.

safe_normalized()

Compute the vector scaled to unit length, or some unit vector if it was the zero vector.

safe_scaled_to(length)

Compute the vector scaled to a given length, or just return the vector if it was the zero vector.

Parameters:
length : float

The length to which to scale.

scaled_to(length)

Compute the vector scaled to a given length.

Parameters:
length : float

The length to which to scale.

signed_angle_to(other)

Compute the signed angle made to another vector in the range (-180, 180].

Parameters:
other : Vector

The vector with which to compute the angle.

x

The horizontal coordinate.

y

The vertical coordinate.

class wasabi.geom.vector.Matrix(x11, x12, x21, x22)

A 2x2 matrix.

This can be used to optimise a transform (such as a rotation) on multiple vectors without recomputing terms.

To transform a vector with this matrix, use premultiplication, ie. for Matrix M and Vector v,

t = M * v
static rotation(angle)

A rotation matrix for angle a.

wasabi.geom.vector.v(*args)

Construct a vector from an iterable or from multiple arguments. Valid forms are therefore: v((x, y)) and v(x, y).