Vec2
A 2D mathematical vector representation.
Constructor
-
Vec2() -
Vec2(value: float) -
Vec2(x: float, y: float)
Parameters
value: Value assigned to both x and y components.x: Horizontal component.y: Vertical component.
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 |
length_squared | The squared length of the vector | float |
angle | The angle of the vector in radians | float |
Methods
Rotate
rotate(radians: float) → NoneRotate the vector by a given angle in radians.
Parameters
radians: The angle to rotate the vector by, in radians.
Normalize
normalize() → NoneNormalize 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) → NoneScale the vector to a specific length.
Parameters
length: The length to scale the vector to.
Distance To
distance_to(other: Vec2) → floatCalculate the distance to another vector.
Parameters
other: The other vector to calculate the distance to.
Returns
float : The distance to the other vector.
Distance Squared To
distance_squared_to(other: Vec2) → floatCalculate the squared distance to another vector.
Parameters
other: The other vector to calculate the squared distance to.
Returns
float : The squared distance to the other vector.
To Polar
to_polar() → PolarCoordinateConvert the vector to polar coordinates.
Returns
PolarCoordinate : The polar coordinate object representation of the vector.
Copy
copy() → Vec2Create a copy of the vector.
Returns
Vec2 : A new vector object that is a copy of the original.
Is Zero
is_zero(tolerance: float = 1e-08) → boolDetermine whether this Vec2 is effectively zero.
Parameters
tolerance: Largest allowed absolute component magnitude.
Returns
bool : True if both components are within the tolerance.
Project
project(other: Vec2) → Vec2Project this Vec2 onto another Vec2.
Parameters
other: The vector to project onto.
Returns
Vec2 : Projection of this vector onto the other vector.
Reflect
reflect(other: Vec2) → Vec2Reflect this Vec2 across another Vec2.
Parameters
other: The vector used as the reflection normal.
Returns
Vec2 : Reflected vector.
Reject
reject(other: Vec2) → Vec2Compute the rejection of this Vec2 from another Vec2.
Parameters
other: The vector defining the projection axis.
Returns
Vec2 : Component of this vector orthogonal to the other vector.