🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How did people turn this Lagrange equation of a 3d pendulum into a physics simulation?

Started by
3 comments, last by thebypasser 4 years, 3 months ago

Disclaimer: I have a rusty understanding of what a Lagrange equation is. The simplest explanation I have found is it's a way to minimize or maximize a function based on a constraint.

I found this forum post showing how they were able to model a pendulum in 3d. I was wondering if someone could give a more in depth explanation of what they did and how they were able to implement it into code at a level that someone who has only taken Physics 1 can understand.

http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1191.0

I was thinking about using this to create a 3d game around hook-shots and swinging.

Advertisement

I doubt this will help you in any way, as the Lagrange equation is all about the constant system energy, which is not something you'd see in a game or real life (there will be energy input and output due to interactions with at least the character, and additional energy loss due to the air friction). When I need somewhat cute physics, I just go the good old force equation (that is, write down the acceleration in dv/dt form) - integrating it usually ends up in a very simple differential equation that can be solved in-place (involving some exponential function). The fun of it is, you get the proper path-vs-frame-time dependency, so will get the trajectory unchanged even when down to just a few physical frames/second. In some cases it gets crazy though, like in a multiple collisions per frame scenario, or, like, when I was making a realistic BLDC motor that had poles to attract the rotor towards several distinct positions - this one involved some crazy math as ends up in an equation your system can't solve immediately - but still doable in the same style.

can you elaborate on what you mean by "good old force equation?" Do you mean like take the equation: F=ma and solving for the acceleration then integrating that into velocity? Or is it something else?

@jak6jak Sorry, my net was down - and I was too busy to fix it, both at work and here fixing bugs. Anyway. Almost like you said, but better written in dv/dt form, like dv/dt=a, where 'a' is the acceleration (F/m). Solving this finding v(t), and next integrating to get the position deltas is the key to very numerous tasks: say, adding a linear dampening, e.g. dv/dt=a-v*k, makes a very simple differential equation with an exponential solution. And even should a solution become impossible, you always have the step-by-step method ;)

This topic is closed to new replies.

Advertisement