Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Use algebraic integration for better performance and accuracy #49

Open
iamralpht opened this issue Oct 27, 2014 · 4 comments
Open

Use algebraic integration for better performance and accuracy #49

iamralpht opened this issue Oct 27, 2014 · 4 comments

Comments

@iamralpht
Copy link

It's possible to use algebraic integration on the damped spring equation, and you get something that implements the same model as Rebound but is faster to compute, a pure function of time and more accurate than doing a numerical integration like RK4.

I did a Java implementation of this here: https://github.com/iamralpht/gravitas/blob/master/Gravitas/src/com/infinite_imagination/physics/Spring.java (the interface was inspired by Rebound, and I originally made it after playing with Rebound but wanting something fast enough that I could generate keyframes for a spring animation in a couple of ms on device).

Also I transliterated it to JavaScript here:
https://github.com/iamralpht/iamralpht.github.io/blob/master/fab/demo/fab.js (you can see it in action here: http://iamralpht.github.io/fab -- the UI was inspired by the Facebook Home menu system, which I really liked!).

It ends up being a lot less code than Rebound (but maybe Rebound does a lot more than damped springs...).

Finally, here's a link to the physics textbook I cribbed the equations from (although after playing around in Maxima I was able to reproduce them there): http://www.stewartcalculus.com/data/CALCULUS%20Concepts%20and%20Contexts/upfiles/3c3-AppsOf2ndOrders_Stu.pdf

@willbailey
Copy link
Contributor

This is great stuff. I was aware of the algebraic solution, but hadn't looked into implementing it. I did add the ability to precompute the numerical integration in a tight loop to support key frame animations, but I haven't benchmarked that yet to see how the performance is. It'd be really interesting to compare it with this approach and see what the performance gain is. Have you run any benchmarks comparing Gravitas to Rebound? Are there any tradeoffs with the algebraic approach that you are aware of?

Also nice work on the Inbox demo. I wrote the menu system for Facebook Home, and I totally agree with you on the importance of continuous/interruptible gestures and animations.

@iamralpht
Copy link
Author

I haven't benchmarked anything yet, it's on my list :). I'll do it once I've got some demos of Gravitas going.

I don't know of any negative tradeoffs with the algebraic solution for a damped spring. For more complex systems (e.g.: when you drag the message bubbles in iMessage) it probably makes more sense to do something with numerical integration -- you can't integrate every equation. But if all you want to do is damped springs then it's a better solution (imo; numbers pending!).

@ppamorim
Copy link
Contributor

+1

@ghost
Copy link

ghost commented Aug 4, 2015

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants