IC8 Python API:RLPy RMath

From Reallusion Wiki!
Jump to: navigation, search

Contents

Main article: IC8 Modules.
Last modified: 12/27/2022

Description

This class provides functions related to mathematics, including functions of trigonometric functions, exponents, logarithms, numerical ccomparisons, creation of random values, etc. It also provides some constant variables that can be referenced directly:

Constant Description
RMath.CONST_ALMOST_ZERO Same as AlmostZero, used to determine whether the value is close to 0.
RMath.CONST_EPSILON Used to determine if a value is close to epsilon 0.
RMath.CONST_MAX_T Maximum allowable floating-point value.
RMath.CONST_MIN_T Minimum allowable floating-point value.
RMath.CONST_PI Value of pi: π.
RMath.CONST_TWO_PI Value of pi times two: 2π.
RMath.CONST_HALF_PI Value of pi divided by 2: π/2.
RMath.CONST_INV_PI 1 divided by the value of pi: 1/π.
RMath.CONST_INV_TWO_PI Inverse of 2 times the value of pi: 1/2π.
RMath.CONST_DEG_TO_RAD Conversion of 1 degree to radians.
RMath.CONST_RAD_TO_DEG Conversion of 1 radian to degrees
RMath.CONST_SQRT_HALF 1 divided by the square root of 2: 1/sqrt(2).
RMath.CONST_MM_TO_INCH Conversion of 1 millimeter to inches.
RMath.CONST_INCH_TO_MM Conversion of 1 inch to millimeters.

Public Methods

Abs (a)

Computes the absolute number of a value.

Parameters

a [IN] Floating-point value - float

Returns

Absolute value of a - float
1 print( RLPy.RMath.Abs( -10 ) )      # 10

ACos (fValue)

Computes the arc-cosine of a value.

Parameters

fValue [IN] Floating-point value - float

Returns

Arc-cosine of fValue in radians - float [0,π]
1 print( RLPy.RMath.ACos( 0.9 ) )     # 0.4510268568992615

AlmostZero ( tValue )

Checks if a value is almost zero.

Parameters

tValue [IN] Floating-point value - float

Returns

True if the value is almost zero, else False - bool
1 print( RLPy.RMath.AlmostZero( 0.1 ) )               # False
2 print( RLPy.RMath.AlmostZero( 0.000000000000001 ) ) # True

ASin ( fValue )

Computes the arc-sine of a value.

Parameters

fValue [IN] Floating-point value - float

Returns

Arc-sine of fValue in radians - float [-π/2,π/2]
1 print( RLPy.RMath.ASin( 0.9 )   )   # 1.1197694540023804

ATan ( fValue )

Computes the arc-tangent of a value.

Parameters

fValue [IN] Floating-point value - float

Returns

Arc-cosine of fValue in radians - float [-π/2,π/2]
1 print( RLPy.RMath.ATan( 0.9 ) ) # 0.7328150868415833

ATan2 ( fY, fX )

Computes the arc-tangent of y/x using the signs of arguments to determine the correct quadrant.

Parameters

fY [IN] Floating-point value - float
fX [IN] Floating-point value - float

Returns

The arc-tangent of fY and fX in radians - float [-π,π]
1 print( RLPy.RMath.ATan2( -7.0, 7.0 ) )  # -0.7853981852531433

Bezier3 ( a, b, c, d, t )

Computes an interpolated value on a cubic bezier curve with 4 control points.

Parameters

a [IN] 1st control point value - float
b [IN] 2nd control point value - float
c [IN] 3rd control point value - float
d [IN] 4th control point value - float
t [IN] Point along the curve - float [0,1]

Returns

An interpolated value from the bezier curve - float
1 print( RLPy.RMath.Bezier3( 0.0,0.5,3.0,4.0,0.0 ) )  # 0.0 
2 print( RLPy.RMath.Bezier3( 0.0,0.5,3.0,4.0,0.5 ) )  # 1.8125
3 print( RLPy.RMath.Bezier3( 0.0,0.5,3.0,4.0,1.0 ) )  # 4.0

