Mathematical functions
What it determines the new value of rotation that our pendulum will have on every instant - i.e. frame - it is the associated mathematical function. It is well know that the function sine has an oscillating course, but constant in the time, and that it oscillates between values +1 and -1; therefore if we associate the simple function sine to the rotation of the pendulum, where the rotation value is given instant to instant - frame to frame - from the value that assumes sin(a) (a is our quarter variable, that it increases to every frame), the pendulum will oscillate between +1 degree and -1 degree, too much little for being appreciated visually:

this is the reason for which we use the variable maxang: it works as multiplier of sin(a); if sin(a) oscillates between +1 and -1, and we give maxang to a value of 60, then
maxang*sin(a)
it will oscillate between +60 (degrees) and -60 (degrees).
Now we want that the pendulum does not oscillate forever, but that it stops its movement, gradually. In order to realize this, we need a function that multiplied to "maxangle*sin(a)", at the beginning it does not have influence but with passing of the time reduces the oscillation until 0 (that is pendulum stopped). Moreover this function must have an effect that carry gradually to 0: the perfect function for this result is just the power function, that is
n^a
where n it is a real number >0. It is well know that
the function power has these property:
- if n>1 it has increasing graph;
- if 0<n<1 it has decreasing graph, and if a is "much large" the function catches up the 0 (and therefore multiplied for "maxangle*sin(a)", when a is "much large", it reduces the oscillation to 0);
- se n=1 it is constant of constant value 1;
- for a=0 it assumes value 1 any is the value of n (and therefore
multiplied for "maxangle*sin(a)" at the beginning,
when a=0, it does not have influence.
For how much said, it appears clearly that we must choose an n, than
in our case it will be the timesmorz variable, than 0

Now we can create the final function, that it encloses sin and power: according
to ActionScript syntax it will be
((Math.sin(a))*(Math.pow(timesmorz,a))*maxang

What about the n_osc variable? It is used in the function in this mode:
Math.sin(n_osc*a)
its duty is to increase the number of totals oscillations that happen in the same arc of time. Example: if n_osc=1 we will have 20 oscillations in 10 sec, if n_osc=2 we will have 40 oscillations in 10 sec and so on. So, the effect of this variable is, for the final motion, of having a "slow-motion" if n_osc<1 and an accelerated one to the growing of n_osc>1. The definitive function used in the movie is:
((Math.sin(n_osc*a))*(Math.pow(timesmorz,a))*maxang
| » Level Advanced |
|
Added: 2001-01-18 Rating: 9 Votes: 960 |
| » Author |
| No author details given. |
| » Download |
| Download the files used in this tutorial. |
| Download (67 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


Comments
There are no comments yet. Be the first to comment!