BB.MathUtils
A static utilitites class for all things math.
Index
Methods
- angleBtwn static
- cartesianToPolar static
- clamp static
- degToRad static
- dist static
- lerp static
- map static
- noise
- norm static
- polarToCartesian static
- radToDeg static
- randomFloat static
- randomInt static
Methods
angleBtwn
(
-
p1x
-
p1y
-
p2x
-
p2y
)
Number
static
-
p1x
-
p1y
-
p2x
-
p2y
Get the angle between two points in radians. For degrees process this return value through BB.MathUtils.radToDegree(...).
Parameters:
-
p1x
NumberThe x value of the first point.
-
p1y
NumberThe y value of the first point.
-
p2x
NumberThe x value of the second point.
-
p2y
NumberThe y value of the second point.
Returns: Number
Returns the angle between (p1x, p1y) and (p2x, p2y) in radians.
cartesianToPolar
(
-
x
-
y
)
Array
static
-
x
-
y
Translate from cartesian to polar coordinates.
Parameters:
-
x
NumberThe x coordinate.
-
y
NumberThe y coordinate.
Returns: Array
An array of length two where the first element is the polar radius and the second element is the polar angle in degrees measured clockwise from the positive x axis.
clamp
(
-
value
-
min
-
max
)
Number
static
-
value
-
min
-
max
Constrains value using min and max as the upper and lower bounds.
Parameters:
-
value
NumberThe value to be clamped.
-
min
NumberThe lower limit to clamp value by.
-
max
NumberThe upper limit to clamp value by.
Returns: Number
The clamped value.
degToRad
(
-
degrees
)
type
static
-
degrees
Translate degrees into radians.
Parameters:
-
degrees
type
Returns: type
Returns degrees in radians.
dist
(
-
p1x
-
p1y
-
p2x
-
p2y
)
Number
static
-
p1x
-
p1y
-
p2x
-
p2y
Get the distance between two points.
Parameters:
-
p1x
NumberThe x value of the first point.
-
p1y
NumberThe y value of the first point.
-
p2x
NumberThe x value of the second point.
-
p2y
NumberThe y value of the second point.
Returns: Number
Returns the distance between (p1x, p1y) and (p2x, p2y).
lerp
(
-
value
-
min
-
max
)
Number
static
-
value
-
min
-
max
Linear interpolate norm from min and max. This is the inverse of BB.MathUtils.norm(...).
Parameters:
-
value
Number -
min
Number -
max
Number
Returns: Number
Returns the lerped norm.
map
(
-
value
-
sourceMin
-
sourceMax
-
destMin
-
destMax
)
Number
static
-
value
-
sourceMin
-
sourceMax
-
destMin
-
destMax
Maps (scales) value between sourceMin and sourceMax to destMin and destMax.
Parameters:
-
value
NumberThe value to be mapped.
-
sourceMin
Number -
sourceMax
Number -
destMin
Number -
destMax
Number
Returns: Number
Returns the mapped value.
noise
(
-
x
-
y
-
z
)
Number
-
x
-
y
-
z
Returns the Perlin noise value at specified coordinates. Perlin noise is a random sequence generator producing a more natural ordered, harmonic succession of numbers compared to the standard random() function. This function is taken almost verbatim from P5.js.
Parameters:
-
x
Numberx-coordinate in noise space
-
y
Numbery-coordinate in noise space
-
z
Numberz-coordinate in noise space
Returns: Number
Perlin noise value (between 0 and 1) at specified coordinates
norm
(
-
value
-
min
-
max
)
Number
static
-
value
-
min
-
max
Scales value using min and max. This is the inverse of BB.MathUtils.lerp(...).
Parameters:
-
value
NumberThe value to be scaled.
-
min
Number -
max
Number
Returns: Number
Returns the scaled value.
polarToCartesian
(
-
radius
-
degrees
)
Array
static
-
radius
-
degrees
Translate from polar coordinates to cartesian coordinates.
Parameters:
-
radius
NumberThe straight line distance from the origin.
-
degrees
NumberThe angle in degrees measured clockwise from the positive x axis.
Returns: Array
An array of length two where the first element is the x value and the second element is the y value.
radToDeg
(
-
radians
)
type
static
-
radians
Translate radians into degrees.
Parameters:
-
radians
type
Returns: type
Returns radians in degrees.
randomFloat
(
-
min
-
max
)
Number
static
-
min
-
max
return a random float between a min and a max
Parameters:
-
min
Numberminimum value ( default to 0 if only one argument is passed )
-
max
Numbermaximum value
Returns: Number
random float
randomInt
(
-
min
-
max
)
Number
static
-
min
-
max
return a random int between a min and a max
Parameters:
-
min
Numberminimum value ( default to 0 if only one argument is passed )
-
max
Numbermaximum value
Returns: Number
random integer