s3d.math
Functions and classes for math.
Module Data
Module Functions
NearEqual
NearEqual (a, b [, tolerance ]) -> boolean
a -> number
b -> number
Returns true if the two numbers are close to equal, within the optional tolerance.
NearGreater
NearGreater (a, b [, tolerance ]) -> boolean
a -> number
b -> number
Returns true if a is greater than b, within the optional tolerance.
NearGreaterEqual
NearGreaterEqual (a, b [, tolerance ]) -> boolean
a -> number
b -> number
Returns true if a is greater than or equal to b, within the optional tolerance.
NearLess
NearLess (a, b [, tolerance ]) -> boolean
a -> number
b -> number
Returns true if a is greater than b, within the optional tolerance.
NearLessEqual
NearLessEqual (a, b [, tolerance ]) -> boolean
a -> number
b -> number
Returns true if a is greater than or equal to b, within the optional tolerance.
NearZero
NearZero (n [, tolerance ]) -> boolean
n -> number
Returns true if n is close to zero, within the optional tolerance.
FrameToTime
FrameToTime (frame, frameInterval) -> number
frame -> integer
frameInterval -> number
Returns the time for a given frame with frame numbers starting at zero and with the given interval between frames in seconds.
TimeToFrame
TimeToFrame (time , frameInterval) -> integer
time -> number
frameInterval -> number
Returns the frame for a given time in seconds with frame numbers starting at zero and with the given interval between frames in seconds.
The following functions are available starting with version 1.1.1 of the scripting system.
ConcentricallySampleDisk
ConcentricallySampleDisk (rand1, rand2) -> number, number
rand1 -> number
rand2 -> number
CosineSampleHemisphere
CosineSampleHemisphere (rand1, rand2) -> s3d.vec.Dir3d
rand1 -> number
rand2 -> number
Halton
Halton (d, i) -> number
d -> integer
i -> integer
UniformlySampleCone
UniformlySampleCone (rand1, rand2, maxCos) -> s3d.vec.Dir3d
rand1 -> number
rand2 -> number
maxCos -> number
UniformlySampleCone
UniformlySampleCone (rand1, rand2, maxCos, x, y, z) -> s3d.vec.Dir3d
rand1 -> number
rand2 -> number
maxCos -> number
x -> s3d.vec.Dir3d
y -> s3d.vec.Dir3d
z -> s3d.vec.Dir3d
UniformlySampleDisk
UniformlySampleDisk (rand1, rand2) -> number, number
rand1 -> number
rand2 -> number
UniformlySampleHemisphere
UniformlySampleHemisphere (rand1, rand2) -> s3d.vec.Dir3d
rand1 -> number
rand2 -> number
UniformlySampleSphere
UniformlySampleSphere (rand1, rand2) -> s3d.vec.Dir3d
rand1 -> number
rand2 -> number
UniformlySampleTriangle
UniformlySampleTriangle (rand1, rand2) -> number, number
rand1 -> number
rand2 -> number
Module Classes
The FastRandom Class
This class is designed to return non-uniformly distributed random values very quickly. It has the following construction methods:
FastRandom ()
Constructs a new fast random number generator with the default seed. Returns the new fast random number generator.
FastRandom (seed)
seed -> integer
Constructs a new fast random number generator with the given seed. Returns the new fast random number generator.
Every instance of this class has the following member methods:
FastRandom:GetSeed () -> integer
Returns the seed value used by this object.
FastRandom:SetSeed (seed)
seed -> integer
Sets the seed value used by this object.
FastRandom:GetInteger (low, high) -> integer
low -> integer
high -> integer
Returns a random integer value within the given range of integers, inclusive.
FastRandom:GetFloat () -> number
Returns a random value within the range 0 to 1.
The QMC Class
The following class is available starting with version 1.1.1 of the scripting system.
This class is designed to return uniformly distributed random values. It has the following construction methods:
QMC ()
Constructs a new uniform random number generator with the default seed. Returns the new uniform random number generator.
QMC (seed, dimensionality)
seed -> integer
dimensionality -> integer
Constructs a new uniform random number generator with the given seed. Returns the new uniform random number generator.
Every instance of this class has the following member methods:
QMC:GetDimensionality () -> integer
Returns the initializer for this object.
QMC:GetSeed () -> integer
Returns the initializer for this object.
QMC:GetFloat (sampleIndex, dimension [, numSamples]) -> number
sampleIndex -> integer
dimension -> integer
numSamples -> optional integer
If the numSamples argument is supplied it is the number of samples that will be taken, and the sampleIndex argument will range from 1 to numSamples. For uniform coverage of the sample space you should always supply this argument.
If the numSamples argument is not supplied then an arbitrary sample is returned for each call with unique sampleIndex and dimension arguments.
The dimension argument should range from 1 to the dimensionality used for initialization. So if you want to take 100 samples of a surface described by two coordinate values you would initialize a QMC object with an arbitrary seed and a dimensionality of 2 and then proceed to make calls to QMC:GetFloat with sampleIndex values from 1 to 100 and dimension values from 1 to 2.
Returns a random value within the range 0 to 1.