Clamp ( tMax, tMin, tValue )

Float result between a min and max values.

Parameters

tMax [IN] Maximum possible value - float
tMin [IN] Minimum possible value - float
tValue [IN] Floating-point value to restrict inside the min-to-max range - float

Returns

Float result between tMax and tMin - float [min,max]
1 print( RLPy.RMath.Clamp( 0.0, 255.0, 300.0 ) )  # 255.0

CopySign ( fValue )

Copies the sign of a floating-point value.

Parameters

fValue [IN] Floating-point value - float

Returns

Return -1 if the input is negative, else 1 - float {-1,1}
1 print( RLPy.RMath.CopySign( 9.0 ) )     # 1.0
2 print( RLPy.RMath.CopySign( 0.0 ) )     # 1.0
3 print( RLPy.RMath.CopySign( -9.0 ) )    # -1.0

Cos ( fValue )

Computes the cosine of a value.

Parameters

fValue [IN] Angle in radians - float

Returns

Cosine of fValue - float [-1,1]
1 print( RLPy.RMath.Cos( RLPy.RMath.CONST_PI ) )  # -1.0

Equal ( tValue1, tValue2 )

Check if 2 values are equal or not.

Parameters

tValue1 [IN] Floating-point value - float
tValue2 [IN] Floating-point value - float

Returns

Return True if TValue1 and TValue2 are almost Equal, else False - bool
1 print( RLPy.RMath.Equal( 0.0000001, 0.0000002 ) )   # True

Erf ( fX )

Computes the polynomial approximation of a value.

Parameters

fX [IN] Floating-point value - float

Returns

Polynomial approximation of fX - float
1 print( RLPy.RMath.Erf( 0.9 ) )  # 0.7960618138313293

Erfc ( fX )

Computes 1-erf(x)

Parameters

fX [IN] Floating-point value - float

Returns

Erfc(x) = 1-erf(x) - float
1 print( RLPy.RMath.Erf( 0.9 ) )  # 0.20393820106983185

Exp ( fValue )

Returns e raised to a given power (ex)

Parameters

fValue [IN] Floating-point value - float

Returns

The base-e exponential of arg is returned - float
1 print( RLPy.RMath.Exp( 2.0 ) )  # 7.389056205749512

FAbs ( fValue )

Absolute value of a floating-point value.

Parameters

fValue [IN] Floating-point value - float

Returns

The absolute value of arg - float
1 print( RLPy.RMath.FAbs( -2.0 ) )    # 2.0

FastCos0 ( fAngle )

Fast evaluation of cos(angle) by polynomial approximations.

Parameters

fAngle [IN] Angle in radians - float [0,π/2]

Returns

The sine of arg in the range of -1 and 1, is returned. The maximum absolute error is about 1.2e-03. This operation is about 2x faster than Cos - float
1 print( RLPy.RMath.Cos( 1.0 ) )      # 0.5403022766113281
2 print( RLPy.RMath.FastCos0( 1.0 ) ) # 0.5403500199317932

FastCos1 ( fAngle )

Fast evaluation of cos(angle) by polynomial approximations.

Parameters

fAngle [IN] Angle in radians - float [0,π/2]

Returns

The sine of arg in the range of 1 and -1, is returned. The maximum absolute error is about 2.3e-09. This operation is about 1.5x faster than Cos - float
1 print( RLPy.RMath.Cos( 1.0 ) )      # 0.5403022766113281
2 print( RLPy.RMath.FastCos1( 1.0 ) ) # 0.5403022766113281

FastInvCos ( fValue )

Fast evaluation of acos(value) by a sqrt times a polynomial.

Parameters

fValue [IN] Floating-point value - float [0,1]

Returns

