Repository navigation
documentation
This Python library introduces a set of fast vector classes, designed for convenient and rapid vector operations, similar to those in Unity. It is well-suited for game development using Pygame and also useful for general mathematical applications. The library is open source and available on GitHub.
The core mathematical logic and vector class are entirely written in C++. They are then utilized through CPython in Python, transforming it into a wrapper class that can be fully utilized in Python. Speaking of its power, here are some speed-related details, including a comparison with the popular numpy library in mathematics:
from rivector import Vector2
vector = Vector2(x: float, y: float)-
Parameters:
-
x: The x-component of the vector. -
y: The y-component of the vector.
-
vector.set(x: float, y: float)-
Parameters:
-
new_X: New value for the x-component. -
new_Y: New value for the y-component.
-
Note
Modifies the current vector.
vector.equals(b: Vector2)-
Parameters:
-
b: Another Vector2 object for comparison.
-
-
Returns:
trueif the vectors are exactly equal; otherwise,false.
vector.clamp_magnitude(max_length: float)-
Parameters:
-
max_length: The maximum length for the vector.
-
- Returns: A dynamically allocated array representing the clamped vector.
vector.distance(b: Vector2)-
Parameters:
-
b: Another Vector2 object.
-
- Returns: The distance between the two vectors.
vector.lerp_unclamped(a: Vector2, b: Vector2, t: float)-
Parameters:
-
a: Starting Vector2. -
b: Ending Vector2. -
t: Interpolation factor (0.0 to 1.0).
-
- Returns: A dynamically allocated array representing the interpolated vector.
vector.max(a: Vector2, b: Vector2)-
Parameters:
-
a: First Vector2. -
b: Second Vector2.
-
- Returns: A dynamically allocated array representing the vector with the largest components.
vector.min(a: Vector2, b: Vector2)-
Parameters:
-
a: First Vector2. -
b: Second Vector2.
-
- Returns: A dynamically allocated array representing the vector with the smallest components.
vector.perpendicular(a: Vector2)-
Parameters:
- a: The Vector2 object.
- Returns: A dynamically allocated array representing the perpendicular vector.
vector.move_towards(a: Vector2, b: Vector2, max_distance_delta: float)-
Parameters:
-
a: Current position. -
b: Target position. -
max_distance_delta: Maximum distance to move towards the target.
-
- Returns: A dynamically allocated array representing the new position.
vector.reflect(a: Vector2, b: Vector2)-
Parameters:
-
a: Incident vector. -
b: Normal vector.
-
- Returns: A dynamically allocated array representing the reflected vector.
vector.scale(a: Vector2, scale: float)-
Parameters:
-
a: The Vector2 object. -
scale: The scaling factor.
-
- Returns: A dynamically allocated array representing the scaled vector.
vector.signed_angle(a: Vector2, b: Vector2)-
Parameters:
-
a: Starting Vector2. -
b: Ending Vector2.
-
- Returns: The signed angle in degrees between the two vectors.
vector.smooth_damp(a: Vector2, b: Vector2, c: Vector2, smooth_time: float, max_speed: float, delta_time: float)-
Parameters:
-
a: Current position. -
b: Target position. -
c: Current velocity. -
smooth_time: Smoothing time. -
max_speed: Maximum speed. -
delta_time: Time since the last call.
-
- Returns: A dynamically allocated array representing the smoothly interpolated position.
vector.to_list()- Returns: A dynamically allocated array representing the vector.
vector.sqrmagnitude- Returns: The squared magnitude of the vector.
vector.magnitude- Returns: The magnitude of the vector.
vector.normalized()- Returns: A dynamically allocated array representing the normalized vector.
vector.dot(a: Vector2, b: Vector2)-
Parameters:
-
a: First Vector2. -
b: Second Vector2.
-
- Returns: The dot product of the two vectors.
vector.angle(a: Vector2, b: Vector2)-
Parameters:
-
a: First Vector2. -
b: Second Vector2.
-
- Returns: The angle in radians between the two vectors.
vector.y_coord
vector.x_coord- Returns: The x or y component of the vector, respectively.
Want to contribute to this Wiki?
- Info
- Constructor
- Getter Methods
- Methods