Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Physics Forces Over Time

Author
Message
flashing snall
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Boston
Posted: 9th Jul 2011 03:45 Edited at: 9th Jul 2011 03:50
Hi.
I am trying to write a physics engine without the use of external plug ins. I am running into an issue that I cant find a way around, and I thought you guys might be able to help.

If an object is being pulled towards a place via a location dependent force such as a spring or gravity or magnetism or any force, the force only acts every update call. However, the body's location may have changed a great deal inbetween updates. The force should have acted at every single location along the path, but since it doesnt, the path becomes inaccurate. Here are some pictures to get the idea across...



Any ideas?http://gyazo.com/e1f0d9ea5064cea18c71455448aafe81.png

heyufool1
16
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 9th Jul 2011 03:48
Might just be me, but I don't see the pictures.

"So hold your head up high and know. It's not the end of the road"
Switch Game Engine
flashing snall
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Boston
Posted: 9th Jul 2011 03:51
Sorry, Gyazo isnt nice. Click the link for all three

Plystire
22
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 9th Jul 2011 04:27 Edited at: 9th Jul 2011 04:28
You need to either make an assumption of how long each update takes or track the time each update took, run the maths using that time interval on the object to provide the necessary increments over time. However, I don't see this being much more accurate than performing the calculations normally.

From your explanation, I figured this would have been something a bit more complex, so as an object being drawn to another object that is in motion, that is being drawn to another in motion (basic solar system in action) and the arcs being made between updates not being taken into account. When it comes to computing physics, some form of estimation is necessary as real-time physics simply cannot be perfectly simulated.


~Plystire

A rose is only a rose until it is held and cherished -- then it becomes a treasure.
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 9th Jul 2011 12:43
As Plystire said, physics engines are just an approximation of reality. You can't do something truly realistic in real time. So you simply have to decide how real you want it verses how fast you want it to run, and strike a balance.

I would guess most real-time physics engines would simply apply forces at each time increment, based on where the bodies are at that point in time. A force is is proportional to time anyway, so if you update once per second, the force is x per update, and if you update 10 times per second, the force is 0.1x. So the force is the same, it's just the directional component that loses accuracy.

The only exception to updating once per interval and ignoring the time in between, would be for collision, where you need to consider the path of objects during that time to ensure they don't teleport through objects if they're moving fast enough to skip over them entirely.

flashing snall
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Boston
Posted: 9th Jul 2011 16:44
A force is not proportional to time. Forces are instantaneous, they just happen at every single instance. In all the force equations I can think of, none of them include a time variable

spring . F = kx
Gravity . F = GmM / r^2
Friction . F = -bV^k

Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 9th Jul 2011 17:00 Edited at: 9th Jul 2011 17:01
To solve it perfectly you would have create a system of differential equations describing the motion of the object, and then solve them to get its position at a given time.

Since this is a physics engine you don't know what these equations will be until runtime, so you would have to write a program to solve systems of differential equations (definitely not easy or efficient).

Although it's impractical to solve it perfectly, you can make the simulation more realistic by using a fixed time-step internally. (Divide up the time-step into multiples of this fixed time-step) Event though it won't be truly accurate, at least you'll get consistent results regardless of the frame-rate.

[b]
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 9th Jul 2011 17:15 Edited at: 9th Jul 2011 17:22
Quote: "In all the force equations I can think of, none of them include a time variable"


f = ma, where acceleration is velocity increase over time (meters/second usually). My physics is rusty, but I believe you can think about them as instantaneous forces (measure the force at any given instant in time on an object, or the force a mechanical system can exert), or in this example, total force required to accelerate objects of a certain mass.

Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 9th Jul 2011 22:15
Quote: "solve systems of differential equations (definitely not easy or efficient)."


and, even more fun: for sort-of complicated real world examples, like three objects under universal gravitation, there is NO exact solution for the general case.

You HAVE to go with some sort of integration method. What I presume you're doing right now is Euler integration.

If this doesn't really make sense, then... well, basically lets call position P, and the instantaneous velocity at any given point in time, V. So, every frame:
P+=V(t). (like I said, V returns the velocity at any given point in time, therefore V(t))

In other words, V(t) is the rate of change of P. So:
P'=V(t)

aaaand then you get to decide what sort of integration method you want to use to calculate the next P. In the equation P+=V(t), that's Euler integration. You could use verlet integration or Runge-Katta integration, but like usual you sacrifice speed for accuracy.


Why does blue text appear every time you are near?
flashing snall
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Boston
Posted: 10th Jul 2011 00:21
I had Euler, but now Im running RK4. The speed drop isnt much of a problem at all.

F = ma is not correct. Fsum = ma is correct. The sum of forces is not so much a force as it is another name for a different force.

Plystire
22
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 10th Jul 2011 00:53
I see what you're talking about now. You want to be able to calculate the missing acceleration that would have been added in the empty spaces between updates.

Well... if you're only wanting to deal with impulse forces, you're not missing anything really. The time step of your updates is more than likely within a 2% error margin of the "real world scenario".

Now, your equations may not state that time is involved, but it always is. The equations must be used at set intervals of time. If time did not move, force would not be applied. Simple fact of the universe.
If you really want to perfect the system more, you need to split up the update routine into set time intervals and apply the forces at those intervals (more likely several times per update).


~Plystire

A rose is only a rose until it is held and cherished -- then it becomes a treasure.
flashing snall
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Boston
Posted: 10th Jul 2011 02:13
Impulse forces are fine, its the springs and gravity forces that are causing havoc.
When a body gets close to a strong gravity center, the force grows VERY large, which gives the body a VERY large velocity, so that in one update call, it winds up far away from the gravity center, and next update call, the attractive force is almost nothing, because the distance is so great.

Plystire
22
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 10th Jul 2011 04:03
Isn't that the slingshot effect in action?

It sounds like you're allowing objects to approach a gravity center too closely. Gravity is usually centered inside of an object, thus not allowing other objects to get that close.

I remember making a small 2D solar system with gravity wells on all the different satellites, and it sure took a lot of fine tuning to keep my ship from getting sucked into a planet or slingshotting out into the black oblivion.


~Plystire

A rose is only a rose until it is held and cherished -- then it becomes a treasure.

Login to post a reply

Server time is: 2025-05-21 05:48:37
Your offset time is: 2025-05-21 05:48:37