# Mass and Inertia Cancelled Out

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

## Recommended Posts

So far everything's fine in my physics engine, except the mass and inertia seem useless cause it gets cancelled out. Just before I integrate, I have it like so: F = M * A; //(With 'A' being my force value) A = F / M; //Integration done here Am I doing something wrong here?

##### Share on other sites
'A' should not be a force, it should be acceleration. You apply 'F' and calculate 'A'. The mass, 'M', will scale the effect of a force, i.e. objects with greater mass will accelerate more slowly than objects with less mass when the same force is applied to both.

You can divide force by mass to get the acceleration. You cannot do that with the moment of inertia because it is a matrix. Instead, you effectively need to invert it. I say 'effectively' because you shouldn't calculate the inverse directly but solve the linear system, but since you're writing a physics engine I guess you already know that.

##### Share on other sites
Quote:
 Original post by jjd'A' should not be a force, it should be acceleration. You apply 'F' and calculate 'A'. The mass, 'M', will scale the effect of a force, i.e. objects with greater mass will accelerate more slowly than objects with less mass when the same force is applied to both.You can divide force by mass to get the acceleration. You cannot do that with the moment of inertia because it is a matrix. Instead, you effectively need to invert it. I say 'effectively' because you shouldn't calculate the inverse directly but solve the linear system, but since you're writing a physics engine I guess you already know that.

Hehe, actually I didn't know that. But I'm still learning. I'm getting better at writing physics engines at least. So what you are saying is, I should do this, right?

---------------------------------------------------
Net_Force = Mass * (Net_Force / Mass) // Since A = F/M
Acceleration = Net_Force / Mass
---------------------------------------------------

It still gets cancelled out. Or wait a minute. Are you saying to just calculate acceleration, and just let force be a value, which is my total amount of forces applied?

Oh and here's part of the code I currently have relating to my thread topic:

