core.physics package
Submodules
core.physics.vector module
Two-dimensional vectors in Forge.
- class core.physics.vector.Vector2D(x: float, y: float)
Bases:
object
Forge’s representation of a two-dimensional vector.
- as_tuple() tuple[float, float]
Return the x and y components of the vector in a tuple. Beneficial for internal interoperability with Pygame.
- Returns
Tuple of the vector’s x and y component respectively.
- Return type
tuple[float, float]
- is_normalized(precision: int = 4) bool
Check whether the vector is normalized, i.e., its length is equal to one.
- Parameters
precision (int) – Precision to which the length of the vector is to be checked to keep a delta for floating-point inaccuracies; defaults to 4.
- Returns
True if the length pr magnitude of the vector is equal to one; else False.
- Return type
bool
- length() float
Compute the length of the vector.
- Returns
Length or magnitude of the vector.
- Return type
float
- length_squared() float
Compute the square of the length of the vector. Faster due to lack of a square root operation.
- Returns
Square of the length or magnitude of the vector.
- Return type
float
- normalize() None
Normalize the vector, i.e., set its length to one while maintaining the same direction.
- Raises
ZeroDivisionError – A vector of zero length cannot be normalized.
- scale(other: Vector2D) None
Scale the vector by another vector’s corresponding components.
- Parameters
other (Vector2D) – Scaling factor vector.
- x: float
- y: float
- core.physics.vector.angle(from_vector: Vector2D, to_vector: Vector2D) float
Calculate the unsigned angle between one vector and another. The unsigned angle means that the direction of rotation becomes irrelevant.
- core.physics.vector.clamp(vector: Vector2D, min_: Vector2D, max_: Vector2D) Vector2D
Clamp a vector between a specified minimum and maximum bound.
- Parameters
- Returns
Vector clamped to the minimum and maximum bound.
- Return type
- Raises
ValueError – The maximum bound cannot be greater than the minimum bound on either component axis.
- core.physics.vector.cross(vector1: Vector2D, vector2: Vector2D) float
Compute the cross product of two vectors.
- core.physics.vector.distance_between(vector1: Vector2D, vector2: Vector2D) float
Compute the distance between two vectors.
- core.physics.vector.distance_squared_between(vector1: Vector2D, vector2: Vector2D) float
Compute the square of the distance between two vectors. Faster due to lack of a square root operation.
- core.physics.vector.dot(vector1: Vector2D, vector2: Vector2D) float
Compute the dot product of two vectors.
- core.physics.vector.down() Vector2D
Create a new vector pointing in the down direction, i.e., x: 0, y: 1.
- Returns
New down vector.
- Return type
- core.physics.vector.from_tuple(position: tuple[float, float]) Vector2D
Create a new vector using an existing tuple of components. Beneficial for internal interoperability with Pygame.
- Parameters
position (tuple[float, float]) – Tuple of the vector’s x and y component respectively.
- Returns
Vector created from the tuple.
- Return type
- core.physics.vector.left() Vector2D
Create a new vector pointing in the left direction, i.e., x: -1, y: 0.
- Returns
New left vector.
- Return type
- core.physics.vector.lerp(from_vector: Vector2D, to_vector: Vector2D, t: float) Vector2D
Compute a smooth linear interpolation of a vector along both axes with respect to a constraint.
- Parameters
- Returns
Linearly interpolated vector between the initial and final vectors.
- Return type
- core.physics.vector.normalized(vector: Vector2D) Vector2D
Normalize a vector, i.e., set its length to one while maintaining the same direction and return it.
- core.physics.vector.one() Vector2D
Create a new one vector: i.e., x: 1, y: 1.
- Returns
New one vector.
- Return type
- core.physics.vector.random() Vector2D
Create a new vector pointing in a random direction, i.e. x: -1 | 0 | 1, y: -1 | 0 | 1.
- Returns
New random vector.
- Return type
- core.physics.vector.reflect(direction: Vector2D, normal: Vector2D) Vector2D
Reflect a vector along a given normal to the direction of the vector.
- core.physics.vector.right() Vector2D
Create a new vector pointing in the right direction, i.e., x: 1, y: 0.
- Returns
New right vector.
- Return type