Friday, November 1, 2019

mathematics - Increase restitution (bounciness) of an object in a JavaScript formula


I'm going slightly around the houses on this one. I originally started a thread over on Stack Overflow about it but then it seemed to diverge into mathematics, with no joy from the SO community over there (https://math.stackexchange.com/questions/295485/modify-formula-for-bouncing-object-to-increase-restitution). So my final attempt before I admit complete failure is to ask here. I don't know if you guys do JavaScript, nor how similar this may be to any traditional gaming language, but it's worth asking.


Basically I have the following JavaScript formula representing a bouncing object with gravity, from the standard jQuery UI library: http://code.jquery.com/ui/1.10.0/jquery-ui.js (search for 'Bounce: function'). A demo here shows it in action: http://jsfiddle.net/NtkNB.


Bounce: function ( p ) {
var pow2,

bounce = 4;

while ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {}
return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 );
}

It works nicely but I need to increase the 'bounciness' of the object. I believe this is called 'restitution'.


I've played around with the numbers but it's admittedly just trial and error (mostly error!) and just can't get it to work as desired. I wondered if someone here might be able to understand this and could say whether it's actually possible to increase the restitution of the object within the bounds of this equation, or if not, how it could be modified such.


I totally appreciate any help anyone can give on this one as I've sunk so many hours into this without any joy whatsoever.


Many thanks.





No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...