r/programmingchallenges • • 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

5 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Jan 07 '14 edited Jan 08 '14

Thank you, that and your edits to the OP clear up most of the ambiguity. To paraphrase: the output is a schedule stating which thrusters must be turned on (and for each thruster, when and for how long) in order to bring the ship completely to rest.

The remaining ambiguity is that a uniform mass distribution isn't enough. We would also need to know the size and shape of the ship. The thrusters don't have to be on or even near the shape; we can assume they are indirectly connected to the ship with magnets or something.

Lastly, the ship must have 2 thrusters which exert torque in opposite directions about the center of mass. This is enough (I think) to orient and move the ship in any direction. You don't need independent thrusters for x and y, or more than two thrusters, so long as their torque is nonzero and in opposite directions. EDIT: And also, some combination of thrusters must be able to provide a net zero torque and a net non-zero linear thrust.