Version 7 (modified by landauf, 8 years ago) (diff) |
---|
Math
Math defines several useful functions for mathematical purpose. The following list gives a short overview:
- sgn(value): Returns the sign of the given value.
- Example: sgn(10) = 1, sgn(-3) = -1
- min(value1, value2): Returns the smaller of two values.
- Example: min(3, 10) = 3, min(2, -2) = -2
- This is useful, if you don't want a value to be greater than a threshold. Use min(value, threshold).
- max(value1, value2): Returns the greater of two values.
- Example: max(3, 10) = 10, max(2, -2) = 2
- This is useful, if you don't want a value to be smaller than a threshold. Use max(value, threshold).
- clamp(value, min, max): Keeps a value between a lower and an upper limit.
- Example: clamp(5, 0, 10) = 5, clamp(100, 0, 10) = 10, clamp(-1, 0, 10) = 0
- This is like a combination of max and min, used for thresholds
- square(value): Returns the square value (x2).
- Example: square(3) = 9
- cube(value): Returns the cube value (x3).
- Example: cube(3) = 27
- floor(value): Rounds the value down.
- Example: floor(0.2) = 0, floor(0.7) = 0
- ceil(value): Rounds the value up.
- Example: floor(0.2) = 1, floor(0.7) = 1
- round(value): Rounds the value.
- Example: floor(0.2) = 0, floor(0.7) = 1
- mod(value, max): The modulo operation, enhanced to work properly with negative values.
- Example: mod(8, 10) = 8, mod(14, 10) = 4, mod(-8, 10) = 2, mod(-14, 10) = 6
- rnd(): Returns a random number between 0 and almost 1: 0 ⇐ rnd < 1.
- rnd(max): Returns a random number between 0 and almost max: 0 ⇐ rnd < max.
- rnd(min, max): Returns a random number between min and almost max: min ⇐ rnd < max.
Attachments (2)
- interpolation.png (3.4 KB) - added by landauf 16 years ago.
- interpolation_smooth.png (7.1 KB) - added by landauf 16 years ago.
Download all attachments as: .zip