Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 1 and Version 2 of code/doc/Math


Ignore:
Timestamp:
Sep 22, 2008, 6:35:47 PM (16 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/Math

    v1 v2  
    22[[TracNav(TracNav/TOC_Development)]]
    33
     4Math defines several useful functions for mathematical purpose. The following list gives a short overview:
    45
    5  * '''sgn('''''value''''')''':
     6 * '''sgn('''''value''''')''': Returns the sign of the given value.
     7  * Example: sgn(10) = 1, sgn(-3) = -1
    68
    7  * '''min('''''value1''''', '''''value2''''')''':
    8  * '''max('''''value1''''', '''''value2''''')''':
    9  * '''clamp('''''value''''', '''''min''''', '''''max''''')''':
     9 * '''min('''''value1''''', '''''value2''''')''': Returns the smaller of two values.
     10  * Example: min(3, 10) = 3, min(2, -2) = -2
     11  * This is useful, if you don't want a value to be greater than a threshold. Use min(value, threshold).
     12 * '''max('''''value1''''', '''''value2''''')''': Returns the greater of two values.
     13  * Example: max(3, 10) = 10, max(2, -2) = 2
     14  * This is useful, if you don't want a value to be smaller than a threshold. Use max(value, threshold).
     15 * '''clamp('''''value''''', '''''min''''', '''''max''''')''': Keeps a value between a lower and an upper limit.
     16  * Example: clamp(5, 0, 10) = 5, clamp(100, 0, 10) = 10, clamp(-1, 0, 10) = 0
     17  * This is like a combination of max and min, used for thresholds
    1018
    11  * '''square('''''value''''')''':
    12  * '''cube('''''value''''')''':
     19 * '''square('''''value''''')''': Returns the square value (x^2^).
     20  * Example: square(3) = 9
     21 * '''cube('''''value''''')''': Returns the cube value (x^3^).
     22  * Example: cube(3) = 27
    1323
    14  * '''floor('''''value''''')''':
    15  * '''ceil('''''value''''')''':
    16  * '''round('''''value''''')''':
    17  * '''mod('''''value''''', '''''max''''')''':
     24 * '''floor('''''value''''')''': Rounds the value down.
     25  * Example: floor(0.2) = 0, floor(0.8) = 0
     26 * '''ceil('''''value''''')''': Rounds the value up.
     27  * Example: floor(0.2) = 1, floor(0.8) = 1
     28 * '''round('''''value''''')''': Rounds the value.
     29  * Example: floor(0.2) = 0, floor(0.8) = 1
    1830
    19  * '''interpolate('''''time''''', '''''start''''', '''''end''''')''':
    20  * '''interpolateSmooth('''''time''''', '''''start''''', '''''end''''')''':
     31 * '''mod('''''value''''', '''''max''''')''': The modulo operation, enhanced to work properly with negative values.
     32  * Example: mod(8, 10) = 8, mod(14, 10) = 4, mod(-8, 10) = 2, mod(-14, 10) = 6
    2133
    22  * '''rnd()''':
    23  * '''rnd('''''max''''')''':
    24  * '''rnd('''''min''''', '''''max''''')''':
     34 * '''interpolate('''''time''''', '''''start''''', '''''end''''')''': Interpolates between two values for a time between 0 and 1.
     35 * '''interpolateSmooth('''''time''''', '''''start''''', '''''end''''')''': Interpolates smoothly between two values for a time between 0 and 1. The function starts slowly, increases faster and stops slowly again.
     36
     37 * '''rnd()''': Returns a random number between 0 and 1.
     38 * '''rnd('''''max''''')''': Returns a random number between 0 and max.
     39 * '''rnd('''''min''''', '''''max''''')''': Returns a random number between min and max.