Public Sub Integrate2D(Obj As PHYSICS2D, dt As Single, Integrator As CONST_INTEGRATOR)    Dim k1 As POINT2D, k2 As POINT2D, k3 As POINT2D, k4 As POINT2D    Dim l1 As VECTOR2D, l2 As VECTOR2D, l3 As VECTOR2D, l4 As VECTOR2D        Dim m1 As Single, m2 As Single, m3 As Single, m4 As Single    Dim n1 As Single, n2 As Single, n3 As Single, n4 As Single        Dim Force As VECTOR2D    Dim Torque As Single        With Obj            Force.X = .Force.Net.X * .Mass                                        Force.Y = .Force.Net.Y * .Mass                .Acceleration.X = Force.X / .Mass        .Acceleration.Y = Force.Y / .Mass                Torque = .Torque.Net * .Inertia        .Angular_Acceleration = Torque / .Inertia                Select Case Integrator                    Case FORWARD_EULER                        .Position.X = .Position.X + .Velocity.X * dt                .Velocity.X = .Velocity.X + .Acceleration.X * dt                            .Position.Y = .Position.Y + .Velocity.Y * dt                .Velocity.Y = .Velocity.Y + .Acceleration.Y * dt                                .Angle = .Angle + .Angular_Velocity * dt                .Angular_Velocity = .Angular_Velocity + .Angular_Acceleration * dt                            Case SECOND_ORDER_EULER                            .Position.X = .Position.X + .Velocity.X * dt + 0.5 * .Acceleration.X * dt * dt                .Velocity.X = .Velocity.X + .Acceleration.X * dt                            .Position.Y = .Position.Y + .Velocity.Y * dt + 0.5 * .Acceleration.Y * dt * dt                .Velocity.Y = .Velocity.Y + .Acceleration.Y * dt                                .Angle = .Angle + .Angular_Velocity * dt + 0.5 * .Angular_Acceleration * dt * dt                .Angular_Velocity = .Angular_Velocity + .Angular_Acceleration * dt                        Case VERLET                            .Velocity.X = .Position.X - Old_Position.X + .Acceleration.X * dt * dt                Old_Position.X = .Position.X                .Position.X = .Position.X + .Velocity.X                                .Velocity.Y = .Position.Y - Old_Position.Y + .Acceleration.Y * dt * dt                Old_Position.Y = .Position.Y                .Position.Y = .Position.Y + .Velocity.Y                                .Angular_Velocity = .Angle - Old_Angle + .Angular_Acceleration * dt * dt                Old_Angle = .Angle                .Angle = .Angle + .Angular_Velocity                            Case VELOCITY_VERLET                                Old_Acceleration.X = .Acceleration.X                .Position.X = .Position.X + .Velocity.X * dt + 0.5 * Old_Acceleration.X * dt * dt                .Velocity.X = .Velocity.X + 0.5 * (Old_Acceleration.X + .Acceleration.X) * dt                            Old_Acceleration.Y = .Acceleration.Y                .Position.Y = .Position.Y + .Velocity.Y * dt + 0.5 * Old_Acceleration.Y * dt * dt                .Velocity.Y = .Velocity.Y + 0.5 * (Old_Acceleration.Y + .Acceleration.Y) * dt                            Old_Angular_Acceleration = .Angular_Acceleration                .Angle = .Angle + .Angular_Velocity * dt + 0.5 + Old_Angular_Acceleration * dt * dt                .Angular_Velocity = .Angular_Velocity + 0.5 * (Old_Angular_Acceleration + .Angular_Acceleration) * dt                        Case SECOND_ORDER_RUNGE_KUTTA                            k1.X = dt * .Velocity.X                k1.Y = dt * .Velocity.Y                l1.X = dt * .Acceleration.X                l1.Y = dt * .Acceleration.Y                                k2.X = dt * (.Velocity.X + k1.X / 2)                k2.Y = dt * (.Velocity.Y + k1.Y / 2)                l2.X = dt * .Acceleration.X                l2.Y = dt * .Acceleration.Y                                m1 = dt * .Angular_Velocity                n1 = dt * .Angular_Acceleration                                m2 = dt * (.Angular_Velocity + m1 / 2)                n2 = dt * .Angular_Acceleration                                .Position.X = .Position.X + k2.X                .Position.Y = .Position.Y + k2.Y                .Velocity.X = .Velocity.X + l2.X                .Velocity.Y = .Velocity.Y + l2.Y                                                .Angle = .Angle + m2                .Angular_Velocity = .Angular_Velocity + n2                        Case THIRD_ORDER_RUNGE_KUTTA                            k1.X = dt * .Velocity.X                k1.Y = dt * .Velocity.Y                l1.X = dt * .Acceleration.X                l1.Y = dt * .Acceleration.Y                                k2.X = dt * (.Velocity.X + k1.X / 2)                k2.Y = dt * (.Velocity.Y + k1.Y / 2)                l2.X = dt * .Acceleration.X                l2.Y = dt * .Acceleration.Y                                k3.X = dt * (.Velocity.X - k1.X + 2 * k2.X)                k3.Y = dt * (.Velocity.Y - k1.Y + 2 * k2.Y)                l3.X = dt * .Acceleration.X                l3.Y = dt * .Acceleration.Y                                m1 = dt * .Angular_Velocity                n1 = dt * .Angular_Acceleration                                m2 = dt * (.Angular_Velocity * m1 / 2)                n2 = dt * .Angular_Acceleration                                m3 = dt * (.Angular_Velocity - m1 + 2 * m2)                n3 = dt * .Angular_Acceleration                                .Position.X = .Position.X + k1.X * 1 / 6 + k2.X * 2 / 3 + k3.X * 1 / 6                .Position.Y = .Position.Y + k1.Y * 1 / 6 + k2.Y * 2 / 3 + k3.Y * 1 / 6                .Velocity.X = .Velocity.X + l1.X * 1 / 6 + l2.X * 2 / 3 + l3.X * 1 / 6                .Velocity.Y = .Velocity.Y + l1.Y * 1 / 6 + l2.Y * 2 / 3 + l3.Y * 1 / 6                                .Angle = .Angle + m1 * 1 / 6 + m2 * 2 / 3 + m3 * 1 / 6                .Angular_Velocity = .Angular_Velocity + n1 * 1 / 6 + n2 * 2 / 3 + n3 * 1 / 6                            Case FORTH_ORDER_RUNGE_KUTTA                            k1.X = dt * .Velocity.X                k1.Y = dt * .Velocity.Y                l1.X = dt * .Acceleration.X                l1.Y = dt * .Acceleration.Y                                k2.X = dt * (.Velocity.X + k1.X / 2)                k2.Y = dt * (.Velocity.Y + k1.Y / 2)                l2.X = dt * .Acceleration.X                l2.Y = dt * .Acceleration.Y                                k3.X = dt * (.Velocity.X + k2.X / 2)                k3.Y = dt * (.Velocity.Y + k2.Y / 2)                l3.X = dt * .Acceleration.X                l3.Y = dt * .Acceleration.Y                                k4.X = dt * (.Velocity.X + k3.X)                k4.Y = dt * (.Velocity.Y + k3.Y)                l4.X = dt * .Acceleration.X                l4.Y = dt * .Acceleration.Y                                m1 = dt * .Angular_Velocity                n1 = dt * .Angular_Acceleration                                m2 = dt * (.Angular_Velocity + m1 / 2)                n2 = dt * .Angular_Acceleration                                m3 = dt * (.Angular_Velocity + m2 / 2)                n3 = dt * .Angular_Acceleration                                m4 = dt * (.Angular_Velocity + m3)                n4 = dt * .Angular_Acceleration                                 .Position.X = .Position.X + k1.X / 6 + k2.X / 3 + k3.X / 3 + k4.X / 6                .Position.Y = .Position.Y + k1.Y / 6 + k2.Y / 3 + k3.Y / 3 + k4.Y / 6                .Velocity.X = .Velocity.X + l1.X / 6 + l2.X / 3 + l3.X / 3 + l4.X / 6                .Velocity.Y = .Velocity.Y + l1.Y / 6 + l2.Y / 3 + l3.Y / 3 + l4.Y / 6                                .Angle = .Angle + m1 / 6 + m2 / 3 + m3 / 3 + m4 / 6                .Angular_Velocity = .Angular_Velocity + n1 / 6 + n2 / 3 + n3 / 3 + n4 / 6                        End Select            End WithEnd Sub

