diff --git a/world/physics.py b/world/physics.py index 796b0ab..4d9199e 100644 --- a/world/physics.py +++ b/world/physics.py @@ -5,51 +5,18 @@ from config.constants import MAX_VELOCITY, MAX_ROTATIONAL_VELOCITY class Physics: """ - Physics - ⠀⠀⢀⣀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡠⣄⠀⠀⠀⠀⠀ - ⠀⣴⠊⠛⠦⣅⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠃⠈⠈⠳⡄⠀⠀⠀ - ⠸⣿⠀⠀⠀⠉⢹⣆⠀⠀⠀⠠⡶⠖⢦⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢻⡄⠀⠀⠈⡆⠀⠀ - ⠀⠈⣧⠀⠀⠀⠀⠉⠓⠂⠐⠋⠀⠀⢸⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣴⡆⢀⢰⣶⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡒⠀⣤⢀⠀⠈⡇⠀⠀⠀⢹⡂⠀ - ⠀⠀⢹⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠰⠞⠄⠀⠀⠀⠀⠀⠀⠀⣀⣤⣾⠿⠁⠈⠁⠉⠻⢷⠶⠴⢭⡄⠤⡀⠀⠀⠀⠀⠀⢿⡇⠀⠈⢢⠀⣸⡇⠀⠀⠀⠐⠁⠀ - ⠀⠀⠀⢻⠀⠀⠀⠀⠀⠀⠀⠀⢐⡏⡀⠀⠀⠀⠀⠀⠀⣠⡚⠛⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠑⢮⡀⡀⠀⠀⠀⠉⢳⡄⠀⡘⠛⠋⠀⠀⠀⠀⠀⡄⠀ - ⠀⠀⠀⢀⣇⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⢀⣴⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣌⢂⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⢰⣧⡅ - ⠀⠀⠀⠀⢻⣄⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⣠⡾⠁⠀⠀⠀⠀⠀⣠⡴⠖⠤⠴⠤⠶⠀⢄⠀⠀⠀⠀⠀⠀⠈⠓⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⢠⣤⠞⠵⠁ - ⠀⠀⠀⠀⠀⠻⣦⡀⠀⠀⠀⢰⡺⠀⠀⠀⢀⡾⠇⠀⠀⠀⠀⣠⡾⠋⠀⠀⠀⠀⠀⠀⠀⠀⢹⣀⡀⠀⠀⠀⠀⠀⢱⠀⠀⠘⠛⢧⡀⠀⠀⣀⣴⠟⠁⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠈⠓⠖⠶⠶⠵⠃⠀⠀⠀⢺⢈⠀⠀⠀⢀⣰⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠙⢆⠀⠀⠀⠀⠀⠸⣄⠁⠀⠀⠈⠻⠒⠚⠏⠁⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢘⡀⠀⠀⠀⢸⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⣡⡀⠀⠀⠀⠀⢸⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠃⠀⠀⣠⡎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⠀⠀⠀⠀⢻⡁⡀⠀⠀⢀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡔⠀⠀⡾⠀⠀⠀⠀⢀⡤⠞⠁⠀⠀⠀⠹⠄⠀⠀⠀⠈⢯⠀⠀⠀⣠⣼⠅⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠿⣧⠀⢸⡇⠀⠀⢠⡼⠋⠀⠀⠀⠀⠀⠀⠀⠀⢰⠀⠀⠀⠸⡄⠀⢀⣿⣏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⣄⣸⡁⠀⢀⠾⡆⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠀⠀⢠⡣⠀⣸⡿⠂⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠿⣬⠛⠁⡆⠉⡆⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠂⢧⠀⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣿⣆⣀⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠀⢀⣸⣤⣿⠯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠀⠘⠳⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣴⠿⠋⠛⠛⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⠛⠲⠖⠒⠒⠂⠒⠒⠒⠛⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - - ⣿⣿⣿⣿⣿⣿⣿⣿⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣹⡏⠀⠈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⢻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⠿⣋⡁⢶⣦⣤⣍⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⠉⡴⣿⡟⢸⣿⣿⡿⣷⡄⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⡿⢸⣿⣿⡗⣼⣿⣿⣯⣽⢻⡆⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⡇⣾⣿⣿⣾⣿⣿⣾⣿⣯⣿⣧⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⡟⣱⣿⣿⣿⣿⣿⣽⣾⣿⣽⢻⣏⡄⣿⢿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⡿⢡⣿⣯⣿⣿⡿⣟⣻⣿⣿⢿⣿⣏⢻⠘⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⠗⠒⣛⢻⣿⣿⣿⡟⢻⣿⣏⣿⣷⣠⣿⡘⡧⡘⢿⣿⣿⣿⣿⣿⣿ - ⠛⠁⢴⠺⢿⡀⠻⣿⢿⡇⣼⠏⠯⠈⢿⡿⢘⣿⡘⣦⡘⣿⣿⣿⣿⣿⣿ - ⠀⠀⠀⠀⠈⢻⡆⠈⠈⢠⡇⠐⠀⠀⠈⠃⢸⣯⣧⠉⣧⠸⣿⣿⣿⣿⣿ - ⡄⣀⢃⠀⠀⣸⣿⣧⡀⣼⣿⡀⠀⠀⢠⡄⠸⣿⣿⣷⢉⠃⣿⣿⣿⣿⣿ - ⡇⢹⣦⡻⣿⣿⣿⢩⣷⣿⣿⣿⣷⣾⣾⠇⣶⣞⡛⣷⣌⡀⣿⣿⣿⣿⣿ - ⡶⢄⠻⣿⣾⣿⠓⠬⠽⠟⢛⣿⣿⣿⣟⢐⢻⣿⣿⣿⠿⢡⣿⣿⣿⣿⣿ - ⣿⣇⢱⠙⢿⣿⣶⣖⣲⣶⣿⣿⡿⢋⣡⣿⣿⣿⣿⡟⢠⣿⣿⣿⣿⣿⣿ - ⣿⣿⣷⣅⢲⣌⠛⠿⠿⠿⢟⠁⣴⣷⣾⣿⣾⡿⠟⣰⣿⣷⣮⣭⣭⣟⣻ - ⣿⣿⣿⣿⣷⣌⡐⠰⣴⣶⠾⠿⢿⠿⠷⠟⠈⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠉⠁⠀⢀⣀⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣷⣶⣬⣘⣒⠷⢦⣶⣶⣶⣗⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣶⣶⣾⣿⣿⣟⣛⣿⣿⣿⣿⣿⣿ + Simulates basic 2D physics for an object, including linear and rotational motion + with drag effects. """ def __init__(self, drag_coefficient: float, rotational_drag: float): + """ + Initialize the Physics object. + + Args: + drag_coefficient (float): Linear drag coefficient. + rotational_drag (float): Rotational drag coefficient. + """ + self.drag_coefficient: float = drag_coefficient self.rotational_drag: float = rotational_drag @@ -61,6 +28,17 @@ class Physics: def move(self, linear_acceleration: float, angular_acceleration: int, rotational_position): + """ + Update the object's velocity and acceleration based on input forces and drag. + + Args: + linear_acceleration (float): The applied linear acceleration. + angular_acceleration (int): The applied angular acceleration. + rotational_position: The current rotational position in degrees. + + Returns: + tuple: Updated (velocity, acceleration, rotational_velocity, angular_acceleration). + """ # Apply drag force drag_coefficient = self.drag_coefficient drag_x = -self.velocity[0] * drag_coefficient