The sine of arg is returned. The maximum absolute error is about 6.8e-05. The speed up is about 2.5 - float
1 print( RLPy.RMath.ACos( 0.9 ) )         # 0.4510268568992615
2 print( RLPy.RMath.FastInvCos( 0.9 ) )   # 0.45104315876960754

FastInvSin ( fValue )

Fast evaluation of asin(value) by a sqrt times a polynomial.

Parameters

fValue [IN] Floating-point value - float [0,1]

Returns

The sine of arg is returned. The maximum absolute error is about 6.8e-05. The speed up is about 2.5 - float
1 print( RLPy.RMath.ASin( 0.9 ) )         # 1.1197694540023804
2 print( RLPy.RMath.FastInvSin( 0.9 ) )   # 1.1197532415390015

FastInvSqrt_Walsh ( tValue )

A fast approximation to 1/sqrt using The Quake 3 Walsh Method.

Parameters

tValue [IN] Floating-point value - float

Returns

The inverse of square root - float
1 print( RLPy.RMath.InvSqrt( 0.9 ) )              # 1.054092526435852
2 print( RLPy.RMath.FastInvSqrt_Walsh( 0.9 ) )    # 1.053429365158081

FastInvTan0 ( fValue )

Fast evaluation of atan(value) by polynomial approximations.

Parameters

fValue [IN] Floating-point value - float [-1,1]

Returns

The atan of arg is returned. The maximum absolute error is about 1.2e-05. The speed up is about 2.2 - float
1 print( RLPy.RMath.ATan( 0.9 ) )         # 0.7328150868415833
2 print( RLPy.RMath.FastInvTan0( 0.9 ) )  # 0.7328156232833862

FastInvTan1 ( fValue )

Fast evaluation of atan(value) by polynomial approximations.

Parameters

fValue [IN] Floating-point value - float [-1,1]

Returns

The atan of arg is returned. The maximum absolute error is about 1.43-08. The speed up is about 1.5 - float
1 print( RLPy.RMath.ATan( 0.9 ) )         # 0.7328150868415833
2 print( RLPy.RMath.FastInvTan1( 0.9 ) )  # 0.7328150868415833

FastSin0 ( fAngle )

Fast evaluation of sin(angle) by polynomial approximations.

Parameters

fAngle [IN] Angle in radians - float [0,π/2]

Returns

The sine of fAngle. The maximum absolute error is about 1.7e-04. This operation is about 2x faster than Sin - float [-1,1]
1 print( RLPy.RMath.Sin( 0.9 ) )      # 0.7833269238471985
2 print( RLPy.RMath.FastSin0( 0.9 ) ) # 0.7834432125091553

FastSin1 ( fAngle )

Fast evaluation of sin(angle) by polynomial approximations.

Parameters

fAngle [IN] Angle in radians - float [0,π/2]

Returns

The sine of arg in the range of -1 and 1, is returned. The maximum absolute error is about 2.3e-09. This operation is about 1.5x faster than Sin - float
1 print( RLPy.RMath.Sin( 0.9 ) )      # 0.7833269238471985
2 print( RLPy.RMath.FastSin1( 0.9 ) ) # 0.7833268642425537

FastSqrt_LogBase2 ( tValue )

A fast approximation of Sqrt that is about 5x faster with slight errors.

Parameters

tValue [IN] Floating-point value - float

Returns

The value of square root - float
1 print( RLPy.RMath.Sqrt( 0.9 ) )                 # 0.9486832618713379
2 print( RLPy.RMath.FastSqrt_LogBase2( 0.9 ) )    # 0.949999988079071

FastSqrt_Walsh ( tValue )

A fast approximation to Sqrt using The Quake 3 Walsh method that is about 2x faster.

Parameters

tValue [IN] Floating-point value - float

Returns

The value of square root - float
1 print( RLPy.RMath.Sqrt( 0.9 ) )             # 0.9486832618713379
2 print( RLPy.RMath.FastSqrt_Walsh( 0.9 ) )   # 0.9480863809585571