[Edited by - Jacob Roman on June 1, 2006 11:20:43 AM]

##### Share on other sites
Quote:
 Original post by Jacob RomanNet_Force = Mass * (Net_Force / Mass) // Since A = F/M

Well, that's fairly tautological.

Quote:
 Acceleration = Net_Force / Mass

That's what you should be doing. You apply a bunch of forces to your object. You add them together and the result is a vector that tells you what the total force is. Now scale that vector by 1/Mass to obtain the acceleration vector. Use that acceleration vector to integrate.

Quote:
 It still gets cancelled out.

What gets cancelled out?

Quote:
 Or wait a minute. Are you saying to just calculate acceleration, and just let force be a value, which is my total amount of forces applied?

That's about right, except I don't know what you mean by "let force be a value".

##### Share on other sites
You are applying accelerations to objects; however, you should be applying forces to objects. A force is then divided by the objects mass to determine the acceleration of an object. So for example, a force of 50N will accelerate a 50kg object at 1m/s^2, whereas it will accelerate a 1kg object at 50m/s^2.

If you're having trouble with the concept of forces, you should probably read this.

##### Share on other sites
Quote:
Original post by alvaro
Quote:
 Original post by Jacob Roman It still gets cancelled out.

What gets cancelled out?

The mass from force does. Take a look:

F = M * A
F = M * (F / M)
F = F

Quote:
Original post by alvaro
Quote:
 Original post by Jacob Roman Or wait a minute. Are you saying to just calculate acceleration, and just let force be a value, which is my total amount of forces applied?

That's about right, except I don't know what you mean by "let force be a value".

From the above quote, that's what I meant. Since F = F, then A = F / M, thus allowing the force to be scaled from whatever the mass is. That way there, heavy objects move slower than fast ones.

##### Share on other sites
Force causes acceleration. Not the other way around. There are certain isolated artificial situations where you might want to set the acceleration directly, but 99% of the time you will start knowing the force and from there figure out the acceleration.

