Heuristic42
Blog
Opengl
Meta
Rendering
2
comment
Oct 4 at 16:12
Matrices
Want to get millions of people to subscribe to your channel eco…
–
anonymous
comment
Sep 30 at 15:51
Matrices
Need a cost-effective way to reach millions? More Info: http:…
–
anonymous
comment
Sep 23 at 13:15
Matrices
[deleted]
–
anonymous
comment
Sep 21 at 3:52
Contributing
I kind of predicted what was bound to happen when my favourite …
–
anonymous
comment
Sep 6 at 22:21
Route contention when running docker and a VPN
Thank you for this. Between this and the overwriting of iptabl…
–
anonymous
comment
Sep 6 at 14:57
Making a real EMF Reader
Sorry for the random quoted text comments. I am one of those p…
–
anonymous
comment
Sep 6 at 14:48
Making a real EMF Reader
["ove! Play a tone with a buzzer and has 5 LEDs to show the “EM…
–
anonymous
comment
Sep 6 at 14:47
Making a real EMF Reader
["easure direction Measure the magnetic fie"](#q107-644-685)
–
anonymous
comment
Aug 20 at 14:01
Matrices
[deleted]
–
anonymous
comment
Aug 11 at 19:32
Matrices
[deleted]
–
anonymous
edited
Jun 8 at 19:29
Rethinking writing files with memory mapping and C++
This post introduces the motivation behind the [decodless C++ o…
–
admin
created
Jun 8 at 19:16
Rethinking writing files with memory mapping and C++
This post introduces the motivation behind the [decodless C++ o…
–
pknowles
comment
Jun 5 at 10:36
Contributing
just buy the newer model, still on amazon or ebay: https://www.…
–
anonymous
comment
Apr 19 at 8:24
Matrices
[deleted]
–
anonymous
comment
Apr 12 at 21:25
Matrices
[deleted]
–
anonymous
comment
Apr 5 at 6:43
Matrices
[deleted]
–
anonymous
comment
Mar 27 at 14:19
Matrices
[deleted]
–
anonymous
comment
Mar 25 at 1:59
Matrices
[deleted]
–
anonymous
comment
Mar 5 at 12:39
Matrices
[deleted]
–
anonymous
comment
Feb 7 at 2:45
Microsoft Natural Ergonomic 4000 Replacement
Thank you so much for sharing your thoughts here, it tells me e…
–
anonymous
comment
Jan 28 at 20:31
Microsoft Natural Ergonomic 4000 Replacement
Oh man, I feel this post. Not sure if you've seen the "new" new…
–
anonymous
comment
Jan 25 at 9:06
Matrices
[deleted]
–
anonymous
comment
Jan 20 at 0:11
Matrices
[deleted]
–
anonymous
reverted
Dec 21 '23
Route contention when running docker and a VPN
updating to latest
–
admin
…
View All
Log in
Creating an implicit bounce function
leave this field blank to prove your humanity
Article title
*
Article revisions must have a non-empty title
Article body
*
The appeal of an implicit function to model a bouncing object first came when creating the graphs at [/tools/graphs/](/tools/graphs/). Lets say you have a GUI element you want to bounce into view, for example the high scores at the end of a game. You *could* create and store a global $y$ position, model velocity and acceleration, deal with fixed/non-fixed time steps etc. Rather than do that for every item, wouldn't it be great to have a single interpolation function: given a time $t$, what height is my bouncing thing? Imagine you have a ball that starts on the ground with an initial velocity. For a short time the $y$ position can be nicely modelled with a simple quadratic: $$y = 0 + v x + \frac{g}{2}x^2$$ That is, zero initial position, $v$ starting velocity and gravity $g$, which is negative. This works great as the ball flies up, slows, and falls back down just like Newton discovered. The problem is there's nothing to model a collision with the ground again, and a repeated bounce, and another collision etc. Normally there would be a check that looks something like this: if (y < 0) v = -v; This should be modelled by a bounce function. There's also some approximations made which could be improved by an implicit bounce function. Firstly, `y < 0`, so the ball is below the ground. In reality it would have hit the ground and started moving upwards. `y = -y;` would be a good start, but since the true collision at `y == 0` it's still been accelerating downwards when it should have been de-accelerating while moving up. Also, `v = -v;` produces a perfectly elastic collision where no energy is lost. At the time of the bounce, the velocity should also be scaled by a [coefficient of restitution](https://en.wikipedia.org/wiki/Coefficient_of_restitution): `v = -c * v;`. The first thing needed is $n$, an integer that counts bounces as time $t$ increases. Now rather than $v$, the initial velocity of each bounce can be set to $c^n v$ to model successive bounces. Then we just need the time since the start of each bounce $t_b = t - t_n$, and we can create a finished product: $$y(t) = c^n v t_b + \frac{g}{2}t_b^2$$ The following image plots $n$ and $t_b$ to show how they separate the components of each quadratic bounce. ![enter image description here][1] OK, so there's still a few things left to do, namely defining $n$ and $t_b$. A tricky part in doing so is that not only does the the height of successive bounces decrease, but so does the duration of each bounce. The duration $d$ a bounce takes to complete is found by the difference in roots of the quadratic equation above, using the quadratic formula with $a=\frac{g}{2}$, $b=c^n v$ and $c=0$. The absolute of gravity is taken so as not to give a negative $d$. $$ \begin{align} d_n &= \frac{2 \sqrt {b^2 - 4ac} }{2a} \\ &= \frac{b}{a} \\ &= \frac{2 c^n v}{|g|} \end{align} $$ Now that the duration of each bounce is known, the absolute time $t_n$ at the start of each bounce is given by the following recurrence relation: $$ \begin{align} t_0 &= 0 \\ t_n &= t_{n-1} + d_{n-1} \\ &= t_{n-1} + \frac{2 c^{n-1} v}{|g|} \\ &= \frac{2 v (c^n - 1)}{ |g| (c-1) } \end{align} $$ Finally, we have a relationship between $t$ and $n$. It just needs to be inverted: $$ \begin{align} t_n &= \frac{2 v (c^n - 1)}{ |g| (c-1) } \\ c^n &= \frac{t_n |g| (c-1)}{2 v} + 1 \\ n &= \left\lfloor \log_c \frac{t |g| (c-1)}{2 v} + 1 \right\rfloor \end{align} $$ Note that this function asymptotes as the ball bounces to a stop, producing the log of a negative. So as input use $\min(t, t_{10})$ for example to limit the number of bounces to 10. This cancels, but due to the scale by $g$ which is negative, the $min$ changes to a $max$. Putting it all together, and substituting: $$ \begin{align} n(t) &= \left\lfloor \log_c \max\left(\frac{t |g| (c-1)}{2 v} + 1, c^{10} \right) \right\rfloor \\ t_b(t) &= t - \frac{2 v (c^{n(t)} - 1)}{ |g| (c-1) } \\ y(t) &= c^{n(t)} v t_b(t) + \frac{g}{2}t_b(t)^2 \end{align} $$ Finally, there exists a single function to model a bounce. Below is a plot of $y(t)$ created with with $v=7$, $c=0.6$ and $g=-31$. Its green line nicely covers a blue numerical solution for validation, using the midpoint method and the collision approach discussed above. ![enter image description here][2] [1]: /u/img/18f653938d30 [2]: /u/img/5e8562bdc905
Toggle Preview
Edit message
*
A description of the changes made
Discard Draft
Save Draft
leave this field blank to prove your humanity
Flag
the thing you clicked
for moderator attention.
Reason choice:
Spam, promoting, advertising without disclosure
Rude, inappropriate, generally offensive
Too arrogant or demeaning to others
Other
Reason:
The reason for raising the flag
Error