Search Tutorials
Mathematical functionsWhat 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).
Notes: according to ActionScript syntax it must write
maxang*(Math.sin(a))
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:
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
Notes: according to ActionScript syntax it must write
Math.pow(timesmorz,a)
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
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||
|