Vec2
A 2D mathematical vector representation.
-
Vec2()
-
Vec2(value: float)
-
Vec2(x: float, y: float)
Properties
Name | Description | Type |
---|---|---|
x | The x-component of the vector | float |
y | The y-component of the vector | float |
xy | A tuple representing the (x, y) components of the vector | tuple[float, float] |
yx | A tuple representing the (y, x) components of the vector | tuple[float, float] |
xx | A tuple representing the (x, x) components of the vector | tuple[float, float] |
yy | A tuple representing the (y, y) components of the vector | tuple[float, float] |
length | The length (magnitude) of the vector | float |
angle | The angle of the vector in radians | float |
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.