##### Share on other sites
What is your source of forces? If you're doing planetary gravity, then you will find that when an object is being attracted by a planet, the object's mass cancels out of its own acceleration equation. Thus, two objects of different sizes will accelerate at the same rate toward the planet in a vacuum. The planet will also accelerate at a different rate back towards the two different objects.

##### Share on other sites
Quote:
 Original post by SneftelForce causes acceleration. Not the other way around. There are certain isolated artificial situations where you might want to set the acceleration directly, but 99% of the time you will start knowing the force and from there figure out the acceleration.

So what am I suppose to do in my code then? I can't really have this since it would make mass practically useless:

F = M * A
A = F / M

And what am I suppose to make 'A' in F = M * A, since F / M is "fairly tautological?"

Quote:
 Original post by NypyrenWhat is your source of forces?

Well in my current program, I'm mostly working with Torque than anything since it's my turntable simulation (soon to be DJ program once I program the DirectSound part). So the forces I'm working with are Applied, Friction, and not sure what it's called, but the motor that automatically spins the vinyl record is another force, set at 1 kmf-cm (9.8 Newtons). The physics are very nice so far, and it feels like it's a real turntable! Here's a snapshot of it:

##### Share on other sites
Quote:
 Original post by Jacob RomanF = M * A

Where did you get that A from?

##### Share on other sites
Quote:
Original post by Sneftel
Quote:
 Original post by Jacob RomanF = M * A

Where did you get that A from?

It was originally my net force, but I changed it to F/M, and now everyones saying not to do that, and now I dunno what I can do. Any pointers?

##### Share on other sites
Quote:
 F = M * AA = F / MAnd what am I suppose to make 'A' in F = M * A, since F / M is "fairly tautological?"

You're not supposed to do anything, because you're not supposed to use "F=M*A". You don't need to calculate the force, because you provide the forces to the objects. Along with the masses, they're a given. You need to then calculate the accelerations(A=F/M), the velocities(V=V+A*dt) and so on.

##### Share on other sites
Alright. Here is what you do.

FIRST, decide what the net force F is, based on contact forces, gravity, tension, spring forces, whatever.

SECOND, divide force F by mass M to get acceleration A.

THIRD, integrate based on that acceleration.

That's all there is to it.

##### Share on other sites
It's about physics here and you're using Newton's law.

What does it mean? It means that when you apply force to an object (say, you push it), it'll accelerate. The more mass the object has, the less it will accelerate from a tiny bit of force.

So, in formula this means a = F / m with

a -> acceleration (in meters per second^2, ms^{-2})
F -> force (in Newton, N)
m -> mass (in kilogram, kg)

In your system you apply force and, using that and the known mass of the object, calculate it's acceleration.

After you've calculated the acceleration, you can accelerate (increase the velocity) of the object:

delta v = a * delta t with

delta v -> chance in velocity (in meters per seconds, ms^{-1})
a -> acceleration (in meters per second^2, ms^{-2})
delta t -> time (in seconds, s)

So, I'll give an example.

I apply 10 Newton of force (F = 10N) to an object of known mass, m = 5.0kg. The object will accelerate:

a = F / m = 10 / 5.0 = 2.0ms^{-2}

It's velocity will increase by 2.0 meters per second, per second. Let's say I apply that same force for 3.0 seconds (delta t = 3.0s). The velocity will change (it will increase, because a > 0):

delta v = a * delta t = 2.0 * 3.0 = 6.0ms^{-1}

So, over the course of those 3.0 seconds, my velocity increased with 6.0 meters per second, because I kept applying 10 Newton of force.

PS: If you apply more than one force at the same time, the F used in Newton's law (a = F / m) is the sum of all applied forces. F, a and v are vectors, which means they have both a direction and size.

Here's Eulers method (let's not start bickering about how bad is) in C.

a = F / m;
v += a * dt;
position += v * dt;

with dt being the time passed since the last simulation. In this model, you need to know: F (the net force) and m (the mass of the object)

Edit: Oh lol maybe I went a bit overboard

##### Share on other sites
Finally some real answers! Thanks people.

