# 2D Physics, calculating velocity and torque?

This topic is 4810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey, I'm creating some kind of space shuttle. On that space shuttle is a thruster (lets say, on position -40, -40 from the center of mass). The direction of this thruster is 0 (so it will push the shuttle forward). Now, how do I calculate the rotation of the shuttle?? I calculate my velocity like this now, works great! Only need the rotation now...
float fDirection = G3D::toRadians( m_pAttachedShipNode->m_fDirection );

Vector2 vMagnitude( -sinf( fDirection ), cosf( fDirection ) );
m_vVelocity += vMagnitude * ( m_fMaxThrustPower / m_fMass ) * m_fCurrentThrust * fTimeStep;
(not all the code, but it shows how it's calculated :) ) (Sorry that i'm not very clear, no idea how to explain this :P )

##### Share on other sites
torque = Cross(C-X, F)

where
C = center of mass
X = Point the force is applied to
F = force
and Cross(u, v) = u.x*v.y-u.y*v.x

then you would just do

angAccel = torque / I

where
I = inertia ( in 2d its just a number. ex. I = 5; )

depending on your coordinate system Cross(u,v) may need to be changed.

if you need some explanation as to how theese are derived just ask.

##### Share on other sites
look up the rocket equation, the force produced by the rocket is related to the velocity of the exaust ejected, also the mass of the fluid. it's just a standard conservation of momentium equation. you might wanna look into it for realistic handling and stuff.

##### Share on other sites
Ok, created a new system, so my calculations are now like this:
-m_fThrustDirection * ( m_fThrust * m_fThrustPower )

This is the force applied to the ship. m_fThrustDirection is the thrust direction (0 -1 for now). m_fThrust is a value of -1.0 to 1.0, tells if thruster is at full power or not. m_fThrustPower is the max power of the thruster (200000 for now, speed is in pixels =P).

Now I also want to limit the max speed of the thruster by m_fThrustSpeed, how to add that in my force calculation?

Also I still don't understand how to calculate the torque for my ship. For example using the formula of Raymond_Porter420, when my thruster will be at -40, -40, the rotation will be 40, but if it's at -80 -80, the rotation will be 80. Doing something wrong or is this correct?

Also how do I calculate the inertia? Is there a site explaining all these basic math stuff? Would be very cool. =)

##### Share on other sites
Quote:
 Original post by XpointOk, created a new system, so my calculations are now like this:-m_fThrustDirection * ( m_fThrust * m_fThrustPower )This is the force applied to the ship. m_fThrustDirection is the thrust direction (0 -1 for now). m_fThrust is a value of -1.0 to 1.0, tells if thruster is at full power or not. m_fThrustPower is the max power of the thruster (200000 for now, speed is in pixels =P).Now I also want to limit the max speed of the thruster by m_fThrustSpeed, how to add that in my force calculation?

For game, I would just clamp rotational and linear speeds of ship. in space thruster does not have limit of speed, so it's not physically accurate anyway.[smile]

As on physically realistic thruster:
real space thruster have certain exhaust velocity and expells certain mass of fuel per second. Force is equal to change of momentum per time, that is equal to
flow_rate*exaust_velocity
where flow rate can be in kg/second and exhaust_velocity is in meters per second.
Typical values of exhaust velocities can be found there (specific impulse is equal to exhaust_velocity/g where g=9.81 . sorta similar to idea of measuring accelerations of ship in g instead of m/(s^2) )

You can have your own unit so it'll be mass_unit/second and distance_unit/second.

as far as units go, you can use your own unit of mass and unit of length if you do it consistantly. That might be somewhat hard to do, though.
Quote:
 Also I still don't understand how to calculate the torque for my ship. For example using the formula of Raymond_Porter420, when my thruster will be at -40, -40, the rotation will be 40, but if it's at -80 -80, the rotation will be 80. Doing something wrong or is this correct?

this is correct. There's many sorta "counterintuitive" things about torque like this; for example, thruster will provide same linear acceleration to center of mass of ship regardless of where/how far away it is from center of mass.
Quote:
 Also how do I calculate the inertia? Is there a site explaining all these basic math stuff? Would be very cool. =)

If you are interested in moment of inertia (rotational inertia), there's some link to read and if something is not solved there, 'moment of inertia' (without quotes) gives a plenty of results in any search engine.
It depends to distribution of mass in the spaceship. For game, i think you can assume that spaceship is a massive stick, and use
I=(1/12)*m*r^2
where m is mass of ship and r is length of ship.

##### Share on other sites
Quote:
 Original post by Dmytrythis is correct. There's many sorta "counterintuitive" things about torque like this; for example, thruster will provide same linear acceleration to center of mass of ship regardless of where/how far away it is from center of mass.

Still don't get that.. So if my thruster is at -1000 -1000, my ship will rotate like a crazy?? =P

##### Share on other sites
Try closing a door by pushing on it near the hinges. Then try closing it by pushing on it near the side opposite the hinges. You need to push a lot harder to get it to turn if you're pushing near the axis of rotation.

##### Share on other sites
Quote:
Original post by Xpoint
Quote:
 Original post by Dmytrythis is correct. There's many sorta "counterintuitive" things about torque like this; for example, thruster will provide same linear acceleration to center of mass of ship regardless of where/how far away it is from center of mass.

Still don't get that.. So if my thruster is at -1000 -1000, my ship will rotate like a crazy?? =P

Yes.
Of course practically to put thruster at -1000 -1000 you will need to add some sort of support structure that will have some mass, thruster itself is massive. Momentum of inertia will be bigger, so it will not look wrong or crazy. (There's some other more complicated real world factors that could be discarded in game; for example if you keep fuel in the center of ship, pumping of fuel radially to reach thruster will slow down the rotation and set some limit of maximal rotational velocity this thing will settle on. This effect is important in turbines with radial flow, but could be ignored in any reasonable game spacecraft.)

Also, see door example above; similarly, if you manage to push equally hard*, it will rotate much slower when pushed close to hinges. (even if friction is small)

*it is not easy to push equally hard not depending to velocity, like thruster does. Constant forces, in some sense, behave "like crazy" because you don't see many examples in everyday life.
Some not very related example: if you apply force f = 1 newton to m = 1kg for one second (initially at rest), it will travel l=f*t^2/(2*m) = 0.5 meters and work will be l*f = 0.5 joules. If for same second you apply same force to 0.001kg, it will travel 500 meters and work will be 500 joules. I.e. I mean that The Force does not intuitively correspond to "effort".[smile]

[Edited by - Dmytry on September 16, 2005 10:18:24 AM]

##### Share on other sites
Ok, everything gets clear in my head now. =) Currently looking into some math stuff, hope to learn this soon, it's so cool! =D

##### Share on other sites
Ok, now with two thruster on the back, is moves forward, and with two thruster on each side of the ship, it also rotates now!!! Thanks for the help, it realy worked!! =D

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 15
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633352
• Total Posts
3011483
• ### Who's Online (See full list)

There are no registered users currently online

×