Re:Modeling a car suspension in Javascript, part 1
by mmcnickle on Monday September 10, 2012 @10:53AM
(#4500092)
Interesting, it's little physics demos like this that started me programming. I went on to specialise in physics modelling as a result. I'd have lapped this stuff back as a teenager.
I see this in a series, is there going to be an introduction to more advanced topics (n-body problems, non-naive integrators), or is it being aimed more at beginners?
Re:Modeling a car suspension in Javascript, part 1
by bkanber on Monday September 10, 2012 @11:02AM
(#4500146)
I'm aiming for the series to have around 30 articles in it. It will include n-body problems, but the series won't just be on mechanics. We'll do heat transfer, electromagnetism, and other fun topics. Maybe even quantum mechanics and special relativity. We'll see how the readers respond to all that!
Re:Modeling a car suspension in Javascript, part 1
by mmcnickle on Monday September 10, 2012 @12:43PM
(#4500671)
Electromagnetism will be tough without a good understanding of the physics first, I think. The quantum mechanics is surprising approachable though. Simulation of a quantum computer is a neat project, especially if written in a way to implement various quantum algorithms.
Re:Modeling a car suspension in Javascript, part 1
by bkanber on Monday September 10, 2012 @12:58PM
(#4500750)
E&M has always been a tricky subject for physics students which is exactly why I want to tackle it! I'll have to figure out a clear and concise way to communicate the concepts to beginners, and while that'll definitely be challenging, it's not a challenge I'll shy away from easily. Bring it on, physics!
Based on own experience if you replace euler with RK4 you can multiply your timestep with 10x and still get more accurate results. Once you start adding constraints this is a must or your constraints will disassemble almost instantly with euler, while rk4 barely requires any after-adjustment to keep the constraints intact.
Re:Modeling a car suspension in Javascript, part 1
by ajross on Monday September 10, 2012 @02:09PM
(#4501147)
That's about right, but note that both Euler and RK4[1] have the same kind of "whiplash" failure modes when faced with out of band inputs. So RK4 is good, and simple, and worth learning. But as you point out it's really just a performance improvement over naive Euler integration[2].
Basically, don't get hung up over pedantry here. Euler is extremely simple, trivially verifiable and works well in a large number of domains. Demanding everyone who wants to do a simple physics model crack open a textbook is, I think, missing the point.
[2] Euler is the simplest possible integration algorithm most people learn in grade school, essentially: compute your derivatives, multiply by the timestep and add to the current value, and repeat. It falls down and produces wild output when the derivative*timestep product is not small in comparison with the current value.
Re:Modeling a car suspension in Javascript, part 1
by bkanber on Monday September 10, 2012 @02:19PM
(#4501216)
Thanks! This article and the other Physics in JS article mention that we're using Euler only because it's the easiest for a student to understand. The article also mentions that the next post will be dedicated to exploring the different integration solvers.
My guess is that the original commenter just skimmed through the code without reading any of the prose ;)
Re:Modeling a car suspension in Javascript, part 1
by bkanber on Monday September 10, 2012 @02:18PM
(#4501200)
You're right!
However, both in this article and a previous article I point out that Euler is the least accurate of the numerical integration methods.
I also mention several times that there will be an upcoming article dedicated to exploring other integration techniques.
Additionally, in the previous article I mention that the reason we're using Euler's method is because it's the easiest for a student to look at and understand at a glance, not because it's the best or only technique.
Finally, other articles mentioned that we are not going through these exercises with game dev or optimization in mind. These are educational articles about physics and physics alone.
But as I said, you're right. Anywhere outside of the scope of education, Euler's method is not the best choice.
Re:Modeling a car suspension in Javascript, part 1
by stephengillie on Monday September 10, 2012 @12:16PM
(#4500542)
This reminds me of a mechanical-modeling "computer" that Lee Iacocca described in his autobiography. Resistors were used as struts, capacitors as springs, etc. The magnetic force of the electricity represented the force of gravity as the modelled car traveled along the simulated road.
Re:Modeling a car suspension in Javascript, part 1
by bkanber on Monday September 10, 2012 @12:36PM
(#4500636)
There are direct parallels between mechanical systems, electrical circuits, and plumbing systems. Three totally different systems can be modeled by the same exact equations!
Re:Modeling a car suspension in Javascript, part 1
by compumike on Monday September 10, 2012 @01:22PM
(#4500883)
Yes -- exactly why electrical circuit simulation tools sometimes get used in non-electronics contexts. Here's a simulation of your spring-mass-dashpot system in CircuitLab (JS-based circuit simulator, which also works for some mechanical models like this): https://www.circuitlab.com/circuit/pr4n2d/physics-car-suspen...
Re:Modeling a car suspension in Javascript, part 1
by sgaither on Monday September 10, 2012 @09:40AM
(#4499683)
Neat! I hope physics classes today are getting more into using such web interactive modeling. Or, that the new wave of interactive books are leveraging this kind of ability.
Re:Modeling a car suspension in Javascript, part 1
by agumonkey on Monday September 10, 2012 @10:01AM
(#4499767)
Repeating myself a bit, but this article with embedded jsfiddle, Bret Victor (http://worrydream.com/), and ipython notebook work. The distance between communication/education and execution is getting smaller and smaller. Symbolically flipping the debugging coin on both of its side at the same time.
I see this in a series, is there going to be an introduction to more advanced topics (n-body problems, non-naive integrators), or is it being aimed more at beginners?
Based on own experience if you replace euler with RK4 you can multiply your timestep with 10x and still get more accurate results. Once you start adding constraints this is a must or your constraints will disassemble almost instantly with euler, while rk4 barely requires any after-adjustment to keep the constraints intact.
http://gafferongames.com/game-physics/fix-your-timestep/ would also be a nice improvement to the simulations.
Basically, don't get hung up over pedantry here. Euler is extremely simple, trivially verifiable and works well in a large number of domains. Demanding everyone who wants to do a simple physics model crack open a textbook is, I think, missing the point.
[1] Fourth order Runge-Kutta integration, a common and reasonably simple algorithm for numeric integration. See: http://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods
[2] Euler is the simplest possible integration algorithm most people learn in grade school, essentially: compute your derivatives, multiply by the timestep and add to the current value, and repeat. It falls down and produces wild output when the derivative*timestep product is not small in comparison with the current value.
My guess is that the original commenter just skimmed through the code without reading any of the prose ;)
However, both in this article and a previous article I point out that Euler is the least accurate of the numerical integration methods.
I also mention several times that there will be an upcoming article dedicated to exploring other integration techniques.
Additionally, in the previous article I mention that the reason we're using Euler's method is because it's the easiest for a student to look at and understand at a glance, not because it's the best or only technique.
Finally, other articles mentioned that we are not going through these exercises with game dev or optimization in mind. These are educational articles about physics and physics alone.
But as I said, you're right. Anywhere outside of the scope of education, Euler's method is not the best choice.
We also have some combined electrical and thermal systems such as https://www.circuitlab.com/circuit/a4xaa6/sous-vide-combined... . Looking forward to the rest of your blog series!
http://www.walter-fendt.de/ph14e/
Which are Java applets. Not quite as good as modern JS would be, but given the era they were written, they were pretty cool things.
Although they are also not done in javascript, but a mix of java and flash.
(All are Java applets.)