Fascia
Fascia

Reputation: 770

Calculating thrusts for offset thruster positions given arbitrary thrusters at arbitrary position around a mass

I've had a bit of a sniff around google for a solution but I believe my terminology is wrong, so bear with me here.

I'm working on a simple game where people can build simplistic spaceships and place thrusters willy nilly over the space ship.

Let's call say my space ship's center of mass is V.

The space ship has an arbitrary number of thrusters at arbitrary positions with arbitrary thrust direction vectors with an arbitrary clamp.

I have an input angular velocity vector (angle/axis notation) and world velocity (vector) which i wish the ship to "go" at.

How would I calculate the the ideal thrust for each of the thrusters for the ship to accelerate to the desired velocities?

My current solution works well for uniformly placed thrusters. Essentially what I do is just dot the desired velocity by the thrusters normal for the linear velocity. While for the angular velocity I just cross the angular velocity by the thrusters position and dot the resulting offset velocity by the thrusters normal. Of course if there's any thrusters that do not have a mirror image on the opposite side of the center of mass it'll result in an undesired force.

Like I said, I think it should be a fairly well documented problem but I might just be looking for the wrong terminology.

Upvotes: 3

Views: 857

Answers (1)

celion
celion

Reputation: 4004

I think you can break this down into two parts. The first is deciding what your acceleration should be each frame, based on your current and desired velocities. A simple rule for this

acceleration = k * (desired velocity - current velocity)

where k is a constant that determines how "responsive" the system is. In order words, if you're going too slow, speed up (positive acceleration), and if you're going too fast, slow down (negative acceleration).

The second part is a bit harder to visualize; you have to figure out which combination of thrusters gives you the desired accelerations. Let's call c_i the amount that each thruster thrusts. You want to solve a system of coupled equations

sum( c_i * thrust_i ) = mass * linear acceleration
sum( c_i * thrust_i X position_i) = moment of interia * angular acceleration

where X is the cross produxt. My physics might be a bit off, but I think that's right.

That's an equation of 6 equations (in 3D) and N unknowns where N is the number of thusters, but you've got the additional constraint that c_i > 0 (assuming the thrusters can't push backwards).

That's a tricky problem, but you should be able to set it up as a LCP and get an answer using the Projected Gauss Seidel method. You don't need to get the exact answer, just something close, since you'll be solving it again for slightly different values on the next frame.

I hope that helps...

Upvotes: 2

Related Questions