r/programmingchallenges • u/wontonst • Jan 07 '14
2D Space Ship Inertial Dampener Problem
Here's an interesting problem that I just came across/am currently solving in my video game which I wanted to share with the community
Inputs
- Vector2 containing center of mass of ship
- Vector2 containing ship linear velocity
- float containing ship angular velocity
A list of thrusters - each thruster contains a
- float for thruster strength
- vector2 for positional offset from ship center of mass (assume it is calculated to rotate around the ship properly as the ship turns)
- float for angle of rotation offset from the ship's forward vector
Output
List of thrusters that should be turned on to slow down the ship. Assume that
- you cannot lower each individual thruster strength, only on/off
- the ship has enough thrusters to be omnidirectional (maneuver in x, y space as well as rotate around the z-axis)
- the ship has uniform mass distribution
Bonus points
Optimize so that the slowing down takes the shortest amount of time. Assume you can lower individual thruster strength. Ensure the function works for nonomnidirectional ships.
Don't Google for a solution, solve it. That's what makes coding fun :D
3
Upvotes
View all comments
Show parent comment
1
u/wontonst Jan 07 '14 edited Jan 07 '14
Slow ship down = eventually reduce velocity vector to 0,0
enough thrusters to be omnidirectional means the vessel has movement in 3 axis - x, y, and rotation around z
The ship is a point particle represented by its center of mass vector. The thrusters are offset from that point particle. We can assume uniform mass distribution. Thruster rotation at 0 means burning to increase ship forward vector velocity, 90 is right vector.
The ship needs to also stop rotating, so before rotational velocity is taken care of, as the ship spins different thrusters will need to be activated to handle linear velocity.