collisionHandler¶
This file contains all of the functions involved in calculating collisions. Here’s a rundown on what all of the function do:
- collisionHandler.normalize(vector: array) array¶
Normalizes the given vector.
- Parameters:
vector (
np.array) – A 2 dimensional vector.- Returns:
The given vector normalized.
- Return type:
np.array
- collisionHandler.findNormalForce(motionVector: array, surface: Surface) array¶
Takes a motionVector (representing the vector formed by an entity’s _priorPosition and _position) and a surface object, then returns the component of the motionVector normal to the surface.
- Parameters:
motionVector (
np.array) – A 2 dimensional vector.surface (
environment.Surface) – A surface object.
- Returns:
The component of the motionVector normal to the surface.
- Return type:
np.array
- collisionHandler.pointInBounds(point: array, xBounds: list[float], yBounds: list[float]) bool¶
Takes a point and two tuples, representing upper/lower x/y bounds, respectively, and returns a boolean indicating whether the point is located in those bounds. It will return true even if the point is one pixel out of bounds in either direction.
- Parameters:
point (np.array) – A point in 2D space.
xBounds (
list[float]) – The lower/upper x bounds (order doesn’t matter)yBounds (
list[float]) – The lower/upper y bounds (order doesn’t matter)
- Returns:
A boolean indicating whether the point is in the given bounds.
- Return type:
bool
- collisionHandler.findCollisionPoint(entity: EntityInterface, surface: Surface) array¶
Finds the collision point of an entity’s trajectory and an surface. If there is no collision point, the function returns NoneType.
- Parameters:
entity (
entity.EntityInterface) – The entity that might collied with a surfacesurface (
environment.Surface) – The surface that the entity might collide with
- Returns:
If there is a collision point, a
np.arraywith the point. Otherwise,None.- Return type:
np.array|None
- collisionHandler.findClosestPoint(objectPosition: array, positions: list[array]) array¶
Takes a position and a list of points. Then finds the point in the list closest to the given position.
- Parameters:
objectPosition (
np.array) – The positionpositions (
list[np.array]) – The list of positions you want to search
- Returns:
The point in the list closest to the object position
- Return type:
np.array
- collisionHandler.findNumpyArrayIndex(list: array, item: int | float) int¶
Finds the index of an item within a numpy array
- Parameters:
list (
np.array) – The numpy arrayitem (
int | float) – The item within the numpy array whose index you want to find
- Returns:
The index of the item within the array
- Return type:
int | float
- collisionHandler.resolveMotion(entity: EntityInterface, environment: list[Surface])¶
Takes an entity and an environment. The environment will be a list of surface objects to represent the “environment”. It then calculates all collisions and entity movements that will take place within a single frame and applies them. :param entity: The entity whose motion you want to resolve :param environment: A list of surface objects to represent the entity’s environment :type entity:
entity.EntityInterface:type environment:list[environment.Surface]