kunz Difference between revisions of "Mathematical Functions in VEX"

Difference between revisions of "Mathematical Functions in VEX"

From kunz
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
====== These are some basic parent functions. ======
[[File:basic_functions.png|960px]]
====== Each formula along with some of the characteristics are listed below. ======
<syntaxhighlight lang='C++'>
<syntaxhighlight lang='C++'>
y = 0;            // Constant (value remains the same at all points in time)
y = 0;            // Constant (value remains the same at all points in time)
</syntaxhighlight>
<syntaxhighlight lang='C++'>
y = x;            // Linear (value changes at a constant rate over time)
y = x;            // Linear (value changes at a constant rate over time)
</syntaxhighlight>
y = pow(2,x);    // Exponential, these functions grow very rapidly. y = pow(M_E, x); y = exp(x);
 
<syntaxhighlight lang='C++'>
y = pow(x,2);    // Quadratic, same as: y = x*x;
y = pow(x,2);    // Quadratic, same as: y = x*x;
</syntaxhighlight>
<syntaxhighlight lang='C++'>
y = pow(x,3);    // Cubic, same as: y = x*x*x;
y = pow(x,3);    // Cubic, same as: y = x*x*x;
</syntaxhighlight>
<syntaxhighlight lang='C++'>
y = pow(2,x);    // Exponential, these functions grow very rapidly. y = pow(M_E, x); y = exp(x);
</syntaxhighlight>
<syntaxhighlight lang='C++'>
y = 1.0/x;        // Reciprocal, with x in the denominator this will produce asymptotes at the axis
y = 1.0/x;        // Reciprocal, with x in the denominator this will produce asymptotes at the axis
</syntaxhighlight>
<syntaxhighlight lang='C++'>
y = pow(x,0.5);  // Square Root, same as: y = sqrt(x);
</syntaxhighlight>
<syntaxhighlight lang='C++'>
y = log(x);      // Logarithmic, rate of growth diminishes over time
y = log(x);      // Logarithmic, rate of growth diminishes over time
y = sqrt(x);      // Square Root, same as: y = pow(x,0.5);
</syntaxhighlight>
</syntaxhighlight>


====== Mathematical Constants ======
====== Mathematical Constants ======
The following constants are defined in math.h and automatically included in all VEX wrangle snippets.
The following constants are defined in $HFS/houdini/vex/include/math.h and automatically included in all VEX wrangle snippets.
<syntaxhighlight lang='C++'>
<syntaxhighlight lang='C++'>
// $HFS/houdini/vex/include/math.h
M_E        2.7182818    // sometimes called the natural number, or Euler's number
M_E        2.7182818    // sometimes called the natural number, or Euler's number
LN10        2.3025850    // natural logarithm of 10
LN10        2.3025850    // natural logarithm of 10
Line 40: Line 22:
LOG10E      0.4342944
LOG10E      0.4342944
LOG2E      1.4426950
LOG2E      1.4426950
PI          3.1415926    // 180° in radians, the ratio of the circumference of any circle to the diameter of that circle
PI          3.1415926    // 180° in radians, the ratio of the circumference to diameter of a circle
M_TWO_PI    6.2831852    // 360° in radians,the circumference of a unit circle, 2 * PI
M_TWO_PI    6.2831852    // 360° in radians, the circumference of a unit circle, 2 * PI
PI_2      1.5707963    // 90° in radians,quarter of the circumference of a circle with a radius of one, PI / 2
PI_2      1.5707963    // 90° in radians, 1/4th of the circumference of a unit circle, PI / 2
PI_4     0.7853981    // 45° in radians,one eighth of the circumference of a circle with a radius of one, PI / 4
PI_4     0.7853981    // 45° in radians, 1/8th of the circumference of a unit circle, PI / 4
SQRT1_2     0.7071067
SQRT1_2     0.7071067
SQRT2     1.4142135
SQRT2     1.4142135
TOLERANCE  0.0001
TOLERANCE  0.0001
</syntaxhighlight>
</syntaxhighlight>
====== Here are some curves produced using standard math/VEX functions. ======
sin wave
square wave
triangle wave
clamp
floor
frac
abs
smoothstep
====== Let's take a look at some practical applications of these functions. ======
#math #vex

Latest revision as of 06:05, 27 October 2021

These are some basic parent functions.

basic functions.png

Each formula along with some of the characteristics are listed below.
y = 0;            // Constant (value remains the same at all points in time)
y = x;            // Linear (value changes at a constant rate over time)
y = pow(2,x);     // Exponential, these functions grow very rapidly. y = pow(M_E, x); y = exp(x);
y = pow(x,2);     // Quadratic, same as: y = x*x;
y = pow(x,3);     // Cubic, same as: y = x*x*x;
y = 1.0/x;        // Reciprocal, with x in the denominator this will produce asymptotes at the axis
y = log(x);       // Logarithmic, rate of growth diminishes over time
y = sqrt(x);      // Square Root, same as: y = pow(x,0.5);
Mathematical Constants

The following constants are defined in $HFS/houdini/vex/include/math.h and automatically included in all VEX wrangle snippets.

M_E         2.7182818    // sometimes called the natural number, or Euler's number
LN10        2.3025850    // natural logarithm of 10
LN2         0.6931471    // natural logarithm of 2
LOG10E      0.4342944
LOG2E       1.4426950
PI          3.1415926    // 180° in radians, the ratio of the circumference to diameter of a circle
M_TWO_PI    6.2831852    // 360° in radians, the circumference of a unit circle, 2 * PI
PI_2   	    1.5707963    // 90° in radians, 1/4th of the circumference of a unit circle, PI / 2
PI_4	    0.7853981    // 45° in radians, 1/8th of the circumference of a unit circle, PI / 4
SQRT1_2	    0.7071067
SQRT2	    1.4142135
TOLERANCE   0.0001
Here are some curves produced using standard math/VEX functions.

sin wave square wave triangle wave clamp floor frac abs smoothstep

Let's take a look at some practical applications of these functions.
  1. math #vex