Main Index : Reference :

Math Functions


Explanation

Here are some convenient math functions that are included in the SDK.

Constants

Constant Explanation
PI p
PI2 2p
PI05 p/2
SQRT2 21/2
ONESQRT2 2-1/2

Functions

[float] Degree([float] radians);
[float] Radians([float] degree);
[vector] MinimizeAngle([vector] a1, [vector] a2);

[vector] VectorToHPB([vector] v);

[vector] HSVToRGB([vector] hsv);
[vector] RGBToHSV([vector] rgb);

[vector] PointLineDistance([vector] p0, [vector] v0, [vector] q);

[float] Modulo([float] a, [float] b);
[float] Step([float] a, [float] x);

[float] Pulse([float] a, [float] b, [float] x);
[float] Clamp([float] a, [float] b, [float] x);
[float] BoxStep([float] a, [float] b, [float] x);
[float] SmoothStep([float] a, [float] b, [float] x);

[float] GammaCorrect([float] gamma, [float] x);
[float] Bias([float] bias, [float] x);
[float] Gain([float] g, [float] x);

[float,vector] Mix([float,vector] a, [float,vector] b, [float,vector] x);

Descriptions

Degree( radians )

[float] Degree([float] radians);

Returns the angle radians converted to degrees.

Radians( degree )

[float] Radians([float] degree);

Returns the angle degree converted to radians.

MinimizeAngle( a1, a2 )

[vector] MinimizeAngle([vector] a1, [vector] a2);

The change of the HPB angles from a1 to a2 might include loops with angles greater than 180°. This function returns a new value of a2 that represents the same rotation, but won't create loops when one rotates from a1 to a2.


VectorToHPB( v )

[vector] VectorToHPB([vector] v);

Returns HPB angles from the vector v.


HSVToRGB( hsv )

[vector] HSVToRGB([vector] hsv);

Converts hsv into the RGB color space and returns the converted value.

RGBToHSV( rgb )

[vector] RGBToHSV([vector] rgb);

Converts rgb into the HSV color space and returns the converted value.


PointLineDistance( p0, v0, q )

[vector] PointLineDistance([vector] p0, [vector] v0, [vector] q);

Returns the shortest vector between the point q and the line defined by the starting point p0 and the direction v0. The returned vector points from the nearest point on the line to q. Therefore the length of the returned vector gives the shortest distance between the line and q.


Modulo( a, b )

[float] Modulo([float] a, [float] b);

Returns a modulo b.

Step( a, b )

[float] Step([float] a, [float] x);

Returns 1.0 if x is greater than or equal to a, else 0.0.


Pulse if x [float] is between or equal to a,b returns 1.0 else 0.0 Clamp if x [float] is less than a returns a else if it is greater than b returns b else returns x BoxStep if x [float] is less than a returns 0.0 else if it is greater than b returns 1.0 else returns x mapped on the range a,b SmoothStep if x [float] is less than a returns 0.0 else if it is greater than b returns 1.0 else returns x mapped on the range a,b and smoothed out (ease in ease out curve)

Pulse( a, b, x )

[float] Pulse([float] a, [float] b, [float] x);

Returns 1.0 if x is between or equal to either of a and b, else 0.0.

Clamp( a, b, x )

[float] Clamp([float] a, [float] b, [float] x);

Returns a if x is less than a and b if x is greater than b, else returns x.

BoxStep( a, b, x )

[float] BoxStep([float] a, [float] b, [float] x);

Returns 0.0 if x is less than a and 1.0 if x is greater than b, else returns x mapped on the range [a,b] (a number between 0.0 and 1.0).

SmoothStep( a, b, x )

[float] SmoothStep([float] a, [float] b, [float] x);

Returns 0.0 if x is less than a and 1.0 if x is greater than b, else returns x mapped on the range [a,b] (a number between 0.0 and 1.0). The mapping is smoothed using an ease-in/ease-out curve.


GammaCorrect( gamma, x )

[float] GammaCorrect([float] gamma, [float] x);

Returns the gamma corrected value of x, calculated with the formula x1/gamma.

Bias( bias, x )

[float] Bias([float] bias, [float] x);

Returns the bias as the defined in the book "Texturing and Modeling" by Ebert. The internal code is:

Bias(b, x)
{
  return Pow(x, -Ln(b) / 0.693147180559945);
}

Gain( g, x )

[float] Gain([float] g, [float] x);

Returns the gain as the defined in the book "Texturing and Modeling" by Ebert. The internal code is:

Gain(g, x)
{
  if (x<0.5)
    return Bias(1.0 - g, 2.0 * x) * 0.5;
  else
    return 1.0 - Bias(1.0 - g, 2.0 - 2.0 * x) * 0.5;
}

Mix( a, b, x )

[float,vector] Mix([float,vector] a, [float,vector] b, [float,vector] x);

Returns a mixed value of a and b using the parameter x, as calculated by a+(b-a)*x.