Vec2

A 2D mathematical vector representation.

  • Vec2()
  • Vec2(value: float)
  • Vec2(x: float, y: float)

Properties


NameDescriptionType
xThe x-component of the vectorfloat
yThe y-component of the vectorfloat
xyA tuple representing the (x, y) components of the vectortuple[float, float]
yxA tuple representing the (y, x) components of the vectortuple[float, float]
xxA tuple representing the (x, x) components of the vectortuple[float, float]
yyA tuple representing the (y, y) components of the vectortuple[float, float]
lengthThe length (magnitude) of the vectorfloat
angleThe angle of the vector in radiansfloat

Methods


Rotate

rotate(radians: float) None

Rotate the vector by a given angle in radians.

Parameters

  • radians : The angle to rotate the vector by, in radians.

Normalize

normalize() None

Normalize the vector, making its length 1.

Note:

If the vector has zero length, it will remain unchanged.

Scale To Length

scale_to_length(length: float) None

Scale the vector to a specific length.

Parameters

  • length : The length to scale the vector to.

Distance To

distance_to(other: Vec2) float

Calculate the distance to another vector.

Parameters

  • other : The other vector to calculate the distance to.

Returns

float : The distance to the other vector.

To Polar

to_polar() PolarCoordinate

Convert the vector to polar coordinates.

Returns

PolarCoordinate : The polar coordinate object representation of the vector.