Closed Thread Icon

Preserved Topic: Acceleration/Deceleration (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18263" title="Pages that link to Preserved Topic: Acceleration/Deceleration (Page 1 of 1)" rel="nofollow" >Preserved Topic: Acceleration/Deceleration <span class="small">(Page 1 of 1)</span>\

 
Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 06-11-2002 19:22

I'm trying to write a script that moves a layer up and down on command to display some content and I want it to do this nifty little 0 to (whatever) acceleration when it starts and another nifty little (whatever) to 0 deceleration when it stops..

how does the math work on this?


Harmonizing new illusions...
ICQ: 67751342

u-neek
Bipolar (III) Inmate

From: Berlin, Germany
Insane since: Jan 2001

posted posted 06-11-2002 20:19

This might help you: http://www.ozoneasylum.com/Forum2/HTML/001365.html

Hugh
Paranoid (IV) Inmate

From: Dublin, Ireland
Insane since: Jul 2000

posted posted 06-12-2002 14:59

How I'd do it is:
get the difference between the target(where you want the layer to go) and where it is. Divide that by ten and add it to where it is. Then repeat. Um, that doesnt seem very understandable:

currentX += (targetX-currentX)/10;

and repeat
This will go very fast if its very far away from where you want it to go, then slow down when it gets near.

Or if you want it to speed up and slow down, you could use sine wave type mathery like

r = (NewX-OldX)/2
X = r*Math.coz(angle);

angle being a number going from 0 to ~6.27 (Math.PI*2)

Im not sure if this would work at all. its just a thought.

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 06-25-2002 12:56

Started an FAQ on this:
http://faq.ozoneasylum.com/651/

___________________
Emps

FAQs: Emperor

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-25-2002 15:12

The method Hugh described will have the object move at a decaying exponential rate. (Make a graph of y=e^(-x) and that's a graph of how close the object is to its destination as a function of time.)

A more accurate acceleration/deceleration model, with constant acceleration or decelaration, would be parabolic. However, this requires knowing when the acceleration starts and stops, and you might not want the acceleration to suddenly change from positive to negative.

So what I usually do in these cases is use the following function

y = (1-cos(x*pi))/2

Graph that from x=0 to x=1, and you'll see that y goes from zero to one in a smooth manner (derivative of zero at both endpoints).

(Also helpful is y = (cos(x*pi)+1)/2 which does the same thing but in the other direction; y goes from one to zero.)

I hope that helps.

Scott
Bipolar (III) Inmate

From: schillmania.com
Insane since: Jul 2002

posted posted 07-13-2002 07:29

I'm not much of a math person, but I found this interesting "theory"..

9 = 3 x 3
1 + 2 + 3 + 2 + 1 = 9

25 = 5 x 5
1 + 2 + 3 + 4 + 5 + 4 + 3 + 2 + 1 = 25

100 = 10 x 10
1 + 2 + 3 + ... + 8 + 9 + 10 + 9 + 8 ... + 3 + 2 + 1 = 100

See the pattern? - adding 1 to the square root of "n", then adding
the same in reverse, gives you "n". (??)

Anyways, this makes a nice sliding motion when used in Javascript;
just use a variable incrementing like that, and then as a percentage
of the total distance to move.

I have an example, tested in IE (apologies to mozilla users).. http://www.schillmania.com/experimental/irrational_motion/index.html

And Doc, by the way, if you read this, check your e-mail! - I wrote you a
few weeks ago

- Scott

« BackwardsOnwards »

Show Forum Drop Down Menu