FastTan0 ( fAngle )

Fast evaluation of tan(angle) by polynomial approximations.

Parameters

fAngle [IN] Angle in radians - float [0,π/4]

Returns

Tangent of fAngle. The maximum absolute error is about 8.1e-04. It is about 2.5x faster than Tan - float
1 print( RLPy.RMath.Tan( 0.9 ) )      # 1.2601581811904907
2 print( RLPy.RMath.FastTan0( 0.9 ) ) # 1.2515404224395752

FastTan1 ( fAngle )

Fast evaluation of tan(angle) by polynomial approximations.

Parameters

fAngle [IN] Angle in radians - float [0,π/4]

Returns

The tangent of arg is returned. The maximum absolute error is about 1.9e-08. It is about 1.75x faster than Tan - float
1 print( RLPy.RMath.Tan( 0.9 ) )      # 1.2601581811904907
2 print( RLPy.RMath.FastTan1( 0.9 ) ) # 1.2601404190063477

FMod ( fX, fY )

Remainder of the floating-point division operation.

Parameters

fX [IN] Floating-point value - float
fY [IN] Floating-point value - float

Returns

The floating-point remainder of the division x/y as defined above - float
1 print( RLPy.RMath.FMod( 5, 3 ) )    # 2.0

Gamma ( fX )

Computes the gamma of a value.

Parameters

fX [IN] Floating-point value - float

Returns

The value of gamma - float
1 print( RLPy.RMath.Gamma( 0.9 ) )    # 1.0686286687850952

IncompleteGamma ( fA, fX )

Computes incomplete gamma.

Parameters

fA [IN] Floating-point value - float
fX [IN] Floating-point value - float

Returns

The value of gamma - float
1 print( RLPy.RMath.IncompleteGamma( 0.1, 0.9 ) ) # 0.9716073274612427

IntervalRandom ( args )

Generate a random number between a min and max value.

Parameters

fMin [IN] Minimum value - float
fSeed [IN] maximum value - float
fSeed [IN] Seeded value - float

Returns

The random number generator may be seeded by a first call to IntervalRandom with a positive seed - float
1 print( RLPy.RMath.IntervalRandom(0.0,255.0,5.0) )   # 0.4202398657798767
2 print( RLPy.RMath.IntervalRandom(0.0,255.0) )       # 223.2952423095703

InvSqrt ( fValue )

Computes inverse of square root (1/sqrt)

Parameters

fValue [IN] Floating-point value - float

Returns

The inverse of square root - float
1 print( RLPy.RMath.InvSqrt( 0.9 ) )  # 1.054092526435852

Log ( fValue )

Computes natural (base e) logarithm.

Parameters

fValue [IN] Floating-point value - float

Returns

The natural (base-e) logarithm of arg is returned - float
1 print( RLPy.RMath.Log( 5.5 ) )  # 1.7047480344772339

LogGamma ( fX )

Computes log gamma.

Parameters

fX [IN] Floating-point value - float

Returns

The value of log gamma - float
1 print( RLPy.RMath.LogGamma( 5.5 ) ) # 3.9578146934509277

Max ( a, b )

Larger of two floating-point values.

Parameters

a [IN] Floating-point value - float
b [IN] Floating-point value - float

Returns

The larger of two floating-point values - float
1 print( RLPy.RMath.Max( 8.0, 9.0 ) ) # 9.0

Min ( a, b )

Smaller of two floating-point values.

Parameters

a [IN] Floating-point value - float
b [IN] Floating-point value - float

Returns

The smaller of two floating-point values - float
1 print( RLPy.RMath.Min( 8.0, 9.0 ) ) # 8.0

ModBessel0 ( fX )

Modified Bessel functions of order 0.

Parameters

fX [IN] Floating-point value - float

Returns

The value of modified bessel - float
1 print( RLPy.RMath.ModBessel0( 5.5 ) )   # 42.694644927978516

