• Advertisement
Sign in to follow this  

Mass and Inertia Cancelled Out

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
'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 this post


Link to post
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 With

End Sub








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

Share this post


Link to post
Share on other sites
Quote:
Original post by Jacob Roman
Net_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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
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.


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 Nypyren
What 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 this post


Link to post
Share on other sites
Quote:
Original post by Jacob Roman
F = M * A

Where did you get that A from?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement