Simple 2D rocket dynamics

I am currently experimenting with some physical toys in XNA using the Farseer Physics library, however my question is not specific to XNA or Farseer, but to any 2D physics library.

I would like to add “rocket” movement (I say rocket-like in the sense that it should not be a rocket - it can be a plane or a boat on the water or any number of similar situations) for some objects in my 2D scene. I know how to implement this using kinematic modeling, but I want to implement it using dynamic modeling (i.e., using forces over time). I kind of lost how to implement this.

To simplify the situation, I do not need dynamics to rotate the geometry, just to affect the speed of the body. I use circle geometry that doesn't spin in Farseer, so I’m only interested in the speed of the object.

I'm not even sure what the best abstraction should be. It is clear that I have a direction in which the body moves (a unit vector), a direction in which I want, and a value showing how quickly I want it to change direction, keeping the speed relatively constant (small variations are acceptable).

I could use this abstraction directly or use something like a “rudder” value that controls how quickly an object changes direction (clockwise or counterclockwise).

What forces should I apply to the body to simulate the movement that I am looking for? Keep in mind that I would also like to tune the “thrust” of the rocket on the fly.

Edit: The way I see it, and correct me, if I'm wrong, you have two forces (now ignoring the main force of the axial impact):

1) You have a static “fin” that always points in the same direction as the body. If the body rotates so that the fin is not aligned with the direction of movement, air resistance will apply forces to the length of the rib, proportional to the angle between the direction of movement and the fin.

2) You have a “steering wheel” that can rotate freely within a given range, which is attached at some distance from the center of mass of the body (in this case we have a circle). Again, when this plane is not parallel to the direction of movement, air resistance causes proportional forces along the length of the rudder.

My question, in other words, how can I calculate these proportional forces from the air resistance against the fin and rudder?

Edit: For reference, here is some code that I wrote to verify the accepted answer:

/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { float dc = 0.001f; float lc = 0.025f; float angle = MathHelper.ToRadians(45); Vector2 vel = new Vector2(1, 0); Vector2 pos = new Vector2(0, 0); for (int i = 0; i < 200; i++) { Vector2 drag = vel * angle * dc; Vector2 sideForce = angle * lc * vel; //sideForce = new Vector2(sideForce.Y, -sideForce.X); // rotate 90 degrees CW sideForce = new Vector2(-sideForce.Y, sideForce.X); // rotate 90 degrees CCW vel = vel + (-drag) + sideForce; pos = pos + vel; if(i % 10 == 0) System.Console.WriteLine("{0}\t{1}\t{2}", pos.X, pos.Y, vel.Length()); } } 

When plotting the output of this program, you will see a nice smooth circular curve, which is exactly what I was looking for!

+6
c # xna 2d physics farseer
source share
3 answers

If you already have code to integrate force and mass with acceleration and speed, you just need to calculate a separate part of each of the two elements you are talking about.

Keeping it simple, I forgot about the fin for a moment and simply say that at any time when your rocket’s body is at an angle to speed, it will generate a linearly increasing lateral force and resistance. Just play around with the odds until it appears and feels like you want.

 Drag = angle*drag_coefficient*velocity + base_drag SideForce = angle*lift_coefficent*velocity 

For the steering wheel, the generated effect is the moment, but if your game does not have to go into angular dynamics, the easier it is for the steering wheel to make a fixed number of changes to the angle of the rocket per time stamp in your game.

+2
source share

I suddenly get it.

You want to simulate a rocket flying in the air , OK. This is a different problem than the one I described in detail below, and imposes various restrictions. You need an aerospace geek. Or you can just kick.


Make this "right" (for a space):

The simulated body must be provided with a moment of inertia around its center of mass and must also have a direction and angular velocity. Then you calculate the angular acceleration from the applied momentum and the distance from CoM and add this to the angular speed. This allows you to calculate the current ship's “direction” (if you are not using gyroscopes or twin jets, you also get linear acceleration (usually very small)).

To generate a turn, you point the ship from the current direction of travel and apply the main disk.

And if you are serious about this, you also need to subtract the mass of fuel burned from the total mass and make appropriate adjustments to the moment of inertia at each increment of time.

BTW . It can be more trouble than it costs: maneuvering a rocket in free fall is difficult. You may recall that the Russians launched docking on the ISS in the manner of a few years ago, well, that’s not because they are stupid.). If you do not tell us your use case, we cannot advise you.

A little pseudo code to hint at what you are doing here:

 rocket { float structuralMass; float fuelMass; point position; point velocity; float heading; float omega; // Angular velocity float structuralI; // moment of inertia from craft float fuelI; // moemnt of inertia from the fuel load float Mass(){return struturalMass + fuelMass}; float I(){return struturalI + fuelI}; float Thrust(float t); float AdjustAttitude(float a); } 

Result: maybe you need a version for the game.


For the reason I don’t both go in here, the most effective way to launch a “real” rocket is usually not to make gradual turns and slow acceleration, but to push hard when all you want is to change direction. In this case, you get the angle of inclination by subtracting the desired vector (full vector, not unit) from the current one. Then you point in that direction and trust everyone until the desired course is reached.

+2
source share

Imagine that you are floating in empty space ... And you have a big stone in your hand ... If you throw a stone, a small impulse will be applied to you in the opposite direction when you throw a stone. You can model your rocket as something that quickly converts a quantum of fuel into some force (vector value) that you can add to your direction vector.

0
source share

All Articles