Now that the position, velocity, and acceleration stuff is out of the way, let's talk about Torque since that's what I'm mainly working with in my current program.

I already calculated my moment of inertia (1/2 * m * r * r) and put it in a constant, and I was treating it like F = MA since I saw a similar formula for torque:

T = I * α // (Moment of Inertia * Angular Acceleration)

But after seeing this post:

Quote:
 You can divide force by mass to get the acceleration. You cannot do that with the moment of inertia because it is a matrix. Instead, you effectively need to invert it. I say 'effectively' because you shouldn't calculate the inverse directly but solve the linear system, but since you're writing a physics engine I guess you already know that.

I don't know what to do. He's saying it's a matrix, but how can it be?

##### Share on other sites
I think jjd talked about the general case. In your case(a disk), the moment of inertia can be reduced to the scalar I=(m*R^2)/2

##### Share on other sites
That's what I just did though.

##### Share on other sites
When a force applies to an object, most of the times there's also torque. Torque depends on where the force is applied, relative to the center of its mass.

torque = r X F with

r being the arm between the point where the force is applied and the center of the objects mass

In that formula X' symbolises something called the 2D pseudo cross product' or `perp. dot product':

torque = r_x * F_y minus r_y * F_x with

r_x, r_y being the x- and y-component of vector r
F_x, F_y being the x- and y-component of the vector F

Angular acceleration depends on the mass and shape of the object. This is called
inertia. For a 2D rectangle, this is:

inertia = (1/12) * m * (l^2 plus h^2), which is constant just like mass

Torque, inertia and acceleration relate to each other, just like force, mass and acceleration (remember a = F / m):

alpha = torque / inertia with

An example:

Let's say I apply a force (F = 4.0N) in the bottom left corner of a rectangle shaped object (m = 5.0kg) with width = 1.0m and height = 2.0m. I push the object up.

I know its dimensions and mass, so I can calculate its inertia:

inertia = (1/12) * m * (l^2 plus h^2) = (1/12) * 5.0 * (1.0^2 + 2.0^2) = 25/12 = 2.1

Now we do have to use vectors to describe what force and where it applied to the object: (my written format here is (x, y)-component)

F = ( 0.0, 4.0 ) -> I push upwards with 4.0 Newtons. It's length (Pythagoras) is the amount of force applied.
r = ( -0.50, -1.0 ) -> I push in the bottom left corner, relative to the objects center point of mass

So, we know where and what force applied, and we'll calculate torque. Torque determines how fast my object will increase its angular velocity (called angular acceleration).

torque = r_x * F_y minus r_y * F_x = -0.50 * 4.0 - -1.0 * 0.0 = -2.0

Angular acceleration, just like (a = F / m), can be calculated now:

alpha = torque / inertia = -2.0 / 2.1 = -0.96 rads^{-2}

Its angular velocity will thus increase by -0.96 radians per second, per second.

delta angular velocity = alpha * delta t

Lets say I applied the force for 3 seconds, always pointing towards the top of the object, my angular velocity will have changed

delta angular velocity = alpha * delta = -0.96 * 3.0 = -2.9rads{-1}

Let's put it into C:

void apply_force( c_Vector2f F, c_Vector2f r )
{
this->F += F;
this->torque += r.x * F.y - r.y * F.x;
}
// This was a snippet out of some old code of mine, partially
// NeHe I think. I just put it here to show how torque is
// calculated using vectors.

rotational_speed += ( torque / inertia ) * dt;
theta += rotational_speed * dt;

with theta being the angle the object is rotated at.

Note: I have not been taught this in school or university yet :P, I figured it out through websites. It is thus prone to mistakes and any real physicist may disagree on it.

Edit: This one was even worse than the previous one :P

##### Share on other sites
Whoh, thanks for the info, but the cross product is not needed in my case. Once I hold the left mouse button with my cursor over the "circular" vinyl (used distance formula to test that), if I move up or left, the cursor and the vinyl rotates counter clockwise. If I move down or right, the cursor and vinyl rotate clockwise. Just two directions there. And if I release it during movement, whatever the delta angle is will be the speed it will spin, with friction slowing it down.