Vec2
A 2D vector representing Cartesian coordinates.
Constructor
A 2D vector representing Cartesian coordinates.
Properties
| Name | Description | Type |
|---|---|---|
x | The x component of the vector. | float |
y | The y component of the vector. | float |
length | Return the magnitude of this Vec2. | float |
length_squared | Return the squared magnitude of this Vec2. | float |
angle | Return the vector angle in radians. | float |
xx | Return a Vec2 with both components set to x. | Vec2 |
xy | Access or assign the (x, y) components as a Vec2. | Vec2 |
yx | Access or assign the (y, x) components as a Vec2. | Vec2 |
yy | Return a Vec2 with both components set to y. | Vec2 |
ZERO | (0.0, 0.0) | Vec2 |
LEFT | (-1.0, 0.0) | Vec2 |
RIGHT | (1.0, 0.0) | Vec2 |
UP | (0.0, -1.0) | Vec2 |
DOWN | (0.0, 1.0) | Vec2 |
Methods
Copy
Is Zero
is_zero(tolerance: float = 1e-08) → boolDetermine whether this Vec2 is effectively zero.
Args
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.
Args
other: The vector to project onto.
Returns
Vec2 : Projection of this vector onto the other vector.
Reject
reject(other: Vec2) → Vec2Compute the rejection of this Vec2 from another Vec2.
Args
other: The vector defining the projection axis.
Returns
Vec2 : Component of this vector orthogonal to the other vector.
Reflect
reflect(other: Vec2) → Vec2Reflect this Vec2 across another Vec2.
Args
other: The vector used as the reflection normal.
Returns
Vec2 : Reflected vector.
Rotate
rotate(radians: float) → NoneRotate this Vec2 in place.
Args
radians: Rotation angle in radians.
Rotated
rotated(radians: float) → Vec2Return a new Vec2 rotated by a specified angle.
Args
radians: Rotation angle in radians.
Returns
Vec2 : A new vector rotated by the given angle.
Normalize
normalize() → NoneNormalize this Vec2 in place.
Normalized
Scale To Length
scale_to_length(length: float) → NoneScale this Vec2 to a specific magnitude.
Args
length: Target vector length.
Scaled To Length
scaled_to_length(length: float) → Vec2Return a new Vec2 scaled to a specific magnitude.
Args
length: Target vector length.
Returns
Vec2 : A new vector scaled to the specified length.
Distance To
distance_to(other: Vec2) → floatCompute the Euclidean distance to another Vec2.
Args
other: Comparison vector.
Returns
float : Distance between the vectors.
Distance Squared To
distance_squared_to(other: Vec2) → floatCompute the squared distance to another Vec2.
Args
other: Comparison vector.
Returns
float : Squared distance between the vectors.
To Polar
to_polar() → PolarCoordinateConvert this Vec2 to polar coordinates.
Returns
PolarCoordinate : Polar representation with angle and length.
Move Toward
move_toward(target: Vec2, delta: float) → NoneMove this Vec2 toward a target Vec2 by a specified delta.
Args
target: The target vector to move towards.delta: The maximum distance to move.
Moved Toward
moved_toward(target: Vec2, delta: float) → Vec2Return a new Vec2 moved toward a target Vec2 by a specified delta.
Args
target: The target vector to move towards.delta: The maximum distance to move.
Returns
Vec2 : A new vector moved toward the target.
Floored
floored() → Vec2Return a new Vec2 with both components floored to the nearest integer.
Returns
Vec2 : A new vector with floored components.
Ceiled
ceiled() → Vec2Return a new Vec2 with both components ceiled to the nearest integer.
Returns
Vec2 : A new vector with ceiled components.
Rounded
rounded() → Vec2Return a new Vec2 with both components rounded to the nearest integer.
Returns
Vec2 : A new vector with rounded components.
As Ints
as_ints() → tuple[int, int]Return the vector components truncated to integers as a tuple.
Returns
tuple[int, int] : The (x, y) components as integers.