BB.MathUtils

Defined in: src/BB.MathUtils.js:1

A static utilitites class for all things math.

Index

Methods

Methods

angleBtwn
(
  • p1x
  • p1y
  • p2x
  • p2y
)
Number static

Get the angle between two points in radians. For degrees process this return value through BB.MathUtils.radToDegree(...).

Parameters:

  • p1x Number

    The x value of the first point.

  • p1y Number

    The y value of the first point.

  • p2x Number

    The x value of the second point.

  • p2y Number

    The y value of the second point.

Returns: Number

Returns the angle between (p1x, p1y) and (p2x, p2y) in radians.

cartesianToPolar
(
  • x
  • y
)
Array static

Translate from cartesian to polar coordinates.

Parameters:

  • x Number

    The x coordinate.

  • y Number

    The 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

Constrains value using min and max as the upper and lower bounds.

Parameters:

  • value Number

    The value to be clamped.

  • min Number

    The lower limit to clamp value by.

  • max Number

    The upper limit to clamp value by.

Returns: Number

The clamped value.

degToRad
(
  • degrees
)
type static

Translate degrees into radians.

Parameters:

  • degrees type

Returns: type

Returns degrees in radians.

dist
(
  • p1x
  • p1y
  • p2x
  • p2y
)
Number static

Get the distance between two points.

Parameters:

  • p1x Number

    The x value of the first point.

  • p1y Number

    The y value of the first point.

  • p2x Number

    The x value of the second point.

  • p2y Number

    The y value of the second point.

Returns: Number

Returns the distance between (p1x, p1y) and (p2x, p2y).

lerp
(
  • value
  • min
  • max
)
Number static

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

Maps (scales) value between sourceMin and sourceMax to destMin and destMax.

Parameters:

  • value Number

    The value to be mapped.

  • sourceMin Number
  • sourceMax Number
  • destMin Number
  • destMax Number

Returns: Number

Returns the mapped value.

noise
(
  • x
  • y
  • z
)
Number

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 Number

    x-coordinate in noise space

  • y Number

    y-coordinate in noise space

  • z Number

    z-coordinate in noise space

Returns: Number

Perlin noise value (between 0 and 1) at specified coordinates

norm
(
  • value
  • min
  • max
)
Number static

Scales value using min and max. This is the inverse of BB.MathUtils.lerp(...).

Parameters:

  • value Number

    The value to be scaled.

  • min Number
  • max Number

Returns: Number

Returns the scaled value.

polarToCartesian
(
  • radius
  • degrees
)
Array static

Translate from polar coordinates to cartesian coordinates.

Parameters:

  • radius Number

    The straight line distance from the origin.

  • degrees Number

    The 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

Translate radians into degrees.

Parameters:

  • radians type

Returns: type

Returns radians in degrees.

randomFloat
(
  • min
  • max
)
Number static

return a random float between a min and a max

Parameters:

  • min Number

    minimum value ( default to 0 if only one argument is passed )

  • max Number

    maximum value

Returns: Number

random float

randomInt
(
  • min
  • max
)
Number static

return a random int between a min and a max

Parameters:

  • min Number

    minimum value ( default to 0 if only one argument is passed )

  • max Number

    maximum value

Returns: Number

random integer

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index