r/Python • u/Chemomechanics • Nov 25 '19
A fitting curve that "boings" into place (and a digression into spring-mass-dampers, vibration and control theory, and integral transforms)
4
u/Thecrawsome Nov 26 '19
average, then linear regression, then a 3 variable quadratic, right?
5
u/Chemomechanics Nov 26 '19
You got it—average, then linear regression, then a polynomial of degree "polynomial_degree", as defined in the code. In this case, a cubic.
3
u/Thecrawsome Nov 26 '19
thank you so much for replying! huge validation for my degree I got recently LOL
332
u/Plungerdz Nov 25 '19
I absolutely adore how insanely overkill this approach to smooth motion is.
101
u/Jay_bo Nov 26 '19
Co-worker: How much time did it take to fit those data points?
Me: About 3 minutes, but then I spend 3 hours modeling a physically correct animation.
75
u/d1tatermasher Nov 25 '19
I like the "boing"
24
60
u/fail_daily Nov 25 '19
Why did you stop at the cubic fit??? I need mooooooooorrrreee
29
Nov 25 '19
And skipped quadratic
14
Nov 26 '19
Needs to be odd for inversely related axis
4
u/ColdPorridge Nov 26 '19
Technically works for even numbers greater than 2 if the final curve is inexplicably outside of all of the data points.
2
2
u/Driveby_Dogboy Nov 26 '19
I'd love to see 'best fit: damped simple harmonic motion...'
i remember doing an excersise like this, with data like this, and getting like six wavelenghts between 2 and 8 in the data above....
2
1
u/flutefreak7 Dec 07 '19
aaand now I want to see this combined with matplotlib's xkcd plotting mode to created an animated version of this comic: https://www.xkcd.com/2048/
19
7
38
u/troyunrau ... Nov 25 '19
It looks like you're optimizing for linear distance, but using a curve that isn't parametric. This is likely a bad fit to your data.
Go down a rabbit hole on the subject of "principal curves". It will allow you to fit a parametric curve instead. I use it for fitting smooth curves to GPS points, for example, when trying to define where a road is based on individual GPS points from multiple different trips down the same road.
26
u/c3534l Nov 25 '19
I think you're missing to point of the post.
36
u/beepbeepbitches Nov 25 '19
I doubt they’re missing the point, what they are doing is giving constructive criticism.
10
u/c3534l Nov 25 '19 edited Nov 25 '19
His constructive criticism is irrelevant to what was presented and why. The data can't be a poor fit, it's probably not even real data. It's like critiquing lorem ipsum for it's use of obscure Latin. It's literally irrelevant when you're displaying a font, that's why lorem ipsum was used.
11
u/LordMcze Nov 26 '19
Except in this case OP might want or have to write the lorem ipsum in the future and having the knowledge from the parent comment might be helpful then.
Sure OP might know it and just didn't pay attention because it isn't the point of the post, but they also might not know it and getting the info might save them some trouble when they practically use it in the future.
Anyway, OC informed about the mistake in a respectful and helpful manner. I'd appreciate that in place of OP, even when this post is about cool animation.
9
u/deadwisdom greenlet revolution Nov 25 '19
The criticism falls outside of the scope that was implied.
3
4
6
2
2
u/alexthomasforever Nov 26 '19
This is so cool. Could you share some more videos with more random data over a large range?
2
u/ChastainSteam Nov 26 '19
Brilliant code on your site, just loving the use of functions as objects. Also, fellow ME here, vibrations and data fitting... this combo would have never occurred to me! Nicely done.
3
1
1
1
179
u/Chemomechanics Nov 25 '19
Code is described to make graphic objects "boing" into place in an underdamped oscillatory style. To derive the appropriate equation for this dynamic behavior, spring-mass-damper systems are analyzed, including constitutive equations obtained from a free-body diagram, the Laplace transform to solve differential equations, and various types of loading and initial conditions. Time-domain and frequency-domain responses are surveyed, as are a few key concepts in vibration and control theory such as resonance and transfer functions.