ModBessel1 ( fX )

Modified Bessel functions of order 1.

Parameters

fX [IN] Floating-point value - float

Returns

The value of modified bessel - float
1 print( RLPy.RMath.ModBessel1( 5.5 ) )   # 38.588165283203125

Pow ( fBase, fExponent )

Raises a number to the given power.

Parameters

fBase [IN] Base as a value of floating-point - float
fExponent [IN] Exponent as a value of floating-point - float

Returns

Base raised to the power of exp - float
1 print( RLPy.RMath.Pow( 2.0, 5.0 ) ) # 32.0

Round ( tValue )

Nearest floating-point.

Parameters

tValue [IN] Floating-point value - float

Returns

The nearest flaoting value to arg - float
1 print( RLPy.RMath.Round( 8.49 ) )   # 8.989999771118164
2 print( RLPy.RMath.Round( 8.5 ) )    # 9.0
3 print( RLPy.RMath.Round( 8.52 ) )   # 9.020000457763672

RoundAlmostZero ( tValue )

Round Almost Zero.

Parameters

tValue1 [IN] Floating-point value.

Returns

Return RoundAlmostZero - float
1 print( RLPy.RMath.RoundAlmostZero( 0.0000001 ) )    # 0.0

RoundEpsilonZero ( tValue )

Round Epsilon Zero.

Parameters

tValue1 [IN] Floating-point value.

Returns

Return RoundEpsilonZero - float
1 print( RLPy.RMath.RoundEpsilonZero( 0.0000001 ) )   # 0.0

Sign ( fValue )

Sign of a value. If the value is greater than 0, return 1; If the value is equal to 0, return 0; If the value is less than 0, return -1;

Parameters

fValue [IN] Floating-point value - float

Returns

Return -1 if the input is negative, 0 if the input is zero, and 1 if the input is positive - float {-1,0,1}
1 print( RLPy.RMath.Sign( 9.0 ) )     # 1.0
2 print( RLPy.RMath.Sign( 0.0 ) )     # 0.0
3 print( RLPy.RMath.Sign( -9.0 ) )    # -1.0

Sin ( fValue )

Computes the sine of a value.

Parameters

fValue [IN] Angle in radians - float

Returns

The sine of arg - float [-1,1]
1 print( RLPy.RMath.Sin( 0.9 ) )  # 0.7833269238471985

Sqr ( fValue )

Computes square.

Parameters

fValue [IN] Floating-point value - float

Returns

Square of arg, fValue * fValue - float
1 print( RLPy.RMath.Sqr( 0.9 ) )  # 0.809999942779541

Sqrt ( fValue )

Computes square root.

Parameters

fValue [IN] Floating-point value - float

Returns

Square root of arg - float
1 print( RLPy.RMath.Sqrt( 0.9 ) ) # 0.9486832618713379

SymmetricRandom ( args )

Generate a random number between -1 and 1. The random number generator may be seeded by a first call to SymmetricRandom with a positive seed.

Parameters

fSeed [IN] Seeded value - float

Returns

Random value - float [-1,1]
1 print( RLPy.RMath.SymmetricRandom( 5.0 ) )  # -0.9967039823532104
2 print( RLPy.RMath.SymmetricRandom() )       # 0.7513352036476135

Tan ( fValue )

Computes the tangent of a value.

Parameters

fValue [IN] Angle in radians - float

Returns

Tangent of fValue - float
1 print( RLPy.RMath.Tan( 0.9 ) )  # 1.2601581811904907

UnitRandom ( args )

Generate a random value between 0 and 1. The random number generator may be seeded by a first call to UnitRandom with a positive seed.

Parameters

fSeed [IN] Seeded value - float

Returns

Random value - float [0,1]
1 print( RLPy.RMath.UnitRandom( 5.0 ) )   # 0.0016479995101690292
2 print( RLPy.RMath.UnitRandom() )        # 0.8756675720214844